]> granicus.if.org Git - vim/commitdiff
patch 8.2.4987: after deletion a small fold may be closable v8.2.4987
authorBrandon Simmons <simmsbra@gmail.com>
Fri, 20 May 2022 17:25:21 +0000 (18:25 +0100)
committerBram Moolenaar <Bram@vim.org>
Fri, 20 May 2022 17:25:21 +0000 (18:25 +0100)
Problem:    After deletion a small fold may be closable.
Solution:   Check for a reverse range. (Brandon Simmons, closes #10457)

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

index 7c51557073640c9a979e9940f3729b7e99d86f17..26a4a98a76ca37a2c471933285d1f8d6f12282ad 100644 (file)
@@ -829,10 +829,18 @@ foldUpdate(win_T *wp, linenr_T top, linenr_T bot)
 
     if (wp->w_folds.ga_len > 0)
     {
-       // Mark all folds from top to bot as maybe-small.
-       (void)foldFind(&wp->w_folds, top, &fp);
+       linenr_T        maybe_small_start = top;
+       linenr_T        maybe_small_end = bot;
+
+       // Mark all folds from top to bot (or bot to top) as maybe-small.
+       if (top > bot)
+       {
+           maybe_small_start = bot;
+           maybe_small_end = top;
+       }
+       (void)foldFind(&wp->w_folds, maybe_small_start, &fp);
        while (fp < (fold_T *)wp->w_folds.ga_data + wp->w_folds.ga_len
-               && fp->fd_top < bot)
+               && fp->fd_top <= maybe_small_end)
        {
            fp->fd_small = MAYBE;
            ++fp;
@@ -2165,7 +2173,7 @@ foldUpdateIEMS(win_T *wp, linenr_T top, linenr_T bot)
        bot = wp->w_buffer->b_ml.ml_line_count;
        wp->w_foldinvalid = FALSE;
 
-       // Mark all folds a maybe-small.
+       // Mark all folds as maybe-small.
        setSmallMaybe(&wp->w_folds);
     }
 
index 52185dca4359e492a9e05a00494f7969b3d97f1a..b0d07db15143ab6de62675b367d42284fdb7f4c0 100644 (file)
@@ -1479,4 +1479,33 @@ func Test_indent_append_under_blank_line()
   bw!
 endfunc
 
+" Make sure that when you delete 1 line of a fold whose length is 2 lines, the
+" fold can't be closed since its length (1) is now less than foldminlines.
+func Test_indent_one_line_fold_close()
+  let lines =<< trim END
+    line 1
+      line 2
+      line 3
+  END
+
+  new
+  setlocal sw=2 foldmethod=indent
+  call setline(1, lines)
+  " open all folds, delete line, then close all folds
+  normal zR
+  3delete
+  normal zM
+  call assert_equal(-1, foldclosed(2)) " the fold should not be closed
+
+  " Now do the same, but delete line 2 this time; this covers different code.
+  " (Combining this code with the above code doesn't expose both bugs.)
+  1,$delete
+  call setline(1, lines)
+  normal zR
+  2delete
+  normal zM
+  call assert_equal(-1, foldclosed(2))
+  bw!
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index b098a739003e2a4431ea7e531b66a22494420453..708f4a8ed3d43f1f0a978ea62e645c3ffa954cc8 100644 (file)
@@ -746,6 +746,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4987,
 /**/
     4986,
 /**/