From: Jan Arne Petersen Date: Mon, 17 Sep 2012 13:28:09 +0000 (+0200) Subject: editor: Delete selected text before adding new X-Git-Tag: 0.99.0~75 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e386dd22c4aab327b38881e6169f24fb02b9a6e6;p=platform%2Fupstream%2Fweston.git 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 @@ static void text_entry_set_preedit(struct text_entry *entry, 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 @@ text_model_commit_string(void *data, 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 @@ text_model_preedit_string(void *data, 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 @@ text_entry_delete_text(struct text_entry *entry, } 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;