]> git.tdb.fi Git - libs/gltk.git/blobdiff - source/entry.cpp
Avoid duplicating the logic in Entry::get_selection
[libs/gltk.git] / source / entry.cpp
index 21064f728d151bbdd709ef8ab3869b85353c1e37..fec27397eaf8a445f068e8edf19b2d6f0decb882 100644 (file)
@@ -93,18 +93,6 @@ void Entry::erase(unsigned pos, unsigned len)
 
        if(multiline)
                check_view_range();
-
-       rebuild();
-}
-
-void Entry::set_edit_position(unsigned pos)
-{
-       edit_pos = min(pos, text.size());
-       selection_active = false;
-
-       if(multiline)
-               check_view_range();
-
        rebuild();
 }
 
@@ -177,10 +165,8 @@ void Entry::rebuild_special(const Part &part)
                if(!text_part || !graphic || !graphic->get_texture())
                        return;
 
-               unsigned start = selection_pos;
-               unsigned end = edit_pos;
-               if(start>end)
-                       swap(start, end);
+               unsigned start, end;
+               get_selection(start, end);
 
                unsigned row, col;
                text.offset_to_coords(start, row, col);
@@ -390,21 +376,18 @@ void Entry::set_edit_position(unsigned ep, bool select)
                selection_pos = edit_pos;
        selection_active = select;
 
-       edit_pos = ep;
-       check_view_range();
+       edit_pos = min(ep, text.size());
+       if(multiline)
+               check_view_range();
        rebuild();
 }
 
 void Entry::erase_selection()
 {
-       if(!selection_active)
+       unsigned start, end;
+       if(!get_selection(start, end))
                return;
 
-       unsigned start = selection_pos;
-       unsigned end = edit_pos;
-       if(start>end)
-               swap(start, end);
-
        text.erase(start, end-start);
        set_edit_position(start, false);
 }