vimwiki

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

commit dcd68a6781a181f0bf56639bf3a0f3d2e1f4e017
parent 0c561e53414707544d3ffcb38301eb2b30c49493
Author: Lionel Flandrin <lionel@svkt.org>
Date:   Wed, 31 Jul 2019 17:47:06 +0100

Fix off-by-one error in get_next_line and get_prev_line

The functions stopped at the end/start block marker (respectively)
instead of returning the following line. This caused issues when the
function was subsequently called in markdown mode since the start and
end block markers are the same.

This fixes #407

Diffstat:
Mautoload/vimwiki/lst.vim | 14++++++++------
Mdoc/vimwiki.txt | 2++
Atest/list_update.vader | 191+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 201 insertions(+), 6 deletions(-)

diff --git a/autoload/vimwiki/lst.vim b/autoload/vimwiki/lst.vim @@ -419,11 +419,13 @@ function! s:get_next_line(lnum, ...) while cur_ln <= line('$') && getline(cur_ln) !~# vimwiki#vars#get_syntaxlocal('rxPreEnd') let cur_ln += 1 endwhile - let next_line = cur_ln + let next_line = cur_ln + 1 else - let next_line = nextnonblank(a:lnum+1) + let next_line = a:lnum + 1 endif + let next_line = nextnonblank(next_line) + if a:0 > 0 && getline(next_line) =~# vimwiki#vars#get_syntaxlocal('rxHeader') let next_line = s:get_next_line(next_line, 1) endif @@ -440,19 +442,19 @@ endfunction "Returns: lnum-1 in most cases, but skips blank lines and preformatted text "0 in case of nonvalid line and a header, because a header ends every list function! s:get_prev_line(lnum) - let prev_line = prevnonblank(a:lnum-1) + let cur_ln = a:lnum - 1 - if getline(prev_line) =~# vimwiki#vars#get_syntaxlocal('rxPreEnd') - let cur_ln = a:lnum - 1 + if getline(cur_ln) =~# vimwiki#vars#get_syntaxlocal('rxPreEnd') while 1 if cur_ln == 0 || getline(cur_ln) =~# vimwiki#vars#get_syntaxlocal('rxPreStart') break endif let cur_ln -= 1 endwhile - let prev_line = cur_ln endif + let prev_line = prevnonblank(cur_ln) + if prev_line < 0 || prev_line > line('$') || \ getline(prev_line) =~# vimwiki#vars#get_syntaxlocal('rxHeader') return 0 diff --git a/doc/vimwiki.txt b/doc/vimwiki.txt @@ -3471,6 +3471,8 @@ https://github.com/vimwiki-backup/vimwiki/issues. 2.5 (in progress)~ New:~ + * PR #735: Make list-toggling work properly even when code blocks are + embedded within the list in Markdown mode. * PR #711: Allow forcing VimwikiAll2HTML with ! * PR #702: Make remapping documentation more accessible to newer vim users * PR #673: Add :VimwikiGoto key mapping. diff --git a/test/list_update.vader b/test/list_update.vader @@ -0,0 +1,191 @@ +Include: vader_includes/vader_setup.vader + +Given vimwiki (Sample nested list, vimwiki syntax): + * [ ] Top Level + * [ ] Child 1 + * [ ] Child 2 + + * [ ] Post space + + {{{code + * [ ] print "hello, world" + }}} + + {{{morecode + print "hello again" + }}} + + * [ ] Post code + * [ ] Sub-child + + * [ ] Sub-sub-child + +Execute (Set syntax to default): + call SetSyntax('default') + +Do (Toggle top-level): + \<C-Space> + +Expect (All tree toggled): + * [X] Top Level + * [X] Child 1 + * [X] Child 2 + + * [X] Post space + + {{{code + * [ ] print "hello, world" + }}} + + {{{morecode + print "hello again" + }}} + + * [X] Post code + * [X] Sub-child + + * [X] Sub-sub-child + +Do (Toggle child): + j + \<C-Space> + +Expect (Child toggled, top updated): + * [.] Top Level + * [X] Child 1 + * [ ] Child 2 + + * [ ] Post space + + {{{code + * [ ] print "hello, world" + }}} + + {{{morecode + print "hello again" + }}} + + * [ ] Post code + * [ ] Sub-child + + * [ ] Sub-sub-child + +Do (Toggle sub-child): + G + \<C-Space> + +Expect (Sub-child toggled, parents updated): + * [.] Top Level + * [ ] Child 1 + * [ ] Child 2 + + * [ ] Post space + + {{{code + * [ ] print "hello, world" + }}} + + {{{morecode + print "hello again" + }}} + + * [o] Post code + * [ ] Sub-child + + * [X] Sub-sub-child + +Given markdown (Sample nested list, markdown syntax): + * [ ] Top Level + * [ ] Child 1 + * [ ] Child 2 + + * [ ] Post space + + ```code + * [ ] print "hello, world" + ``` + + ```morecode + print "hello again" + ``` + + * [ ] Post code + * [ ] Sub-child + + * [ ] Sub-sub-child + +Execute (Set syntax to markdown): + call SetSyntax('markdown') + +Do (Toggle top-level): + \<C-Space> + +Expect (All tree toggled): + * [X] Top Level + * [X] Child 1 + * [X] Child 2 + + * [X] Post space + + ```code + * [ ] print "hello, world" + ``` + + ```morecode + print "hello again" + ``` + + * [X] Post code + * [X] Sub-child + + * [X] Sub-sub-child + +Do (Toggle child): + j + \<C-Space> + +Expect (Child toggled, top updated): + * [.] Top Level + * [X] Child 1 + * [ ] Child 2 + + * [ ] Post space + + ```code + * [ ] print "hello, world" + ``` + + ```morecode + print "hello again" + ``` + + * [ ] Post code + * [ ] Sub-child + + * [ ] Sub-sub-child + +Do (Toggle sub-child): + G + \<C-Space> + +Expect (Sub-child toggled, parents updated): + * [.] Top Level + * [ ] Child 1 + * [ ] Child 2 + + * [ ] Post space + + ```code + * [ ] print "hello, world" + ``` + + ```morecode + print "hello again" + ``` + + * [o] Post code + * [ ] Sub-child + + * [X] Sub-sub-child + +Include: vader_includes/vader_teardown.vader