mirror of
https://github.com/vim/vim.git
synced 2025-09-23 03:43:49 -04:00
patch 8.0.0388: filtering lines changes folds
Problem: filtering lines through "cat", without changing the line count, changes manual folds. Solution: Change how marks and folds are adjusted. (Matthew Malcomson, from neovim #6194.
This commit is contained in:
13
src/fold.c
13
src/fold.c
@@ -1576,16 +1576,23 @@ foldMarkAdjustRecurse(
|
|||||||
{
|
{
|
||||||
/* 5. fold is below line1 and contains line2; need to
|
/* 5. fold is below line1 and contains line2; need to
|
||||||
* correct nested folds too */
|
* correct nested folds too */
|
||||||
foldMarkAdjustRecurse(&fp->fd_nested, line1 - fp->fd_top,
|
|
||||||
line2 - fp->fd_top, amount,
|
|
||||||
amount_after + (fp->fd_top - top));
|
|
||||||
if (amount == MAXLNUM)
|
if (amount == MAXLNUM)
|
||||||
{
|
{
|
||||||
|
foldMarkAdjustRecurse(&fp->fd_nested,
|
||||||
|
line1 - fp->fd_top,
|
||||||
|
line2 - fp->fd_top,
|
||||||
|
amount,
|
||||||
|
amount_after + (fp->fd_top - top));
|
||||||
fp->fd_len -= line2 - fp->fd_top + 1;
|
fp->fd_len -= line2 - fp->fd_top + 1;
|
||||||
fp->fd_top = line1;
|
fp->fd_top = line1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
foldMarkAdjustRecurse(&fp->fd_nested,
|
||||||
|
line1 - fp->fd_top,
|
||||||
|
line2 - fp->fd_top,
|
||||||
|
amount,
|
||||||
|
amount_after - amount);
|
||||||
fp->fd_len += amount_after - amount;
|
fp->fd_len += amount_after - amount;
|
||||||
fp->fd_top += amount;
|
fp->fd_top += amount;
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
" Test for folding
|
" Test for folding
|
||||||
|
|
||||||
function! 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'])
|
||||||
@@ -62,9 +62,9 @@ function! Test_address_fold()
|
|||||||
call assert_equal(['4', '5', '}/*}}}*/'], getreg(0,1,1))
|
call assert_equal(['4', '5', '}/*}}}*/'], getreg(0,1,1))
|
||||||
|
|
||||||
quit!
|
quit!
|
||||||
endfunction
|
endfunc
|
||||||
|
|
||||||
function! Test_indent_fold()
|
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
|
||||||
@@ -72,9 +72,9 @@ function! Test_indent_fold()
|
|||||||
norm! >>
|
norm! >>
|
||||||
let a=map(range(1,4), 'foldclosed(v:val)')
|
let a=map(range(1,4), 'foldclosed(v:val)')
|
||||||
call assert_equal([-1,-1,-1,-1], a)
|
call assert_equal([-1,-1,-1,-1], a)
|
||||||
endfu
|
endfunc
|
||||||
|
|
||||||
function! Test_indent_fold()
|
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
|
||||||
@@ -83,9 +83,9 @@ function! Test_indent_fold()
|
|||||||
let a=map(range(1,4), 'foldclosed(v:val)')
|
let a=map(range(1,4), 'foldclosed(v:val)')
|
||||||
call assert_equal([-1,-1,-1,-1], a)
|
call assert_equal([-1,-1,-1,-1], a)
|
||||||
bw!
|
bw!
|
||||||
endfu
|
endfunc
|
||||||
|
|
||||||
function! Test_indent_fold2()
|
func! Test_indent_fold2()
|
||||||
new
|
new
|
||||||
call setline(1, ['', '{{{', '}}}', '{{{', '}}}'])
|
call setline(1, ['', '{{{', '}}}', '{{{', '}}}'])
|
||||||
setl fen fdm=marker
|
setl fen fdm=marker
|
||||||
@@ -94,4 +94,21 @@ function! Test_indent_fold2()
|
|||||||
let a=map(range(1,5), 'foldclosed(v:val)')
|
let a=map(range(1,5), 'foldclosed(v:val)')
|
||||||
call assert_equal([-1,-1,-1,4,4], a)
|
call assert_equal([-1,-1,-1,4,4], a)
|
||||||
bw!
|
bw!
|
||||||
endfu
|
endfunc
|
||||||
|
|
||||||
|
func Test_manual_fold_with_filter()
|
||||||
|
if !executable('cat')
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
new
|
||||||
|
call setline(1, range(1, 20))
|
||||||
|
4,$fold
|
||||||
|
%foldopen
|
||||||
|
10,$fold
|
||||||
|
%foldopen
|
||||||
|
" This filter command should not have an effect
|
||||||
|
1,8! cat
|
||||||
|
call feedkeys('5ggzdzMGdd', 'xt')
|
||||||
|
call assert_equal(['1', '2', '3', '4', '5', '6', '7', '8', '9'], getline(1, '$'))
|
||||||
|
bwipe!
|
||||||
|
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 */
|
||||||
|
/**/
|
||||||
|
388,
|
||||||
/**/
|
/**/
|
||||||
387,
|
387,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user