Skip to content

Commit

Permalink
improve textbox's selection handling refs #19, #1
Browse files Browse the repository at this point in the history
  • Loading branch information
beru committed May 24, 2015
1 parent 2776365 commit 21dc2aa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 28 deletions.
31 changes: 5 additions & 26 deletions source/gui/widgets/skeletons/text_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1619,20 +1619,12 @@ namespace nana{ namespace widgets

//Set caret pos by screen point and get the caret pos.
auto pos = mouse_caret(scrpos);
if(!hit_select_area(pos))
if(!select(false))
{
if(!select(false))
{
select_.a = points_.caret; //Set begin caret
set_end_caret();
}
select_.mode_selection = selection::mode_mouse_selected;
}
else
{
select(false);
select_.mode_selection = selection::mode_no_selected;
select_.a = points_.caret; //Set begin caret
set_end_caret();
}
select_.mode_selection = selection::mode_mouse_selected;
}

text_area_.border_renderer(graph_, _m_bgcolor());
Expand Down Expand Up @@ -2345,32 +2337,19 @@ namespace nana{ namespace widgets
case keyboard::os_arrow_up:
case keyboard::os_home:
case keyboard::os_pageup:
if (points_.caret == select_.b) {
select_.b = select_.a;
}else {
select_.b = std::max(select_.b, points_.caret);
}
select_.a = caret;
select_.b = caret;
break;
case keyboard::os_arrow_right:
case keyboard::os_arrow_down:
case keyboard::os_end:
case keyboard::os_pagedown:
if (select_.b == points_.caret) {
select_.a = std::min(select_.a, points_.caret);
}else {
select_.a = std::max(select_.b, points_.caret);
}
select_.b = caret;
break;
}
}else {
select_.b = caret;
select_.a = caret;
}
if (select_.a > select_.b) {
std::swap(select_.a, select_.b);
}
points_.caret = caret;
behavior_->adjust_caret_into_screen();
render(true);
Expand Down
6 changes: 4 additions & 2 deletions source/gui/widgets/textbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,13 @@ namespace drawerbase {
void drawer::focus(graph_reference graph, const arg_focus& arg)
{
refresh(graph);
if (arg.getting) {
if (!editor_->attr().multi_lines && arg.getting)
{
static auto& brock = detail::bedrock::instance();
auto native_window = reinterpret_cast<native_window_type>(arg.receiver);
auto* root_runtime = brock.wd_manager.root_runtime(native_window);
if (root_runtime && root_runtime->condition.tabstop_focus_changed) {
if (root_runtime && root_runtime->condition.tabstop_focus_changed)
{
editor_->select(true);
editor_->move_caret_end();
}
Expand Down

0 comments on commit 21dc2aa

Please sign in to comment.