mirror of
https://github.com/neovim/neovim.git
synced 2025-09-29 22:48:34 +00:00
vim-patch:9.1.0002: a closing fold expr, may start a new fold (#26876)
Problem: a closing fold expression may unexpectedly start a new fold
when it should end a fold
(reported by Shota Nozaki)
Solution: if a fold hasn't started yet, do not immediately
start a new fold with level 1
(Shota Nozaki)
fixes: vim/vim#12768
closes: vim/vim#13748
0689b87059
Co-authored-by: Shota Nozaki <emonkak@gmail.com>
This commit is contained in:
@@ -2980,7 +2980,9 @@ static void foldlevelExpr(fline_T *flp)
|
|||||||
|
|
||||||
// "<1", "<2", .. : end a fold with a certain level
|
// "<1", "<2", .. : end a fold with a certain level
|
||||||
case '<':
|
case '<':
|
||||||
flp->lvl_next = n - 1;
|
// To prevent an unexpected start of a new fold, the next
|
||||||
|
// level must not exceed the level of the current fold.
|
||||||
|
flp->lvl_next = MIN(flp->lvl, n - 1);
|
||||||
flp->end = n;
|
flp->end = n;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@@ -1578,4 +1578,17 @@ func Test_foldexpr_return_empty_string()
|
|||||||
|
|
||||||
bwipe!
|
bwipe!
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
" Make sure that when ending a fold that hasn't been started, it does not
|
||||||
|
" start a new fold.
|
||||||
|
func Test_foldexpr_end_fold()
|
||||||
|
new
|
||||||
|
setlocal foldmethod=expr
|
||||||
|
let &l:foldexpr = 'v:lnum == 2 ? "<2" : "="'
|
||||||
|
call setline(1, range(1, 3))
|
||||||
|
redraw
|
||||||
|
call assert_equal([0, 0, 0], range(1, 3)->map('foldlevel(v:val)'))
|
||||||
|
|
||||||
|
bwipe!
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user