patch 9.1.2118: 'cursorline' missing after :diffput to empty buf
Commit:
https://github.com/vim/vim/commit/ce1e562fdafa998e577d65a8b0a1b8bc1cbfcf4c
Author: zeertzjq <[email protected]>
Date: Fri Jan 30 09:57:56 2026 +0000
patch 9.1.2118: 'cursorline' missing after :diffput to empty buf
Problem: 'cursorline' and part of 'statusline' are missing after
:diffput to an empty buffer.
Solution: Make sure the cursor doesn't go beyond the last line after
:diffput (zeertzjq)
related: neovim/neovim#37621
closes: #19281
Signed-off-by: zeertzjq <[email protected]>
Signed-off-by: Christian Brabandt <[email protected]>
diff --git a/src/diff.c b/src/diff.c
index 8b2e83e79..2c359a92f 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -4224,7 +4224,13 @@ ex_diffgetput(exarg_T *eap)
// Adjust the cursor position if it's in/after the changed
// lines.
if (curwin->w_cursor.lnum >= lnum + count)
+ {
curwin->w_cursor.lnum += added;
+ // When the buffer was previously empty, the cursor may
+ // now be beyond the last line, so clamp cursor lnum.
+ curwin->w_cursor.lnum = MIN(curwin->w_cursor.lnum,
+ curbuf->b_ml.ml_line_count);
+ }
else if (added < 0)
curwin->w_cursor.lnum = lnum;
}
diff --git a/src/testdir/dumps/Test_diffput_to_empty_buf_01.dump
b/src/testdir/dumps/Test_diffput_to_empty_buf_01.dump
new file mode 100644
index 000000000..8fbd7a539
--- /dev/null
+++ b/src/testdir/dumps/Test_diffput_to_empty_buf_01.dump
@@ -0,0 +1,20 @@
+| +0#0000e05#a8a8a8255@1>f+8#0000000#5fd7ff255|o@1| @31||+1&#ffffff0|
+0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@34
+| +0#0000e05#a8a8a8255@1|b+0#0000000#5fd7ff255|a|r| @31||+1&#ffffff0|
+0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@34
+| +0#0000e05#a8a8a8255@1|b+0#0000000#5fd7ff255|a|z| @31||+1&#ffffff0|
+0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@34
+|~+0&#ffffff0| @35||+1#0000000&| +0#0000e05#a8a8a8255@1| +8#0000000#ffffff0@34
+|~+0#4040ff13&| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|[+3#0000000&|N|o| |N|a|m|e|]| |[|+|]| @5|1|,|1| @11|A|l@1| |[+1&&|N|o|
|N|a|m|e|]| @9|0|,|0|-|1| @9|A|l@1
+| +0&&@74
diff --git a/src/testdir/dumps/Test_diffput_to_empty_buf_02.dump
b/src/testdir/dumps/Test_diffput_to_empty_buf_02.dump
new file mode 100644
index 000000000..83cca781c
--- /dev/null
+++ b/src/testdir/dumps/Test_diffput_to_empty_buf_02.dump
@@ -0,0 +1,20 @@
+| +0#0000e05#a8a8a8255@1>f+8#0000000#ffffff0|o@1| @31||+1&&|
+0#0000e05#a8a8a8255@1|f+0#0000000#ffffff0|o@1| @31
+| +0#0000e05#a8a8a8255@1|b+0#0000000#ffffff0|a|r| @31||+1&&|
+0#0000e05#a8a8a8255@1|b+0#0000000#ffffff0|a|r| @31
+| +0#0000e05#a8a8a8255@1|b+0#0000000#ffffff0|a|z| @31||+1&&|
+0#0000e05#a8a8a8255@1|b+8#0000000#ffffff0|a|z| @31
+|~+0#4040ff13&| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|[+3#0000000&|N|o| |N|a|m|e|]| |[|+|]| @5|1|,|1| @11|A|l@1| |[+1&&|N|o|
|N|a|m|e|]| |[|+|]| @5|3|,|1| @11|A|l@1
+| +0&&@74
diff --git a/src/testdir/dumps/Test_diffput_to_empty_buf_03.dump
b/src/testdir/dumps/Test_diffput_to_empty_buf_03.dump
new file mode 100644
index 000000000..c7ca7cda9
--- /dev/null
+++ b/src/testdir/dumps/Test_diffput_to_empty_buf_03.dump
@@ -0,0 +1,20 @@
+| +0#0000e05#a8a8a8255@1|f+0#0000000#ffffff0|o@1| @31||+1&&|
+0#0000e05#a8a8a8255@1|f+0#0000000#ffffff0|o@1| @31
+| +0#0000e05#a8a8a8255@1>b+8#0000000#ffffff0|a|r| @31||+1&&|
+0#0000e05#a8a8a8255@1|b+8#0000000#ffffff0|a|r| @31
+| +0#0000e05#a8a8a8255@1|b+0#0000000#ffffff0|a|z| @31||+1&&|
+0#0000e05#a8a8a8255@1|b+0#0000000#ffffff0|a|z| @31
+|~+0#4040ff13&| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|[+3#0000000&|N|o| |N|a|m|e|]| |[|+|]| @5|2|,|1| @11|A|l@1| |[+1&&|N|o|
|N|a|m|e|]| |[|+|]| @5|2|,|1| @11|A|l@1
+| +0&&@74
diff --git a/src/testdir/test_diffmode.vim b/src/testdir/test_diffmode.vim
index e4ae57820..5562f5edd 100644
--- a/src/testdir/test_diffmode.vim
+++ b/src/testdir/test_diffmode.vim
@@ -3598,4 +3598,30 @@ func Test_diffexpr_wipe_buffers()
call StopVimInTerminal(buf)
endfunc
+func Test_diffput_to_empty_buf()
+ CheckScreendump
+
+ let lines =<< trim END
+ call setline(1, ['foo', 'bar', 'baz'])
+ rightbelow vnew
+ windo diffthis
+ windo set cursorline nofoldenable
+ wincmd t
+ END
+ call writefile(lines, 'Xtest_diffput_to_empty_buf', 'D')
+
+ let buf = RunVimInTerminal('-S Xtest_diffput_to_empty_buf', {})
+ call VerifyScreenDump(buf, 'Test_diffput_to_empty_buf_01', {})
+ call term_sendkeys(buf, '0') " Trigger an initial 'cursorbind' check.
+ call VerifyScreenDump(buf, 'Test_diffput_to_empty_buf_01', {})
+ call term_sendkeys(buf, ":diffput | echo\<CR>")
+ call VerifyScreenDump(buf, 'Test_diffput_to_empty_buf_02', {})
+ call term_sendkeys(buf, ":redraw!\<CR>")
+ call VerifyScreenDump(buf, 'Test_diffput_to_empty_buf_02', {})
+ call term_sendkeys(buf, 'j')
+ call VerifyScreenDump(buf, 'Test_diffput_to_empty_buf_03', {})
+
+ call StopVimInTerminal(buf)
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/version.c b/src/version.c
index aef56cbd2..c43326bbd 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 */
+/**/
+ 2118,
/**/
2117,
/**/
--
--
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/E1vllIM-003h0M-SZ%40256bit.org.