0
0
mirror of https://github.com/vim/vim.git synced 2025-09-23 03:43:49 -04:00

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)
This commit is contained in:
Bram Moolenaar
2017-03-14 21:53:58 +01:00
parent 84be8b6660
commit 88d298aed8
7 changed files with 355 additions and 10 deletions

View File

@@ -800,6 +800,8 @@ do_move(linenr_T line1, linenr_T line2, linenr_T dest)
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, linenr_T dest)
* 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, linenr_T dest)
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;