Hi there,

I noticed that part of neovim PR #6221 has been included in patch 88d298aed.
Recently some off-by-one errors have been fixed in that PR, so I'm sending a patch testing for them and fixing them.

Also, I noticed that the test that :move should not close folds in 'Test_move_folds_around_indent()' doesn't look at the case where folds are open because the user opened them with :foldopen or with zo, instead it checks for folds being open because of the value of 'foldlevel' (by using zR). As folds opened because of the 'foldlevel' setting haven't been getting closed after :move, but in recent versions of vim folds opened from zo or :foldopen have been closing after :move, the patch attached changes this test to look for folds opened because of :foldopen, and includes the change to pass this test.

Regards,

Matthew Malcomson

--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- You received this message because you are subscribed to the Google Groups "vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
diff --git a/src/ex_cmds.c b/src/ex_cmds.c
index 897730274..df35f52da 100644
--- a/src/ex_cmds.c
+++ b/src/ex_cmds.c
@@ -799,16 +799,8 @@ do_move(linenr_T line1, linenr_T line2, linenr_T dest)
     linenr_T	num_lines;  /* Num lines moved */
     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
-     * would delete all folds. */
-    isFolded = hasAnyFolding(curwin) && !foldmethodIsManual(curwin);
-    if (isFolded)
-	deleteFoldRecurse(&curwin->w_folds);
 #endif
 
     if (dest >= line1 && dest < line2)
@@ -918,12 +910,6 @@ do_move(linenr_T line1, linenr_T line2, linenr_T dest)
     else
 	changed_lines(dest + 1, 0, line1 + num_lines, 0L);
 
-#ifdef FEAT_FOLDING
-    /* recreate folds */
-    if (isFolded)
-	foldUpdateAll(curwin);
-#endif
-
     return OK;
 }
 
diff --git a/src/fold.c b/src/fold.c
index 6af71783b..8186c187d 100644
--- a/src/fold.c
+++ b/src/fold.c
@@ -3028,8 +3028,9 @@ foldReverseOrder(garray_T *gap, linenr_T start, linenr_T end)
     static void
 truncate_fold(fold_T *fp, linenr_T end)
 {
+    end += 1;
     foldRemove(&fp->fd_nested, end - fp->fd_top, MAXLNUM);
-    fp->fd_len = end - fp->fd_top + 1;
+    fp->fd_len = end - fp->fd_top;
 }
 
 #define fold_end(fp) ((fp)->fd_top + (fp)->fd_len - 1)
@@ -3069,7 +3070,7 @@ foldMoveRange_int(garray_T *gap, linenr_T line1, linenr_T line2, linenr_T dest)
 	}
 	else
 	    /* Case 2 truncate fold, folds after this one must be dealt with. */
-	    truncate_fold(fp, line1);
+	    truncate_fold(fp, line1 - 1);
 
 	/* Look at the next fold, and treat that one as if it were the first
 	 * after  "line1" (because now it is). */
@@ -3085,11 +3086,11 @@ foldMoveRange_int(garray_T *gap, linenr_T line1, linenr_T line2, linenr_T dest)
     }
     else if (fp->fd_top > line2)
     {
-	for (; valid_fold(fp, gap) && fold_end(fp) < dest; fp++)
+	for (; valid_fold(fp, gap) && fold_end(fp) <= dest; fp++)
 	/* Case 9. (for all case 9's) -- shift up. */
 	    fp->fd_top -= range_len;
 
-	if (valid_fold(fp, gap) && fp->fd_top < dest)
+	if (valid_fold(fp, gap) && fp->fd_top <= dest)
 	{
 	    /* Case 8. -- ensure truncated at dest, shift up */
 	    truncate_fold(fp, dest);
diff --git a/src/testdir/test_fold.vim b/src/testdir/test_fold.vim
index 19c94140d..46c54e861 100644
--- a/src/testdir/test_fold.vim
+++ b/src/testdir/test_fold.vim
@@ -249,7 +249,7 @@ func! Test_move_folds_around_manual()
   redraw!
   set fdm=manual
   call cursor(2, 1)
-  norm! zR
+  %foldopen
   7,12m0
   let folds=repeat([-1], 18)
   call assert_equal(PrepIndent("b") + PrepIndent("a") + PrepIndent("c"), getline(1, '$'))
@@ -284,6 +284,16 @@ func! Test_move_folds_around_manual()
   call assert_equal(0, foldlevel(6))
   call assert_equal(9, foldclosedend(7))
   call assert_equal([-1, 2, 2, 2, 2, -1, 7, 7, 7, -1], map(range(1, line('$')), 'foldclosed(v:val)'))
+  %d
+  " Ensure moving around the edges still works.
+  call setline(1, PrepIndent("a") + repeat(["a"], 3) + ["\ta"])
+  set fdm=indent foldlevel=0
+  set fdm=manual
+  %foldopen
+  6m$
+  " The first fold has been truncated to the 5'th line.
+  " Second fold has been moved up because the moved line is now below it.
+  call assert_equal([0, 1, 1, 1, 1, 0, 0, 0, 1, 0], map(range(1, line('$')), 'foldlevel(v:val)'))
   bw!
 endfunc
 
@@ -307,7 +317,7 @@ func! Test_move_folds_around_indent()
   call setline(1, PrepIndent("a") + PrepIndent("b") + PrepIndent("c"))
   set fdm=indent
   call cursor(2, 1)
-  norm! zR
+  %foldopen
   7,12m0
   let folds=repeat([-1], 18)
   call assert_equal(PrepIndent("b") + PrepIndent("a") + PrepIndent("c"), getline(1, '$'))
@@ -339,5 +349,14 @@ func! Test_move_folds_around_indent()
   call assert_equal(1, foldlevel(6))
   call assert_equal(9, foldclosedend(7))
   call assert_equal([-1, 2, 2, 2, 2, 2, 2, 2, 2, -1], map(range(1, line('$')), 'foldclosed(v:val)'))
+  " Ensure moving around the edges still works.
+  %d
+  call setline(1, PrepIndent("a") + repeat(["a"], 3) + ["\ta"])
+  set fdm=indent foldlevel=0
+  %foldopen
+  6m$
+  " The first fold has been truncated to the 5'th line.
+  " Second fold has been moved up because the moved line is now below it.
+  call assert_equal([0, 1, 1, 1, 1, 0, 0, 0, 1, 1], map(range(1, line('$')), 'foldlevel(v:val)'))
   bw!
 endfunc

Raspunde prin e-mail lui