From 21dc2aa48ca8d8ab75a37ad5decea34e38a72c4a Mon Sep 17 00:00:00 2001 From: beru Date: Sun, 24 May 2015 23:25:39 +0900 Subject: [PATCH] improve textbox's selection handling refs #19, #1 --- source/gui/widgets/skeletons/text_editor.cpp | 31 ++++---------------- source/gui/widgets/textbox.cpp | 6 ++-- 2 files changed, 9 insertions(+), 28 deletions(-) diff --git a/source/gui/widgets/skeletons/text_editor.cpp b/source/gui/widgets/skeletons/text_editor.cpp index 3031e6ca..713059bf 100644 --- a/source/gui/widgets/skeletons/text_editor.cpp +++ b/source/gui/widgets/skeletons/text_editor.cpp @@ -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()); @@ -2345,22 +2337,12 @@ 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; } @@ -2368,9 +2350,6 @@ namespace nana{ namespace widgets 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); diff --git a/source/gui/widgets/textbox.cpp b/source/gui/widgets/textbox.cpp index ab443cbe..dff7856f 100644 --- a/source/gui/widgets/textbox.cpp +++ b/source/gui/widgets/textbox.cpp @@ -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(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(); }