From: Jan Arne Petersen <jpeter...@openismus.com> Signed-off-by: Jan Arne Petersen <jpeter...@openismus.com> --- clients/editor.c | 33 +++++++++++++++++++-------------- clients/keyboard.c | 3 +++ 2 files changed, 22 insertions(+), 14 deletions(-)
diff --git a/clients/editor.c b/clients/editor.c index c40815a..56205af 100644 --- a/clients/editor.c +++ b/clients/editor.c @@ -56,6 +56,8 @@ struct text_entry { struct { int32_t cursor; int32_t anchor; + uint32_t delete_index; + uint32_t delete_length; } pending_commit; struct text_input *text_input; PangoLayout *layout; @@ -148,6 +150,13 @@ text_input_commit_string(void *data, text_entry_reset_preedit(entry); text_entry_delete_selected_text(entry); + + if (entry->pending_commit.delete_length) { + text_entry_delete_text(entry, + entry->pending_commit.delete_index, + entry->pending_commit.delete_length); + } + text_entry_insert_at_cursor(entry, text, entry->pending_commit.cursor, entry->pending_commit.anchor); @@ -186,28 +195,24 @@ text_input_delete_surrounding_text(void *data, uint32_t length) { struct text_entry *entry = data; - uint32_t cursor_index = index + entry->cursor; - const char *start, *end; + uint32_t text_length; + + entry->pending_commit.delete_index = entry->cursor + index; + entry->pending_commit.delete_length = length; - if (cursor_index > strlen(entry->text)) { + text_length = utf8_characters(entry->text); + + if (entry->pending_commit.delete_index > text_length) { fprintf(stderr, "Invalid cursor index %d\n", index); + entry->pending_commit.delete_length = 0; return; } - if (cursor_index + length > strlen(entry->text)) { + if (entry->pending_commit.delete_index + length > text_length) { fprintf(stderr, "Invalid length %d\n", length); + entry->pending_commit.delete_length = 0; return; } - - if (length == 0) - return; - - start = utf8_start_char(entry->text, entry->text + cursor_index); - end = utf8_end_char(entry->text + cursor_index + length); - - text_entry_delete_text(entry, - start - entry->text, - end - start); } static void diff --git a/clients/keyboard.c b/clients/keyboard.c index 9dd210a..bd88207 100644 --- a/clients/keyboard.c +++ b/clients/keyboard.c @@ -447,6 +447,9 @@ keyboard_handle_key(struct keyboard *keyboard, uint32_t time, const struct key * if (strlen(keyboard->keyboard->preedit_string) == 0) { input_method_context_delete_surrounding_text(keyboard->keyboard->context, -1, 1); + input_method_context_commit_string(keyboard->keyboard->context, + keyboard->keyboard->serial, + ""); } else { keyboard->keyboard->preedit_string[strlen(keyboard->keyboard->preedit_string) - 1] = '\0'; virtual_keyboard_send_preedit(keyboard->keyboard, -1); -- 1.8.1.4 _______________________________________________ wayland-devel mailing list wayland-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/wayland-devel