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<Esc>`, `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).
This commit is contained in:
Justin M. Keyes
2026-08-27 16:12:11 -04:00
committed by GitHub
parent 617f9e628c
commit 7e2e3f8c25
16 changed files with 185 additions and 137 deletions

View File

@@ -888,11 +888,12 @@ describe('API/extmarks', function()
set_extmark(ns, marks[1], 1, 2)
feed('0<c-v>k>')
check_undo_redo(ns, marks[1], 1, 2, 1, 6)
feed('<c-v>j>')
-- "gg0": the cursor after undo/redo depends on |restore-undo-cursor|.
feed('gg0<c-v>j>')
expect('\t12345\n\t12345')
check_undo_redo(ns, marks[1], 1, 6, 1, 3)
feed('<c-v>j<LT>')
feed('gg0<c-v>j<LT>')
check_undo_redo(ns, marks[1], 1, 3, 1, 6)
end)