Skip to content

Commit 1159b16

Browse files
committed
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.
1 parent b113c3a commit 1159b16

File tree

3 files changed

+37
-11
lines changed

3 files changed

+37
-11
lines changed

src/fold.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,16 +1576,23 @@ foldMarkAdjustRecurse(
15761576
{
15771577
/* 5. fold is below line1 and contains line2; need to
15781578
* correct nested folds too */
1579-
foldMarkAdjustRecurse(&fp->fd_nested, line1 - fp->fd_top,
1580-
line2 - fp->fd_top, amount,
1581-
amount_after + (fp->fd_top - top));
15821579
if (amount == MAXLNUM)
15831580
{
1581+
foldMarkAdjustRecurse(&fp->fd_nested,
1582+
line1 - fp->fd_top,
1583+
line2 - fp->fd_top,
1584+
amount,
1585+
amount_after + (fp->fd_top - top));
15841586
fp->fd_len -= line2 - fp->fd_top + 1;
15851587
fp->fd_top = line1;
15861588
}
15871589
else
15881590
{
1591+
foldMarkAdjustRecurse(&fp->fd_nested,
1592+
line1 - fp->fd_top,
1593+
line2 - fp->fd_top,
1594+
amount,
1595+
amount_after - amount);
15891596
fp->fd_len += amount_after - amount;
15901597
fp->fd_top += amount;
15911598
}

src/testdir/test_fold.vim

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
" Test for folding
22

3-
function! Test_address_fold()
3+
func! Test_address_fold()
44
new
55
call setline(1, ['int FuncName() {/*{{{*/', 1, 2, 3, 4, 5, '}/*}}}*/',
66
\ 'after fold 1', 'after fold 2', 'after fold 3'])
@@ -62,19 +62,19 @@ function! Test_address_fold()
6262
call assert_equal(['4', '5', '}/*}}}*/'], getreg(0,1,1))
6363

6464
quit!
65-
endfunction
65+
endfunc
6666

67-
function! Test_indent_fold()
67+
func! Test_indent_fold()
6868
new
6969
call setline(1, ['', 'a', ' b', ' c'])
7070
setl fen fdm=indent
7171
2
7272
norm! >>
7373
let a=map(range(1,4), 'foldclosed(v:val)')
7474
call assert_equal([-1,-1,-1,-1], a)
75-
endfu
75+
endfunc
7676

77-
function! Test_indent_fold()
77+
func! Test_indent_fold()
7878
new
7979
call setline(1, ['', 'a', ' b', ' c'])
8080
setl fen fdm=indent
@@ -83,9 +83,9 @@ function! Test_indent_fold()
8383
let a=map(range(1,4), 'foldclosed(v:val)')
8484
call assert_equal([-1,-1,-1,-1], a)
8585
bw!
86-
endfu
86+
endfunc
8787

88-
function! Test_indent_fold2()
88+
func! Test_indent_fold2()
8989
new
9090
call setline(1, ['', '{{{', '}}}', '{{{', '}}}'])
9191
setl fen fdm=marker
@@ -94,4 +94,21 @@ function! Test_indent_fold2()
9494
let a=map(range(1,5), 'foldclosed(v:val)')
9595
call assert_equal([-1,-1,-1,4,4], a)
9696
bw!
97-
endfu
97+
endfunc
98+
99+
func Test_manual_fold_with_filter()
100+
if !executable('cat')
101+
return
102+
endif
103+
new
104+
call setline(1, range(1, 20))
105+
4,$fold
106+
%foldopen
107+
10,$fold
108+
%foldopen
109+
" This filter command should not have an effect
110+
1,8! cat
111+
call feedkeys('5ggzdzMGdd', 'xt')
112+
call assert_equal(['1', '2', '3', '4', '5', '6', '7', '8', '9'], getline(1, '$'))
113+
bwipe!
114+
endfunc

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+
388,
767769
/**/
768770
387,
769771
/**/

0 commit comments

Comments
 (0)