mirror of
https://github.com/vim/vim.git
synced 2025-09-01 21:03:39 -04:00
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)
This commit is contained in:
parent
f1d21c8cc8
commit
94be619e30
10
src/fold.c
10
src/fold.c
@ -3133,10 +3133,14 @@ foldMoveRange(garray_T *gap, linenr_T line1, linenr_T line2, linenr_T dest)
|
|||||||
dest_index = fold_index(fp, gap);
|
dest_index = fold_index(fp, gap);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* All folds are now correct, but they are not necessarily in the correct
|
* All folds are now correct, but not necessarily in the correct order. We
|
||||||
* order. We have to swap folds in the range [move_end, dest_index) with
|
* must swap folds in the range [move_end, dest_index) with those in the
|
||||||
* those in the range [move_start, move_end).
|
* range [move_start, move_end).
|
||||||
*/
|
*/
|
||||||
|
if (move_end == 0)
|
||||||
|
/* There are no folds after those moved, hence no folds have been moved
|
||||||
|
* out of order. */
|
||||||
|
return;
|
||||||
foldReverseOrder(gap, (linenr_T)move_start, (linenr_T)dest_index - 1);
|
foldReverseOrder(gap, (linenr_T)move_start, (linenr_T)dest_index - 1);
|
||||||
foldReverseOrder(gap, (linenr_T)move_start,
|
foldReverseOrder(gap, (linenr_T)move_start,
|
||||||
(linenr_T)(move_start + dest_index - move_end - 1));
|
(linenr_T)(move_start + dest_index - move_end - 1));
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
" Test for folding
|
" Test for folding
|
||||||
|
|
||||||
func! PrepIndent(arg)
|
func PrepIndent(arg)
|
||||||
return [a:arg] + repeat(["\t".a:arg], 5)
|
return [a:arg] + repeat(["\t".a:arg], 5)
|
||||||
endfu
|
endfu
|
||||||
|
|
||||||
func! Test_address_fold()
|
func Test_address_fold()
|
||||||
new
|
new
|
||||||
call setline(1, ['int FuncName() {/*{{{*/', 1, 2, 3, 4, 5, '}/*}}}*/',
|
call setline(1, ['int FuncName() {/*{{{*/', 1, 2, 3, 4, 5, '}/*}}}*/',
|
||||||
\ 'after fold 1', 'after fold 2', 'after fold 3'])
|
\ 'after fold 1', 'after fold 2', 'after fold 3'])
|
||||||
@ -68,17 +68,7 @@ func! Test_address_fold()
|
|||||||
quit!
|
quit!
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func! Test_indent_fold()
|
func Test_indent_fold()
|
||||||
new
|
|
||||||
call setline(1, ['', 'a', ' b', ' c'])
|
|
||||||
setl fen fdm=indent
|
|
||||||
2
|
|
||||||
norm! >>
|
|
||||||
let a=map(range(1,4), 'foldclosed(v:val)')
|
|
||||||
call assert_equal([-1,-1,-1,-1], a)
|
|
||||||
endfunc
|
|
||||||
|
|
||||||
func! Test_indent_fold()
|
|
||||||
new
|
new
|
||||||
call setline(1, ['', 'a', ' b', ' c'])
|
call setline(1, ['', 'a', ' b', ' c'])
|
||||||
setl fen fdm=indent
|
setl fen fdm=indent
|
||||||
@ -89,7 +79,7 @@ func! Test_indent_fold()
|
|||||||
bw!
|
bw!
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func! Test_indent_fold2()
|
func Test_indent_fold2()
|
||||||
new
|
new
|
||||||
call setline(1, ['', '{{{', '}}}', '{{{', '}}}'])
|
call setline(1, ['', '{{{', '}}}', '{{{', '}}}'])
|
||||||
setl fen fdm=marker
|
setl fen fdm=marker
|
||||||
@ -122,7 +112,7 @@ func Test_manual_fold_with_filter()
|
|||||||
endfor
|
endfor
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func! Test_indent_fold_with_read()
|
func Test_indent_fold_with_read()
|
||||||
new
|
new
|
||||||
set foldmethod=indent
|
set foldmethod=indent
|
||||||
call setline(1, repeat(["\<Tab>a"], 4))
|
call setline(1, repeat(["\<Tab>a"], 4))
|
||||||
@ -224,7 +214,11 @@ func Test_update_folds_expr_read()
|
|||||||
set foldmethod& foldexpr&
|
set foldmethod& foldexpr&
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func! Test_move_folds_around_manual()
|
func Check_foldlevels(expected)
|
||||||
|
call assert_equal(a:expected, map(range(1, line('$')), 'foldlevel(v:val)'))
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
func Test_move_folds_around_manual()
|
||||||
new
|
new
|
||||||
let input = PrepIndent("a") + PrepIndent("b") + PrepIndent("c")
|
let input = PrepIndent("a") + PrepIndent("b") + PrepIndent("c")
|
||||||
call setline(1, PrepIndent("a") + PrepIndent("b") + PrepIndent("c"))
|
call setline(1, PrepIndent("a") + PrepIndent("b") + PrepIndent("c"))
|
||||||
@ -293,11 +287,50 @@ func! Test_move_folds_around_manual()
|
|||||||
6m$
|
6m$
|
||||||
" The first fold has been truncated to the 5'th line.
|
" 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.
|
" 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)'))
|
call Check_foldlevels([0, 1, 1, 1, 1, 0, 0, 0, 1, 0])
|
||||||
|
|
||||||
|
%delete
|
||||||
|
set fdm=indent foldlevel=0
|
||||||
|
call setline(1, [
|
||||||
|
\ "a",
|
||||||
|
\ "\ta",
|
||||||
|
\ "\t\ta",
|
||||||
|
\ "\t\ta",
|
||||||
|
\ "\t\ta",
|
||||||
|
\ "a",
|
||||||
|
\ "a"])
|
||||||
|
set fdm=manual
|
||||||
|
%foldopen!
|
||||||
|
4,5m6
|
||||||
|
call Check_foldlevels([0, 1, 2, 0, 0, 0, 0])
|
||||||
|
|
||||||
|
%delete
|
||||||
|
set fdm=indent
|
||||||
|
call setline(1, [
|
||||||
|
\ "\ta",
|
||||||
|
\ "\t\ta",
|
||||||
|
\ "\t\ta",
|
||||||
|
\ "\t\ta",
|
||||||
|
\ "\ta",
|
||||||
|
\ "\t\ta",
|
||||||
|
\ "\t\ta",
|
||||||
|
\ "\t\ta",
|
||||||
|
\ "\ta",
|
||||||
|
\ "\t\ta",
|
||||||
|
\ "\t\ta",
|
||||||
|
\ "\t\ta",
|
||||||
|
\ "\t\ta",
|
||||||
|
\ "\ta",
|
||||||
|
\ "a"])
|
||||||
|
set fdm=manual
|
||||||
|
%foldopen!
|
||||||
|
13m7
|
||||||
|
call Check_foldlevels([1, 2, 2, 2, 1, 2, 2, 1, 1, 1, 2, 2, 2, 1, 0])
|
||||||
|
|
||||||
bw!
|
bw!
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func! Test_move_folds_around_indent()
|
func Test_move_folds_around_indent()
|
||||||
new
|
new
|
||||||
let input = PrepIndent("a") + PrepIndent("b") + PrepIndent("c")
|
let input = PrepIndent("a") + PrepIndent("b") + PrepIndent("c")
|
||||||
call setline(1, PrepIndent("a") + PrepIndent("b") + PrepIndent("c"))
|
call setline(1, PrepIndent("a") + PrepIndent("b") + PrepIndent("c"))
|
||||||
@ -357,7 +390,7 @@ func! Test_move_folds_around_indent()
|
|||||||
6m$
|
6m$
|
||||||
" The first fold has been truncated to the 5'th line.
|
" 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.
|
" 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)'))
|
call Check_foldlevels([0, 1, 1, 1, 1, 0, 0, 0, 1, 1])
|
||||||
bw!
|
bw!
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
@ -764,6 +764,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
581,
|
||||||
/**/
|
/**/
|
||||||
580,
|
580,
|
||||||
/**/
|
/**/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user