Skip to content

Commit 94be619

Browse files
committed
patch 8.0.0581: moving folded text is sometimes not correct
Problem: Moving folded text is sometimes not correct. Solution: Bail out when "move_end" is zero. (Matthew Malcomson)
1 parent f1d21c8 commit 94be619

File tree

3 files changed

+61
-22
lines changed

3 files changed

+61
-22
lines changed

src/fold.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3133,10 +3133,14 @@ foldMoveRange(garray_T *gap, linenr_T line1, linenr_T line2, linenr_T dest)
31333133
dest_index = fold_index(fp, gap);
31343134

31353135
/*
3136-
* All folds are now correct, but they are not necessarily in the correct
3137-
* order. We have to swap folds in the range [move_end, dest_index) with
3138-
* those in the range [move_start, move_end).
3136+
* All folds are now correct, but not necessarily in the correct order. We
3137+
* must swap folds in the range [move_end, dest_index) with those in the
3138+
* range [move_start, move_end).
31393139
*/
3140+
if (move_end == 0)
3141+
/* There are no folds after those moved, hence no folds have been moved
3142+
* out of order. */
3143+
return;
31403144
foldReverseOrder(gap, (linenr_T)move_start, (linenr_T)dest_index - 1);
31413145
foldReverseOrder(gap, (linenr_T)move_start,
31423146
(linenr_T)(move_start + dest_index - move_end - 1));

src/testdir/test_fold.vim

Lines changed: 52 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
" Test for folding
22

3-
func! PrepIndent(arg)
3+
func PrepIndent(arg)
44
return [a:arg] + repeat(["\t".a:arg], 5)
55
endfu
66

7-
func! Test_address_fold()
7+
func Test_address_fold()
88
new
99
call setline(1, ['int FuncName() {/*{{{*/', 1, 2, 3, 4, 5, '}/*}}}*/',
1010
\ 'after fold 1', 'after fold 2', 'after fold 3'])
@@ -68,17 +68,7 @@ func! Test_address_fold()
6868
quit!
6969
endfunc
7070

71-
func! Test_indent_fold()
72-
new
73-
call setline(1, ['', 'a', ' b', ' c'])
74-
setl fen fdm=indent
75-
2
76-
norm! >>
77-
let a=map(range(1,4), 'foldclosed(v:val)')
78-
call assert_equal([-1,-1,-1,-1], a)
79-
endfunc
80-
81-
func! Test_indent_fold()
71+
func Test_indent_fold()
8272
new
8373
call setline(1, ['', 'a', ' b', ' c'])
8474
setl fen fdm=indent
@@ -89,7 +79,7 @@ func! Test_indent_fold()
8979
bw!
9080
endfunc
9181

92-
func! Test_indent_fold2()
82+
func Test_indent_fold2()
9383
new
9484
call setline(1, ['', '{{{', '}}}', '{{{', '}}}'])
9585
setl fen fdm=marker
@@ -122,7 +112,7 @@ func Test_manual_fold_with_filter()
122112
endfor
123113
endfunc
124114

125-
func! Test_indent_fold_with_read()
115+
func Test_indent_fold_with_read()
126116
new
127117
set foldmethod=indent
128118
call setline(1, repeat(["\<Tab>a"], 4))
@@ -224,7 +214,11 @@ func Test_update_folds_expr_read()
224214
set foldmethod& foldexpr&
225215
endfunc
226216

227-
func! Test_move_folds_around_manual()
217+
func Check_foldlevels(expected)
218+
call assert_equal(a:expected, map(range(1, line('$')), 'foldlevel(v:val)'))
219+
endfunc
220+
221+
func Test_move_folds_around_manual()
228222
new
229223
let input = PrepIndent("a") + PrepIndent("b") + PrepIndent("c")
230224
call setline(1, PrepIndent("a") + PrepIndent("b") + PrepIndent("c"))
@@ -293,11 +287,50 @@ func! Test_move_folds_around_manual()
293287
6m$
294288
" The first fold has been truncated to the 5'th line.
295289
" Second fold has been moved up because the moved line is now below it.
296-
call assert_equal([0, 1, 1, 1, 1, 0, 0, 0, 1, 0], map(range(1, line('$')), 'foldlevel(v:val)'))
290+
call Check_foldlevels([0, 1, 1, 1, 1, 0, 0, 0, 1, 0])
291+
292+
%delete
293+
set fdm=indent foldlevel=0
294+
call setline(1, [
295+
\ "a",
296+
\ "\ta",
297+
\ "\t\ta",
298+
\ "\t\ta",
299+
\ "\t\ta",
300+
\ "a",
301+
\ "a"])
302+
set fdm=manual
303+
%foldopen!
304+
4,5m6
305+
call Check_foldlevels([0, 1, 2, 0, 0, 0, 0])
306+
307+
%delete
308+
set fdm=indent
309+
call setline(1, [
310+
\ "\ta",
311+
\ "\t\ta",
312+
\ "\t\ta",
313+
\ "\t\ta",
314+
\ "\ta",
315+
\ "\t\ta",
316+
\ "\t\ta",
317+
\ "\t\ta",
318+
\ "\ta",
319+
\ "\t\ta",
320+
\ "\t\ta",
321+
\ "\t\ta",
322+
\ "\t\ta",
323+
\ "\ta",
324+
\ "a"])
325+
set fdm=manual
326+
%foldopen!
327+
13m7
328+
call Check_foldlevels([1, 2, 2, 2, 1, 2, 2, 1, 1, 1, 2, 2, 2, 1, 0])
329+
297330
bw!
298331
endfunc
299332

300-
func! Test_move_folds_around_indent()
333+
func Test_move_folds_around_indent()
301334
new
302335
let input = PrepIndent("a") + PrepIndent("b") + PrepIndent("c")
303336
call setline(1, PrepIndent("a") + PrepIndent("b") + PrepIndent("c"))
@@ -357,7 +390,7 @@ func! Test_move_folds_around_indent()
357390
6m$
358391
" The first fold has been truncated to the 5'th line.
359392
" Second fold has been moved up because the moved line is now below it.
360-
call assert_equal([0, 1, 1, 1, 1, 0, 0, 0, 1, 1], map(range(1, line('$')), 'foldlevel(v:val)'))
393+
call Check_foldlevels([0, 1, 1, 1, 1, 0, 0, 0, 1, 1])
361394
bw!
362395
endfunc
363396

src/version.c

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

765765
static int included_patches[] =
766766
{ /* Add new patch number below this line */
767+
/**/
768+
581,
767769
/**/
768770
580,
769771
/**/

0 commit comments

Comments
 (0)