void Entry::insert(unsigned pos, const string &t)
{
+ if(t.empty())
+ return;
+
text.insert(pos, t);
unsigned old_edit_pos = edit_pos;
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);
void Entry::erase(unsigned pos, unsigned len)
{
+ if(!len)
+ return;
+
text.erase(pos, len);
unsigned old_edit_pos = edit_pos;
selection_pos = pos;
}
+ signal_text_changed.emit(text.get());
if(edit_pos!=old_edit_pos)
signal_edit_position_changed.emit(edit_pos);
if(key==Input::KEY_BACKSPACE)
{
if(selection_active)
- erase_selection();
+ erase_selection(true);
else if(edit_pos>0)
erase(edit_pos-1, 1);
}
else if(key==Input::KEY_DELETE)
{
if(selection_active)
- erase_selection();
+ erase_selection(true);
else
erase(edit_pos, 1);
}
if(got_key_press && ch>=' ' && ch!=0x7F)
{
if(selection_active)
- erase_selection();
+ erase_selection(false);
insert(edit_pos, StringCodec::encode<StringCodec::Utf8>(StringCodec::ustring(1, ch)));
return true;
}
rebuild();
}
-void Entry::erase_selection()
+void Entry::erase_selection(bool emit_change)
{
unsigned start, end;
if(!get_selection(start, end))
return;
text.erase(start, end-start);
+ if(emit_change)
+ signal_text_changed.emit(text.get());
set_edit_position(start, false);
}
sigc::signal<void, unsigned> signal_edit_position_changed;
sigc::signal<void, unsigned> signal_scroll_position_changed;
+ sigc::signal<void, const std::string &> signal_text_changed;
// Deprecated
sigc::signal<void> signal_enter;
void move_edit_position(Navigation, bool);
void set_edit_position(unsigned, bool);
- void erase_selection();
+ void erase_selection(bool);
void check_cursor_blink();
void check_view_range();
void slider_value_changed(double);