From c2ab5d46940bb01ab4ab2b4ef82b6829ddbadb5c Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Mon, 15 Aug 2022 22:21:53 +0200 Subject: Allow to undo and redo selection changes From the issue: > It often happens to me that I carefully craft a selection with multiple > cursors, ready to make changes elegantly, only to completely mess it > up by pressing a wrong key (by merging the cursors for example). Being > able to undo the last selection change (even if only until the previous > buffer change) would make this much less painful. Fix this by recording selection changes and allowing simple linear undo/redo of selection changes. The preliminary key bindings are and . Here are some other vacant normal mode keys I considered X Y # ^ = ' unfortunately none of them is super convenient to type. Maybe we can kick out some other normal mode command? --- This feature has some overlap with the jump list (/) and with undo (u) but each of the three features have their moment. Currently there's no special integration with either peer feature; the three histories are completely independent. In future we might want to synchronize them so we can implement Sublime Text's "Soft undo" feature. Note that it is possible to restore selections that predate a buffer modification. Depending on the buffer modification, the selections might look different of course. (When trying to apply an old buffer's selection to the new buffer, Kakoune computes a diff of the buffers and updates the selection accordingly. This works quite well for many practical examples.) This makes us record the full history of all selections for each client. This seems wasteful, we could set a limit. I don't expect excessive memory usage in practice (we also keep the full history of buffer changes) but I could be wrong. Closes #898 --- src/input_handler.cc | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/input_handler.cc') diff --git a/src/input_handler.cc b/src/input_handler.cc index 73ad276d..25c450c8 100644 --- a/src/input_handler.cc +++ b/src/input_handler.cc @@ -100,6 +100,7 @@ struct MouseHandler switch (key.mouse_button()) { case Key::MouseButton::Right: { + kak_assert(not context.is_editing_selection()); m_dragging.reset(); cursor = context.window().buffer_coord(key.coord()); ScopedSelectionEdition selection_edition{context}; @@ -113,6 +114,7 @@ struct MouseHandler } case Key::MouseButton::Left: { + kak_assert(not context.is_editing_selection()); m_dragging.reset(new ScopedSelectionEdition{context}); m_anchor = context.window().buffer_coord(key.coord()); if (not (key.modifiers & Key::Modifiers::Control)) -- cgit v1.2.3