]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.2.0222: "zb" scrolls incorrectly with cursor on fold v9.2.0222
authorzeertzjq <zeertzjq@outlook.com>
Sun, 22 Mar 2026 15:49:59 +0000 (15:49 +0000)
committerChristian Brabandt <cb@256bit.org>
Sun, 22 Mar 2026 15:49:59 +0000 (15:49 +0000)
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 <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/move.c
src/testdir/test_normal.vim
src/version.c

index 2bf8c2b74a188b8bae05ca7348d4f60f03f4657a..ebc88536174ef56a7e80c7a5fca551c94823c1cc 100644 (file)
@@ -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
index 20adb24b1ed1bdfdf963a0ace98cd05cb2fa3ba0..4f353c5b8c1db659da792b7a05fa29fbac08ee4d 100644 (file)
@@ -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
index 9f578f20e2578104e09eb78c0ff88bf2b774196d..ca65857756534f5c1a70adb29ad2210b8381dbef 100644 (file)
@@ -734,6 +734,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    222,
 /**/
     221,
 /**/