From 8427379a5dfcf35af35fd5a7b26803e8727476e6 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Thu, 22 Dec 2022 18:09:45 +0100 Subject: [PATCH] Tweak selection-undo interaction with WinDisplay hooks Each selection undo operation is surrounded by pair of begin_edition()/end_edition() calls. The original reason for adding these was that in one of my preliminary versions, a WinDisplay hook could break an undo chain, even if the hook did not affect selections at all. This has since been fixed. By surrounding the undo with begin_edition()/end_edition(), try to ensure that any selection modification that happens in a WinDisplay hook would not break the undo chain. Essentially this means that, after using to undo a buffer change, this was meant to make sure that could redo that buffer change. However, it turns out this actually doesn't work. The attached test case triggers an assertion. As described in the first paragraph, the only real-world motivation for this is gone, so let's simplify the behavior. The assertion fix means that we can test the next commit better. --- src/context.cc | 6 ------ test/normal/selection-undo/windisplay-hook/cmd | 1 + test/normal/selection-undo/windisplay-hook/in | 3 +++ test/normal/selection-undo/windisplay-hook/out | 3 +++ test/normal/selection-undo/windisplay-hook/rc | 1 + test/normal/selection-undo/windisplay-hook/script | 2 ++ 6 files changed, 10 insertions(+), 6 deletions(-) create mode 100644 test/normal/selection-undo/windisplay-hook/cmd create mode 100644 test/normal/selection-undo/windisplay-hook/in create mode 100644 test/normal/selection-undo/windisplay-hook/out create mode 100644 test/normal/selection-undo/windisplay-hook/rc create mode 100644 test/normal/selection-undo/windisplay-hook/script diff --git a/src/context.cc b/src/context.cc index 568142c6..3a0aadb4 100644 --- a/src/context.cc +++ b/src/context.cc @@ -225,11 +225,6 @@ void Context::SelectionHistory::undo() if (in_edition()) throw runtime_error("selection undo is only supported at top-level"); kak_assert(not empty()); - begin_edition(); - auto end = on_scope_end([&] { - kak_assert(current_history_node().selections == m_staging->selections); - end_edition(); - }); HistoryId next; if constexpr (backward) next = current_history_node().parent; @@ -242,7 +237,6 @@ void Context::SelectionHistory::undo() m_history_id = next; if constexpr (backward) current_history_node().redo_child = previous_id; - m_staging = current_history_node(); }; Buffer& destination_buffer = history_node(next).selections.buffer(); if (&destination_buffer == &m_context.buffer()) diff --git a/test/normal/selection-undo/windisplay-hook/cmd b/test/normal/selection-undo/windisplay-hook/cmd new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/test/normal/selection-undo/windisplay-hook/cmd @@ -0,0 +1 @@ + diff --git a/test/normal/selection-undo/windisplay-hook/in b/test/normal/selection-undo/windisplay-hook/in new file mode 100644 index 00000000..01e79c32 --- /dev/null +++ b/test/normal/selection-undo/windisplay-hook/in @@ -0,0 +1,3 @@ +1 +2 +3 diff --git a/test/normal/selection-undo/windisplay-hook/out b/test/normal/selection-undo/windisplay-hook/out new file mode 100644 index 00000000..92243f2b --- /dev/null +++ b/test/normal/selection-undo/windisplay-hook/out @@ -0,0 +1,3 @@ +1 +2 +here3 diff --git a/test/normal/selection-undo/windisplay-hook/rc b/test/normal/selection-undo/windisplay-hook/rc new file mode 100644 index 00000000..b157a2ce --- /dev/null +++ b/test/normal/selection-undo/windisplay-hook/rc @@ -0,0 +1 @@ +hook global WinDisplay .*/out %{exec j} diff --git a/test/normal/selection-undo/windisplay-hook/script b/test/normal/selection-undo/windisplay-hook/script new file mode 100644 index 00000000..d2fd1c40 --- /dev/null +++ b/test/normal/selection-undo/windisplay-hook/script @@ -0,0 +1,2 @@ +ui_out -ignore 4 +ui_in '{ "jsonrpc": "2.0", "method": "keys", "params": [ "j:buffer *debug*ihere" ] }'