From: Mikko Rasa Date: Fri, 27 Sep 2019 11:29:46 +0000 (+0300) Subject: Add a signal for selection changes in Entry X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=b391f4b774d17c53dfd9062fc7c7a6b14f72f926;p=libs%2Fgltk.git Add a signal for selection changes in Entry --- diff --git a/source/entry.cpp b/source/entry.cpp index 1c66f98..f75f200 100644 --- a/source/entry.cpp +++ b/source/entry.cpp @@ -395,6 +395,7 @@ void Entry::move_edit_position(Navigation nav, bool select) void Entry::adjust_edit_position_for_change(unsigned pos, int change) { unsigned old_edit_pos = edit_pos; + unsigned old_select_pos = selection_pos; if(change>0) { @@ -413,10 +414,17 @@ void Entry::adjust_edit_position_for_change(unsigned pos, int change) if(edit_pos!=old_edit_pos) signal_edit_position_changed.emit(edit_pos); + if(selection_active && (edit_pos!=old_edit_pos || selection_pos!=old_select_pos)) + { + unsigned start, end; + if(get_selection(start, end)) + signal_selection_changed.emit(start, end); + } } void Entry::set_edit_position(unsigned ep, bool select) { + bool selection_was_active = selection_active; if(select && !selection_active) selection_pos = edit_pos; selection_active = select; @@ -425,7 +433,14 @@ void Entry::set_edit_position(unsigned ep, bool select) edit_pos = min(ep, text.size()); if(edit_pos!=old_edit_pos) + { signal_edit_position_changed.emit(edit_pos); + unsigned start, end; + if(get_selection(start, end)) + signal_selection_changed.emit(start, end); + else if(selection_was_active) + signal_selection_changed.emit(edit_pos, edit_pos); + } if(multiline) check_view_range(); diff --git a/source/entry.h b/source/entry.h index da29a51..165b7c7 100644 --- a/source/entry.h +++ b/source/entry.h @@ -33,6 +33,7 @@ public: sigc::signal signal_edit_position_changed; sigc::signal signal_scroll_position_changed; + sigc::signal signal_selection_changed; sigc::signal signal_text_changed; // Deprecated