From: altermo <107814000+altermo@users.noreply.github.com> Date: Thu, 1 Jan 2026 14:32:50 +0000 (+0000) Subject: patch 9.1.2037: undo: cursor position not correctly restored X-Git-Tag: v9.1.2037^0 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a722da29c128576d581f451f3f6282de27680d9f;p=thirdparty%2Fvim.git patch 9.1.2037: undo: cursor position not correctly restored Problem: undo: cursor position not correctly restored Solution: Do not override the saved cursor position (altermo) closes: #19052 Signed-off-by: altermo <107814000+altermo@users.noreply.github.com> Signed-off-by: Christian Brabandt --- diff --git a/src/testdir/test_undo.vim b/src/testdir/test_undo.vim index c69cf09bfc..ad724aa04d 100644 --- a/src/testdir/test_undo.vim +++ b/src/testdir/test_undo.vim @@ -913,5 +913,16 @@ func Test_load_existing_undofile() bw! endfunc +func Test_restore_cursor_position_after_undo() + CheckFeature persistent_undo + sp samples/test_undo.txt + + 3 | exe "norm! gqk" | undojoin | 1 delete + call assert_equal(1, line('.')) + norm! u + call assert_equal(3, line('.')) + bw! +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/undo.c b/src/undo.c index f40aca6605..54fdd22715 100644 --- a/src/undo.c +++ b/src/undo.c @@ -2721,7 +2721,6 @@ u_undoredo(int undo) // Decide about the cursor position, depending on what text changed. // Don't set it yet, it may be invalid if lines are going to be added. - if (top < newlnum) { // If the saved cursor is somewhere in this undo block, move it to // the remembered position. Makes "gwap" put the cursor back @@ -2730,9 +2729,12 @@ u_undoredo(int undo) if (lnum >= top && lnum <= top + newsize + 1) { new_curpos = curhead->uh_cursor; - newlnum = new_curpos.lnum - 1; + + // We don't want other entries to override saved cursor + // position. + newlnum = -1; } - else + else if (top < newlnum) { // Use the first line that actually changed. Avoids that // undoing auto-formatting puts the cursor in the previous diff --git a/src/version.c b/src/version.c index 77eed6f887..95992bcef7 100644 --- a/src/version.c +++ b/src/version.c @@ -734,6 +734,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 2037, /**/ 2036, /**/