patch 9.1.0672: marker folds may get corrupted on undo
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>
diff --git a/src/fold.c b/src/fold.c
index 2cd4dcd..3353cc5 100644
--- a/src/fold.c
+++ b/src/fold.c
@@ -1492,6 +1492,9 @@
// 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 @@
// 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)
diff --git a/src/testdir/test_fold.vim b/src/testdir/test_fold.vim
index 7fb0043..17487a5 100644
--- a/src/testdir/test_fold.vim
+++ b/src/testdir/test_fold.vim
Binary files differ
diff --git a/src/version.c b/src/version.c
index ef1ffb0..159357e 100644
--- a/src/version.c
+++ b/src/version.c
@@ -705,6 +705,8 @@
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 672,
+/**/
671,
/**/
670,