]> git.tdb.fi Git - libs/gltk.git/commitdiff
Add a signal for selection changes in Entry
authorMikko Rasa <tdb@tdb.fi>
Fri, 27 Sep 2019 11:29:46 +0000 (14:29 +0300)
committerMikko Rasa <tdb@tdb.fi>
Fri, 27 Sep 2019 12:19:40 +0000 (15:19 +0300)
source/entry.cpp
source/entry.h

index 1c66f9885fe8e5058a0ef0ae20e40ec3d83e1013..f75f2005bc2cdd880d4960cf26b6f1db2cde6cf1 100644 (file)
@@ -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();
index da29a5134f5fd4c3e7e9a86e58eeade3530057c4..165b7c731a91ef110cf1a9180b57e96ae079ea59 100644 (file)
@@ -33,6 +33,7 @@ public:
 
        sigc::signal<void, unsigned> signal_edit_position_changed;
        sigc::signal<void, unsigned> signal_scroll_position_changed;
+       sigc::signal<void, unsigned, unsigned> signal_selection_changed;
        sigc::signal<void, const std::string &> signal_text_changed;
 
        // Deprecated