editor: Delete selected text before adding new
When inserting new text, delete selected text first.
diff --git a/clients/editor.c b/clients/editor.c
index 5ad1aa2..5c75ac1 100644
--- a/clients/editor.c
+++ b/clients/editor.c
@@ -214,6 +214,7 @@
int preedit_cursor);
static void text_entry_delete_text(struct text_entry *entry,
uint32_t index, uint32_t length);
+static void text_entry_delete_selected_text(struct text_entry *entry);
static void
text_model_commit_string(void *data,
@@ -228,6 +229,7 @@
index = strlen(text);
}
+ text_entry_delete_selected_text(entry);
text_entry_insert_at_cursor(entry, text);
widget_schedule_redraw(entry->widget);
@@ -246,6 +248,7 @@
index = strlen(text);
}
+ text_entry_delete_selected_text(entry);
text_entry_set_preedit(entry, text, index);
widget_schedule_redraw(entry->widget);
@@ -597,6 +600,20 @@
}
static void
+text_entry_delete_selected_text(struct text_entry *entry)
+{
+ uint32_t start_index = entry->anchor < entry->cursor ? entry->anchor : entry->cursor;
+ uint32_t end_index = entry->anchor < entry->cursor ? entry->cursor : entry->anchor;
+
+ if (entry->anchor == entry->cursor)
+ return;
+
+ text_entry_delete_text(entry, start_index, end_index - start_index);
+
+ entry->anchor = entry->cursor;
+}
+
+static void
text_entry_draw_selection(struct text_entry *entry, cairo_t *cr)
{
cairo_text_extents_t extents;