editor: Do not commit/preedit after invalid delete
Ignore the whole commit-string or preedit_string transaction when the delete_surrounding event was invalid. Signed-off-by: Jan Arne Petersen <jpetersen@openismus.com>
This commit is contained in:
committed by
Kristian Høgsberg
parent
895a128ce1
commit
8ccb7cc258
+41
-14
@@ -59,6 +59,7 @@ struct text_entry {
|
|||||||
int32_t anchor;
|
int32_t anchor;
|
||||||
uint32_t delete_index;
|
uint32_t delete_index;
|
||||||
uint32_t delete_length;
|
uint32_t delete_length;
|
||||||
|
bool invalid_delete;
|
||||||
} pending_commit;
|
} pending_commit;
|
||||||
struct wl_text_input *text_input;
|
struct wl_text_input *text_input;
|
||||||
PangoLayout *layout;
|
PangoLayout *layout;
|
||||||
@@ -144,8 +145,13 @@ text_input_commit_string(void *data,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
text_entry_reset_preedit(entry);
|
if (entry->pending_commit.invalid_delete) {
|
||||||
|
fprintf(stderr, "Ignore commit. Invalid previous delete_surrounding event.\n");
|
||||||
|
memset(&entry->pending_commit, 0, sizeof entry->pending_commit);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
text_entry_reset_preedit(entry);
|
||||||
|
|
||||||
if (entry->pending_commit.delete_length) {
|
if (entry->pending_commit.delete_length) {
|
||||||
text_entry_delete_text(entry,
|
text_entry_delete_text(entry,
|
||||||
@@ -164,6 +170,19 @@ text_input_commit_string(void *data,
|
|||||||
widget_schedule_redraw(entry->widget);
|
widget_schedule_redraw(entry->widget);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
clear_pending_preedit(struct text_entry *entry)
|
||||||
|
{
|
||||||
|
memset(&entry->pending_commit, 0, sizeof entry->pending_commit);
|
||||||
|
|
||||||
|
pango_attr_list_unref(entry->preedit_info.attr_list);
|
||||||
|
|
||||||
|
entry->preedit_info.cursor = 0;
|
||||||
|
entry->preedit_info.attr_list = NULL;
|
||||||
|
|
||||||
|
memset(&entry->preedit_info, 0, sizeof entry->preedit_info);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
text_input_preedit_string(void *data,
|
text_input_preedit_string(void *data,
|
||||||
struct wl_text_input *text_input,
|
struct wl_text_input *text_input,
|
||||||
@@ -173,6 +192,19 @@ text_input_preedit_string(void *data,
|
|||||||
{
|
{
|
||||||
struct text_entry *entry = data;
|
struct text_entry *entry = data;
|
||||||
|
|
||||||
|
if ((entry->serial - serial) > (entry->serial - entry->reset_serial)) {
|
||||||
|
fprintf(stderr, "Ignore preedit_string. Serial: %u, Current: %u, Reset: %u\n",
|
||||||
|
serial, entry->serial, entry->reset_serial);
|
||||||
|
clear_pending_preedit(entry);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (entry->pending_commit.invalid_delete) {
|
||||||
|
fprintf(stderr, "Ignore preedit_string. Invalid previous delete_surrounding event.\n");
|
||||||
|
clear_pending_preedit(entry);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (entry->pending_commit.delete_length) {
|
if (entry->pending_commit.delete_length) {
|
||||||
text_entry_delete_text(entry,
|
text_entry_delete_text(entry,
|
||||||
entry->pending_commit.delete_index,
|
entry->pending_commit.delete_index,
|
||||||
@@ -180,14 +212,12 @@ text_input_preedit_string(void *data,
|
|||||||
} else {
|
} else {
|
||||||
text_entry_delete_selected_text(entry);
|
text_entry_delete_selected_text(entry);
|
||||||
}
|
}
|
||||||
memset(&entry->pending_commit, 0, sizeof entry->pending_commit);
|
|
||||||
|
|
||||||
text_entry_set_preedit(entry, text, entry->preedit_info.cursor);
|
text_entry_set_preedit(entry, text, entry->preedit_info.cursor);
|
||||||
entry->preedit.commit = strdup(commit);
|
entry->preedit.commit = strdup(commit);
|
||||||
entry->preedit.attr_list = entry->preedit_info.attr_list;
|
entry->preedit.attr_list = pango_attr_list_ref(entry->preedit_info.attr_list);
|
||||||
|
|
||||||
entry->preedit_info.cursor = 0;
|
clear_pending_preedit(entry);
|
||||||
entry->preedit_info.attr_list = NULL;
|
|
||||||
|
|
||||||
text_entry_update(entry);
|
text_entry_update(entry);
|
||||||
|
|
||||||
@@ -205,19 +235,16 @@ text_input_delete_surrounding_text(void *data,
|
|||||||
|
|
||||||
entry->pending_commit.delete_index = entry->cursor + index;
|
entry->pending_commit.delete_index = entry->cursor + index;
|
||||||
entry->pending_commit.delete_length = length;
|
entry->pending_commit.delete_length = length;
|
||||||
|
entry->pending_commit.invalid_delete = false;
|
||||||
|
|
||||||
text_length = strlen(entry->text);
|
text_length = strlen(entry->text);
|
||||||
|
|
||||||
if (entry->pending_commit.delete_index > text_length) {
|
if (entry->pending_commit.delete_index > text_length ||
|
||||||
fprintf(stderr, "Invalid cursor index %d\n", index);
|
length > text_length ||
|
||||||
entry->pending_commit.delete_length = 0;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (length > text_length ||
|
|
||||||
entry->pending_commit.delete_index + length > text_length) {
|
entry->pending_commit.delete_index + length > text_length) {
|
||||||
fprintf(stderr, "Invalid length %d\n", length);
|
fprintf(stderr, "delete_surrounding_text: Invalid index: %d," \
|
||||||
entry->pending_commit.delete_length = 0;
|
"length %u'; cursor: %u text length: %u\n", index, length, entry->cursor, text_length);
|
||||||
|
entry->pending_commit.invalid_delete = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user