diff src/ex_cmds.c @ 11140:6b26e044b6f5 v8.0.0457

patch 8.0.0457: using :move messes up manual folds commit https://github.com/vim/vim/commit/88d298aed8682eac872ebfe40df3112a6acd83e8 Author: Bram Moolenaar <Bram@vim.org> Date: Tue Mar 14 21:53:58 2017 +0100 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)
author Christian Brabandt <cb@256bit.org>
date Tue, 14 Mar 2017 22:00:05 +0100
parents f4ea50924c6d
children e85aa0e46ca5
line wrap: on
line diff
--- a/src/ex_cmds.c
+++ b/src/ex_cmds.c
@@ -800,6 +800,8 @@ do_move(linenr_T line1, linenr_T line2, 
     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 @@ do_move(linenr_T line1, linenr_T line2, 
      * 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 @@ do_move(linenr_T line1, linenr_T line2, 
 	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;