patch 8.2.4935: with 'foldmethod' "indent" some lines not included in fold v8.2.4935
authorBrandon Simmons <simmsbra@gmail.com>
Tue, 10 May 2022 18:13:23 +0000 (19:13 +0100)
committerBram Moolenaar <Bram@vim.org>
Tue, 10 May 2022 18:13:23 +0000 (19:13 +0100)
Problem:    With 'foldmethod' "indent" some lines are not included in the
            fold. (Oleg Koshovetc)
Solution:   Fix it. (Brandon Simmons, closes #10399, closes #3214)

src/fold.c
src/testdir/test_fold.vim
src/version.c

index f94b38949bb1d51741c4b18bcad4ae37c1990745..7c51557073640c9a979e9940f3729b7e99d86f17 100644 (file)
@@ -2246,7 +2246,14 @@ foldUpdateIEMS(win_T *wp, linenr_T top, linenr_T bot)
            getlevel = foldlevelDiff;
 #endif
        else
+       {
            getlevel = foldlevelIndent;
+           // Start one line back, because if the line above "top" has an
+           // undefined fold level, folding it relies on the line under it,
+           // which is "top".
+           if (top > 1)
+               --fline.lnum;
+       }
 
        // Backup to a line for which the fold level is defined.  Since it's
        // always defined for line one, we will stop there.
index 3abb81aaffcf3534c231738f3c3171716458fb35..52185dca4359e492a9e05a00494f7969b3d97f1a 100644 (file)
@@ -1459,4 +1459,24 @@ func Test_fold_split()
   bw!
 endfunc
 
+" Make sure that when you append under a blank line that is under a fold with
+" the same indent level as your appended line, the fold expands across the
+" blank line
+func Test_indent_append_under_blank_line()
+  new
+  let lines =<< trim END
+    line 1
+      line 2
+      line 3
+  END
+  call setline(1, lines)
+  setlocal sw=2
+  setlocal foldmethod=indent foldenable
+  call assert_equal([0, 1, 1], range(1, 3)->map('foldlevel(v:val)'))
+  call append(3, '')
+  call append(4, '  line 5')
+  call assert_equal([0, 1, 1, 1, 1], range(1, 5)->map('foldlevel(v:val)'))
+  bw!
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index 80f631bdc37d61b4a2c6e92e9aecd54db83406b8..2de3cb1c3d7527cd15780390e01080b737534f17 100644 (file)
@@ -746,6 +746,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4935,
 /**/
     4934,
 /**/