Skip to content

Commit 8db654e

Browse files
brammooldouglaskayama
authored andcommitted
patch 7.4.700 Problem: Fold can't be opened after ":move". (Ein Brown) Solution: Delete the folding information and update it afterwards. (Christian Brabandt)
1 parent 5027f23 commit 8db654e

5 files changed

Lines changed: 35 additions & 2 deletions

File tree

src/ex_cmds.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,16 @@ do_move(line1, line2, dest)
741741
linenr_T extra; /* Num lines added before line1 */
742742
linenr_T num_lines; /* Num lines moved */
743743
linenr_T last_line; /* Last line in file after adding new text */
744+
#ifdef FEAT_FOLDING
745+
int isFolded;
746+
747+
/* Moving lines seems to corrupt the folds, delete folding info now
748+
* and recreate it when finished. Don't do this for manual folding, it
749+
* would delete all folds. */
750+
isFolded = hasAnyFolding(curwin) && !foldmethodIsManual(curwin);
751+
if (isFolded)
752+
deleteFoldRecurse(&curwin->w_folds);
753+
#endif
744754

745755
if (dest >= line1 && dest < line2)
746756
{
@@ -839,6 +849,12 @@ do_move(line1, line2, dest)
839849
else
840850
changed_lines(dest + 1, 0, line1 + num_lines, 0L);
841851

852+
#ifdef FEAT_FOLDING
853+
/* recreate folds */
854+
if (isFolded)
855+
foldUpdateAll(curwin);
856+
#endif
857+
842858
return OK;
843859
}
844860

src/fold.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -847,8 +847,8 @@ foldUpdate(wp, top, bot)
847847
fold_T *fp;
848848

849849
/* Mark all folds from top to bot as maybe-small. */
850-
(void)foldFind(&curwin->w_folds, top, &fp);
851-
while (fp < (fold_T *)curwin->w_folds.ga_data + curwin->w_folds.ga_len
850+
(void)foldFind(&wp->w_folds, top, &fp);
851+
while (fp < (fold_T *)wp->w_folds.ga_data + wp->w_folds.ga_len
852852
&& fp->fd_top < bot)
853853
{
854854
fp->fd_small = MAYBE;

src/testdir/test45.in

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,16 @@ endfun
6363
:call append("$", foldlevel("."))
6464
:/^last/+1,$w! test.out
6565
:delfun Flvl
66+
:new
67+
iTest fdm=indent and :move bug END
68+
line2
69+
Test fdm=indent START
70+
line3
71+
line4
72+
:set fdm=indent
73+
:1m1
74+
2jzc:m0
75+
:%w >> test.out
6676
:qa!
6777
ENDTEST
6878

src/testdir/test45.ok

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,8 @@ expr 2
1616
1
1717
2
1818
0
19+
Test fdm=indent START
20+
line3
21+
line4
22+
Test fdm=indent and :move bug END
23+
line2

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,8 @@ static char *(features[]) =
756756

757757
static int included_patches[] =
758758
{ /* Add new patch number below this line */
759+
/**/
760+
700,
759761
/**/
760762
699,
761763
/**/

0 commit comments

Comments
 (0)