Commit: patch 9.2.0938: cursorbind: cursor in the other window is not updated after undo

Christian Brabandt <[email protected]> Tue, 11 Aug 2026 21:15:06 +0200
Newsgroups gmane.editors.vim.devel
Message-ID <[email protected]>
patch 9.2.0938: cursorbind: cursor in the other window is not updated after undo

Commit: https://github.com/vim/vim/commit/2045a20d4bf604c47828bfc22d2da25f0294bc01
Author: Hirohito Higashi <[email protected]>
Date:   Tue Aug 11 19:10:19 2026 +0000

    patch 9.2.0938: cursorbind: cursor in the other window is not updated after undo
    
    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) <[email protected]>
    Signed-off-by: Hirohito Higashi <[email protected]>
    Signed-off-by: zeertzjq <[email protected]>
    Signed-off-by: Christian Brabandt <[email protected]>

diff --git a/src/move.c b/src/move.c
index 6e7921cc2..635e63eb2 100644
--- a/src/move.c
+++ b/src/move.c
@@ -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;
diff --git a/src/testdir/test_diffmode.vim b/src/testdir/test_diffmode.vim
index 7fc4a3248..7165e19d8 100644
--- a/src/testdir/test_diffmode.vim
+++ b/src/testdir/test_diffmode.vim
@@ -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
diff --git a/src/version.c b/src/version.c
index a5cb9e1dd..48a1faf0f 100644
--- a/src/version.c
+++ b/src/version.c
@@ -763,6 +763,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    938,
 /**/
     937,
 /**/

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups "vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion visit https://groups.google.com/d/msgid/vim_dev/E1wtrwI-007Z5S-EC%40256bit.org.