From 7e2e3f8c255f7ae65bd9fdc3feba6b4efd21416f Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Thu, 27 Aug 2026 16:12:11 -0400 Subject: feat(editor): undo restores cursor position #41520 Problem: Undo places the cursor wherever the cursor happened to sit at "save time" (`uh_cursor` is sampled lazily on the first change). Examples: - `i` preserves, but `a` does not - `diw`, `atest`, `d^` abandon the original position - `D`, `o` restore it (by accident). Solution: `composite` tracks the pending atom (and its `origin`) across frames. A `stuffed` continuation frame inherits the `origin` + prepped redo. Store `origin` info in the undo header, so undo can restore it. - Not for a mid-command undo break (i_CTRL-G_u). - Undoing a mapping restores where the mapping started (which technically may be different than where the "edit" started). --- test/functional/lua/buffer_updates_spec.lua | 2 ++ 1 file changed, 2 insertions(+) (limited to 'test/functional/lua/buffer_updates_spec.lua') diff --git a/test/functional/lua/buffer_updates_spec.lua b/test/functional/lua/buffer_updates_spec.lua index 0910218c08..6b2ca56e94 100644 --- a/test/functional/lua/buffer_updates_spec.lua +++ b/test/functional/lua/buffer_updates_spec.lua @@ -167,6 +167,8 @@ describe('lua: nvim_buf_attach on_lines', function() tick = tick + 1 check_events { { 'test2', 'lines', 1, tick, 1, 1, 2, 0 } } + -- Undo restored the cursor (|restore-undo-cursor|); pin it for the relative edits below. + api.nvim_win_set_cursor(0, { 5, 0 }) feed('wix') tick = tick + 1 check_events { { 'test2', 'lines', 1, tick, 4, 5, 5, 16 } } -- cgit