aboutsummaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorfiaxh <git@mx.ax.lt>2017-08-25 12:04:03 +0200
committerfiaxh <git@mx.ax.lt>2017-08-25 22:30:03 +0200
commitf3e587d7663edd6dd2bdb2c87a337156d2e9d0e9 (patch)
tree93b0db8f7042802ba4fe7374b7f1908815f7ee29 /main
parentb672df94e82032f265255ea756b459251cadfef1 (diff)
downloaddino-f3e587d7663edd6dd2bdb2c87a337156d2e9d0e9.tar.gz
dino-f3e587d7663edd6dd2bdb2c87a337156d2e9d0e9.zip
Improve undo/redo
Diffstat (limited to 'main')
-rw-r--r--main/src/ui/chat_input/edit_history.vala15
1 files 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;
}