From 12cdee72452b3013a2d01ef50cf980e1fa740242 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 4 Jan 2024 05:36:38 +0800 Subject: 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 https://github.com/vim/vim/commit/0689b870595c687a23e102913ce5037f65d03748 Co-authored-by: Shota Nozaki --- test/old/testdir/test_fold.vim | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'test') diff --git a/test/old/testdir/test_fold.vim b/test/old/testdir/test_fold.vim index e529a94174..eae6952e72 100644 --- a/test/old/testdir/test_fold.vim +++ b/test/old/testdir/test_fold.vim @@ -1578,4 +1578,17 @@ func Test_foldexpr_return_empty_string() bwipe! 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 + " vim: shiftwidth=2 sts=2 expandtab -- cgit