]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.2.0938: cursorbind: cursor in the other window is not updated after undo v9.2.0938
authorHirohito Higashi <h.east.727@gmail.com>
Tue, 11 Aug 2026 19:10:19 +0000 (19:10 +0000)
committerChristian Brabandt <cb@256bit.org>
Tue, 11 Aug 2026 19:12:19 +0000 (19:12 +0000)
Problem:  In diff mode with 'cursorbind' the cursor in the other window is
          not updated after an undo that changes which lines correspond.
Solution: Also check whether the text changed before skipping the update
          (Hirohito Higashi).

fixes:   #20982
related: #13219
related: #13210
closes:  #21004

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Hirohito Higashi <h.east.727@gmail.com>
Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/move.c
src/testdir/test_diffmode.vim
src/version.c

index 6e7921cc2b80eabbb064e2ef8e584f3d6be69eca..635e63eb286bdc1e9b07a36c48ba914d2f8befbf 100644 (file)
@@ -3408,11 +3408,19 @@ pagescroll(int dir, long count, int half)
 do_check_cursorbind(void)
 {
     static win_T       *prev_curwin = NULL;
+    static buf_T       *prev_curbuf = NULL;
+    static varnumber_T prev_changedtick = 0;
     static pos_T       prev_cursor = {0, 0, 0};
 
-    if (curwin == prev_curwin && EQUAL_POS(curwin->w_cursor, prev_cursor))
+    // Nothing to do when the cursor didn't move and the text didn't change.
+    // After a change the corresponding line in a diff may be different.
+    if (curwin == prev_curwin && curbuf == prev_curbuf
+           && CHANGEDTICK(curbuf) == prev_changedtick
+           && EQUAL_POS(curwin->w_cursor, prev_cursor))
        return;
     prev_curwin = curwin;
+    prev_curbuf = curbuf;
+    prev_changedtick = CHANGEDTICK(curbuf);
     prev_cursor = curwin->w_cursor;
 
     linenr_T   line = curwin->w_cursor.lnum;
index 7fc4a32483c77f5f29c7a67c7f0c7e00fc31fd17..7165e19d87dda895e35e7bfea5992352c4313356 100644 (file)
@@ -3646,4 +3646,29 @@ func Test_diffput_to_empty_buf()
   call StopVimInTerminal(buf)
 endfunc
 
+" Undo can change which lines correspond in a diff. 'cursorbind' must update
+" the other window even when the cursor here did not move.
+func Test_diff_cursorbind_after_undo()
+  call setline(1, ['x', 'y', 'c', 'd'])
+  let w1 = win_getid()
+  new
+  call setline(1, ['p', 'q', 'c', 'd'])
+  let w2 = win_getid()
+  windo diffthis
+  call win_gotoid(w1)
+
+  normal! 2dd
+  call assert_equal(1, line('.', w1))
+  call assert_equal(1, line('.', w2))
+  normal! jk
+  call assert_equal(1, line('.', w1))
+  call assert_equal(3, line('.', w2))
+
+  normal! u
+  call assert_equal(1, line('.', w1))
+  call assert_equal(1, line('.', w2))
+
+  %bw!
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index a5cb9e1ddd2a7bd461990333ca9f745f2c8dca39..48a1faf0fb1a57b7a5edf3ca84c4f6f7217e1515 100644 (file)
@@ -763,6 +763,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    938,
 /**/
     937,
 /**/