From f3e587d7663edd6dd2bdb2c87a337156d2e9d0e9 Mon Sep 17 00:00:00 2001 From: fiaxh Date: Fri, 25 Aug 2017 12:04:03 +0200 Subject: [PATCH] Improve undo/redo --- main/src/ui/chat_input/edit_history.vala | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/main/src/ui/chat_input/edit_history.vala b/main/src/ui/chat_input/edit_history.vala index 22032a0b..2ac0b88a 100644 --- a/main/src/ui/chat_input/edit_history.vala +++ b/main/src/ui/chat_input/edit_history.vala @@ -20,6 +20,10 @@ class EditHistory { this.text_input = text_input; text_input.key_press_event.connect(on_text_input_key_press); + text_input.cut_clipboard.connect_after(save_state); + text_input.paste_clipboard.connect_after(save_state); + text_input.move_cursor.connect_after(save_state); + text_input.button_release_event.connect_after(() => { save_state(); return false; }); } public void initialize_for_conversation(Conversation conversation) { @@ -36,18 +40,13 @@ class EditHistory { } else if (ctrl_pressed && (event.keyval in new uint[]{ Key.Z, Key.y } )) { redo(); } else if (event.keyval in new uint[]{ Key.space, Key.Tab, Key.ISO_Left_Tab }) { - if (indices[conversation] < histories[conversation].size - 1) { - histories[conversation] = histories[conversation].slice(0, indices[conversation] + 1); - } save_state(); } return false; } private void undo() { - if (histories[conversation][indices[conversation]] != text_input.buffer.text) { - save_state(); - } + save_state(); if (indices[conversation] > 0) { indices[conversation] = indices[conversation] - 1; text_input.buffer.text = histories[conversation][indices[conversation]]; @@ -62,6 +61,10 @@ class EditHistory { } private void save_state() { + if (histories[conversation][indices[conversation]] == text_input.buffer.text) return; + if (indices[conversation] < histories[conversation].size - 1) { + histories[conversation] = histories[conversation].slice(0, indices[conversation] + 1); + } histories[conversation].add(text_input.buffer.text); indices[conversation] = indices[conversation] + 1; }