]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.2.0874: fold size is compared against 'foldminlines' of the wrong window v9.2.0874
authorIgor Mikushkin <igor.mikushkin@gmail.com>
Wed, 29 Jul 2026 18:53:08 +0000 (18:53 +0000)
committerChristian Brabandt <cb@256bit.org>
Wed, 29 Jul 2026 18:53:08 +0000 (18:53 +0000)
Problem:  checkSmall() compares the fold size of window "wp" against
          the current window's 'foldminlines'.  A fold of another
          window, e.g. measured while it is redrawn, is judged by an
          unrelated option value.
Solution: Use 'foldminlines' of the window containing the fold
          (Igor Mikushkin).

closes: #20864

Co-authored-by: Claude <noreply@anthropic.com>
Signed-off-by: Igor Mikushkin <igor.mikushkin@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/fold.c
src/testdir/test_fold.vim
src/version.c

index 19c444c14c98f7f67b45132fb6bc9cafc3cdf463..04698429d68f0633e4e9ed886ee66ca49b2a9313 100644 (file)
@@ -1730,7 +1730,7 @@ checkSmall(
     // Mark any nested folds to maybe-small
     setSmallMaybe(&fp->fd_nested);
 
-    if (fp->fd_len > curwin->w_p_fml)
+    if (fp->fd_len > wp->w_p_fml)
        fp->fd_small = FALSE;
     else
     {
@@ -1738,7 +1738,7 @@ checkSmall(
        for (n = 0; n < fp->fd_len; ++n)
        {
            count += plines_win_nofold(wp, fp->fd_top + lnum_off + n);
-           if (count > curwin->w_p_fml)
+           if (count > wp->w_p_fml)
            {
                fp->fd_small = FALSE;
                return;
index d4b3a5093b22274cb4e758f3e048fa0982254796..1c09719b136beb5799b78b3adc27ad7bc7f91552 100644 (file)
@@ -2105,4 +2105,42 @@ func Test_cursor_fold_marker_undo()
   bwipe!
 endfunc
 
+" The fold size must be compared against 'foldminlines' of the window that
+" contains the fold, not of the current window.
+func Test_foldminlines_per_window()
+  " Window with 'foldminlines'=5: its two-line fold stays displayed open.
+  new
+  setlocal foldenable foldmethod=manual foldminlines=5
+  call setline(1, ['one', 'two', 'three', 'four'])
+  2,3fold
+  call assert_equal(-1, foldclosed(2))
+  let winid = win_getid()
+
+  " Split; only the new current window gets 'foldminlines'=0.  setline()
+  " invalidates the fold sizes of both windows and measures them again right
+  " away, the other window's while this window is current.  win_execute()
+  " below only reads that cached verdict, without measuring again.
+  split
+  setlocal foldminlines=0
+  call setline(2, 'changed')
+  call assert_equal(2, foldclosed(2))
+  call win_execute(winid, 'call assert_equal(-1, foldclosed(2))')
+  bwipe!
+
+  " The same the other way around: 'foldminlines'=0 in the other window, so
+  " its fold must remain closed while the current window has a higher value.
+  new
+  setlocal foldenable foldmethod=manual foldminlines=0
+  call setline(1, ['one', 'two', 'three', 'four'])
+  2,3fold
+  call assert_equal(2, foldclosed(2))
+  let winid = win_getid()
+  split
+  setlocal foldminlines=5
+  call setline(2, 'changed')
+  call assert_equal(-1, foldclosed(2))
+  call win_execute(winid, 'call assert_equal(2, foldclosed(2))')
+  bwipe!
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index 1f78ca0d8517cfb507b16634aaf3da4589d2294a..9d2474d6874acd12bac6716ea8e6b4a88f581007 100644 (file)
@@ -758,6 +758,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    874,
 /**/
     873,
 /**/