]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.0672: marker folds may get corrupted on undo v9.1.0672
authorChristian Brabandt <cb@256bit.org>
Sun, 11 Aug 2024 18:12:41 +0000 (20:12 +0200)
committerChristian Brabandt <cb@256bit.org>
Sun, 11 Aug 2024 18:12:41 +0000 (20:12 +0200)
Problem:  marker folds may get corrupted on undo (Yousef Mohammed)
Solution: when adjusting folds, make sure that line1 is the lower limit
          and line2 is the upper line limit. In particular, line2 should
          not be able to get smaller than line1.

fixes: #15455
closes: #15466

Signed-off-by: Christian Brabandt <cb@256bit.org>
src/fold.c
src/testdir/test_fold.vim
src/version.c

index 2cd4dcd5806e96cfb2d0f08e2b48b2dfb4a25d3f..3353cc55feaed8bea3f9c0ef75f6d0b32b1ddba7 100644 (file)
@@ -1492,6 +1492,9 @@ deleteFoldRecurse(garray_T *gap)
 // foldMarkAdjust() {{{2
 /*
  * Update line numbers of folds for inserted/deleted lines.
+ *
+ * We are adjusting the folds in the range from line1 til line2,
+ * make sure that line2 does not get smaller than line1
  */
     void
 foldMarkAdjust(
@@ -1505,6 +1508,8 @@ foldMarkAdjust(
     // lines, set line2 so that only deleted lines have their folds removed.
     if (amount == MAXLNUM && line2 >= line1 && line2 - line1 >= -amount_after)
        line2 = line1 - amount_after - 1;
+    if (line2 < line1)
+       line2 = line1;
     // If appending a line in Insert mode, it should be included in the fold
     // just above the line.
     if ((State & MODE_INSERT) && amount == (linenr_T)1 && line2 == MAXLNUM)
index 7fb004331149bbdbb24e6af30901344030b2f09e..17487a561e79ca9a9291262257ad6f3afd6d2fc7 100644 (file)
@@ -1928,4 +1928,25 @@ func Test_cursor_down_fold_eob()
   bwipe!
 endfunc
 
+" issue: #15455
+func Test_cursor_fold_marker_undo()
+  new
+  call setline(1, ['{{{', '', 'This is a Line', '', 'This is a Line', '', '}}}'])
+  let &ul=&ul
+  setl foldmethod=marker
+  call cursor(2, 1)
+  norm! zo1vjdu
+  call assert_equal(1, foldlevel('.'))
+  bwipe!
+  new
+  call setline(1, ['', '{{{', '', 'This is a Line', '', 'This is a Line', '', '}}}'])
+  let &ul=&ul
+  setl foldmethod=marker
+  call cursor(3, 1)
+  norm! zo
+  norm! vjdu
+  call assert_equal(1, foldlevel('.'))
+  bwipe!
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index ef1ffb0aeb4ddab71af663566c524562ce616e8f..159357e21b29c0dfd656305a60a60d5250c870b1 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    672,
 /**/
     671,
 /**/