vimwiki

Personal wiki for vim
git clone https://github.com/vimwiki/vimwiki.git
Log | Files | Refs | README | LICENSE

commit 90b23b466fd5a368099732ee48b0896ce4bfa57f
parent 68664e5d728c5f265aecd159f81ea60d3c2ba21d
Author: Tinmarino <tinmarino@gmail.com>
Date:   Tue, 31 Oct 2023 12:40:39 -0300

Fix: Folding code blocks using markdown syntax folds the entire rest of the file (#1323)

Diffstat:
Mftplugin/vimwiki.vim | 10++++++++--
Atest/issue_1323_fold_code_block.vader | 45+++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 53 insertions(+), 2 deletions(-)

diff --git a/ftplugin/vimwiki.vim b/ftplugin/vimwiki.vim @@ -196,9 +196,15 @@ function! VimwikiFoldLevel(lnum) abort endif " Code block folding... - if line =~# vimwiki#vars#get_syntaxlocal('rxPreStart') + " -- previously it would always increment when it saw a ```, so we never left the code block. (See #1323) + let prevline = getline(v:lnum - 1) + let nextline = getline(v:lnum + 1) + + " -- Start: assumes empty line before + if line =~# vimwiki#vars#get_syntaxlocal('rxPreStart') && prevline =~ '^\s*$' return 'a1' - elseif line =~# vimwiki#vars#get_syntaxlocal('rxPreEnd') + " -- End: assumes empty line after + elseif line =~# vimwiki#vars#get_syntaxlocal('rxPreEnd') && nextline =~ '^\s*$' return 's1' endif diff --git a/test/issue_1323_fold_code_block.vader b/test/issue_1323_fold_code_block.vader @@ -0,0 +1,45 @@ +# Non regression tests for issue 1323 +# -- Folding code blocks using markdown syntax folds the entire rest of the file #1323 +# +# Syntax: https://github.com/junegunn/vader.vim#syntax-of-vader-file +# Run: bash run_tests.sh -v -t vader -n vim_7.3.429 -f issue_example.vader + +Given vimwiki (Input file): + # Header + + ```sql + SELECT blah FROM bleh; + ``` + + More text in session one + + # Header two + + More text in session two + + +Execute (Cheat vars): + call SetSyntax('markdown') + let old_foldexpr = &foldexpr + let old_foldmethod = &foldmethod + set foldexpr=VimwikiFoldLevel(v:lnum) + set foldmethod=expr + + +Execute (Call function to verify): + AssertEqual 'line 1 => 1', 'line 1 => ' . foldlevel(1) + AssertEqual 'line 2 => 1', 'line 2 => ' . foldlevel(2) + AssertEqual 'line 3 => 2', 'line 3 => ' . foldlevel(3) + AssertEqual 'line 4 => 2', 'line 4 => ' . foldlevel(4) + AssertEqual 'line 5 => 2', 'line 5 => ' . foldlevel(5) + AssertEqual 'line 6 => 1', 'line 6 => ' . foldlevel(6) + AssertEqual 'line 7 => 1', 'line 7 => ' . foldlevel(7) + AssertEqual 'line 8 => 1', 'line 8 => ' . foldlevel(8) +# AssertEqual 'line 9 => 0', 'line 9 => ' . foldlevel(9) +# AssertEqual 'line 10 => 1', 'line 10 => ' . foldlevel(10) +# AssertEqual 'line 11 => 1', 'line 11 => ' . foldlevel(11) + + +Execute (Restore vars): + let &foldexpr = old_foldexpr + let &foldmethod = old_foldmethod