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 <c-h> to undo a buffer change, this was meant to
make sure that <c-k> 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.
This commit is contained in:
Johannes Altmanninger 2022-12-22 18:09:45 +01:00
parent 8e8c2fb46d
commit 8427379a5d
6 changed files with 10 additions and 6 deletions

View File

@ -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())

View File

@ -0,0 +1 @@

View File

@ -0,0 +1,3 @@
1
2
3

View File

@ -0,0 +1,3 @@
1
2
here3

View File

@ -0,0 +1 @@
hook global WinDisplay .*/out %{exec j}

View File

@ -0,0 +1,2 @@
ui_out -ignore 4
ui_in '{ "jsonrpc": "2.0", "method": "keys", "params": [ "j:buffer *debug*<ret><c-h>ihere<esc>" ] }'