patch 8.0.0457: using :move messes up manual folds
Problem: Using :move messes up manual folds.
Solution: Split adjusting marks and folds. Add foldMoveRange(). (neovim
patch #6221)
diff --git a/src/ex_cmds.c b/src/ex_cmds.c
index 64d7f6b..8977302 100644
--- a/src/ex_cmds.c
+++ b/src/ex_cmds.c
@@ -800,6 +800,8 @@
linenr_T last_line; /* Last line in file after adding new text */
#ifdef FEAT_FOLDING
int isFolded;
+ win_T *win;
+ tabpage_T *tp;
/* Moving lines seems to corrupt the folds, delete folding info now
* and recreate it when finished. Don't do this for manual folding, it
@@ -851,24 +853,34 @@
* their final destination at the new text position -- webb
*/
last_line = curbuf->b_ml.ml_line_count;
- mark_adjust(line1, line2, last_line - line2, 0L);
- changed_lines(last_line - num_lines + 1, 0, last_line + 1, num_lines);
+ mark_adjust_nofold(line1, line2, last_line - line2, 0L);
if (dest >= line2)
{
- mark_adjust(line2 + 1, dest, -num_lines, 0L);
+ mark_adjust_nofold(line2 + 1, dest, -num_lines, 0L);
+#ifdef FEAT_FOLDING
+ FOR_ALL_TAB_WINDOWS(tp, win) {
+ if (win->w_buffer == curbuf)
+ foldMoveRange(&win->w_folds, line1, line2, dest);
+ }
+#endif
curbuf->b_op_start.lnum = dest - num_lines + 1;
curbuf->b_op_end.lnum = dest;
}
else
{
- mark_adjust(dest + 1, line1 - 1, num_lines, 0L);
+ mark_adjust_nofold(dest + 1, line1 - 1, num_lines, 0L);
+#ifdef FEAT_FOLDING
+ FOR_ALL_TAB_WINDOWS(tp, win) {
+ if (win->w_buffer == curbuf)
+ foldMoveRange(&win->w_folds, dest + 1, line1 - 1, line2);
+ }
+#endif
curbuf->b_op_start.lnum = dest + 1;
curbuf->b_op_end.lnum = dest + num_lines;
}
curbuf->b_op_start.col = curbuf->b_op_end.col = 0;
- mark_adjust(last_line - num_lines + 1, last_line,
+ mark_adjust_nofold(last_line - num_lines + 1, last_line,
-(last_line - dest - extra), 0L);
- changed_lines(last_line - num_lines + 1, 0, last_line + 1, -extra);
/*
* Now we delete the original text -- webb
@@ -907,9 +919,9 @@
changed_lines(dest + 1, 0, line1 + num_lines, 0L);
#ifdef FEAT_FOLDING
- /* recreate folds */
- if (isFolded)
- foldUpdateAll(curwin);
+ /* recreate folds */
+ if (isFolded)
+ foldUpdateAll(curwin);
#endif
return OK;