return;
text.insert(pos, t);
-
- unsigned old_edit_pos = edit_pos;
- if(edit_pos>=pos)
- edit_pos += t.size();
- if(selection_active && selection_pos>=pos)
- selection_pos += t.size();
-
signal_text_changed.emit(text.get());
- if(edit_pos!=old_edit_pos)
- signal_edit_position_changed.emit(edit_pos);
+ adjust_edit_position_for_change(pos, t.size());
if(multiline)
check_view_range();
return;
text.erase(pos, len);
-
- unsigned old_edit_pos = edit_pos;
- if(edit_pos>=pos+len)
- edit_pos -= len;
- else if(edit_pos>=pos)
- edit_pos = pos;
- if(selection_active)
- {
- if(selection_pos>=pos+len)
- selection_pos -= len;
- else if(selection_pos>=pos)
- selection_pos = pos;
- }
-
signal_text_changed.emit(text.get());
- if(edit_pos!=old_edit_pos)
- signal_edit_position_changed.emit(edit_pos);
+ adjust_edit_position_for_change(pos, -len);
if(multiline)
check_view_range();
throw invalid_argument("Entry::move_edit_position");
}
+void Entry::adjust_edit_position_for_change(unsigned pos, int change)
+{
+ unsigned old_edit_pos = edit_pos;
+
+ if(change>0)
+ {
+ if(edit_pos>=pos)
+ edit_pos += change;
+ if(selection_active && selection_pos>=pos)
+ selection_pos += change;
+ }
+ else if(change<0)
+ {
+ if(edit_pos>=pos)
+ edit_pos -= min<unsigned>(edit_pos-pos, -change);
+ if(selection_active)
+ selection_pos -= min<unsigned>(selection_pos-pos, -change);
+ }
+
+ if(edit_pos!=old_edit_pos)
+ signal_edit_position_changed.emit(edit_pos);
+}
+
void Entry::set_edit_position(unsigned ep, bool select)
{
if(select && !selection_active)
virtual void on_style_change();
void move_edit_position(Navigation, bool);
+ void adjust_edit_position_for_change(unsigned, int);
void set_edit_position(unsigned, bool);
void erase_selection(bool);
void check_cursor_blink();