Commit: patch 9.2.0222: "zb" scrolls incorrectly with cursor on fold

1 view
Skip to first unread message

Christian Brabandt

unread,
Mar 22, 2026, 12:02:09 PM (21 hours ago) Mar 22
to vim...@googlegroups.com
patch 9.2.0222: "zb" scrolls incorrectly with cursor on fold

Commit: https://github.com/vim/vim/commit/5a3b75d67b98777b319eb9c4e5e0d7a130aaec5e
Author: zeertzjq <zeer...@outlook.com>
Date: Sun Mar 22 15:49:59 2026 +0000

patch 9.2.0222: "zb" scrolls incorrectly with cursor on fold

Problem: "zb" scrolls incorrectly with cursor on fold.
Solution: Set w_botline to the line below the fold (zeertzjq).

related: neovim/neovim#38413
closes: #19785

Signed-off-by: zeertzjq <zeer...@outlook.com>
Signed-off-by: Christian Brabandt <c...@256bit.org>

diff --git a/src/move.c b/src/move.c
index 2bf8c2b74..ebc885361 100644
--- a/src/move.c
+++ b/src/move.c
@@ -2570,8 +2570,12 @@ scroll_cursor_bot(int min_scroll, int set_topbot)
if (set_topbot)
{
used = 0;
- curwin->w_botline = cln + 1;
- loff.lnum = cln + 1;
+ linenr_T cln_last = cln;
+#ifdef FEAT_FOLDING
+ (void)hasFolding(cln, NULL, &cln_last);
+#endif
+ curwin->w_botline = cln_last + 1;
+ loff.lnum = cln_last + 1;
#ifdef FEAT_DIFF
loff.fill = 0;
#endif
diff --git a/src/testdir/test_normal.vim b/src/testdir/test_normal.vim
index 20adb24b1..4f353c5b8 100644
--- a/src/testdir/test_normal.vim
+++ b/src/testdir/test_normal.vim
@@ -4269,6 +4269,20 @@ func Test_single_line_filler_zb()
bw!
endfunc

+" Test for zb with fewer buffer lines than window height, non-zero 'scrolloff'
+" and cursor on fold.
+func Test_zb_with_cursor_on_fold()
+ 15new
+ call setline(1, range(1, 5) + ['', 'foo{{{', 'bar}}}', '', 'baz'])
+ setlocal foldmethod=marker scrolloff=1
+ call assert_equal(8, foldclosedend(7))
+ call cursor(7, 1)
+ normal! zb
+ call assert_equal(1, line('w0'))
+
+ bwipe!
+endfunc
+
" Test for Ctrl-U not getting stuck at end of buffer with 'scrolloff'.
func Test_halfpage_scrolloff_eob()
set scrolloff=5
diff --git a/src/version.c b/src/version.c
index 9f578f20e..ca6585775 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 */
+/**/
+ 222,
/**/
221,
/**/
Reply all
Reply to author
Forward
0 new messages