From dcd68a6781a181f0bf56639bf3a0f3d2e1f4e017 Mon Sep 17 00:00:00 2001 From: Lionel Flandrin Date: Wed, 31 Jul 2019 17:47:06 +0100 Subject: [PATCH] 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 --- autoload/vimwiki/lst.vim | 14 +-- doc/vimwiki.txt | 2 + test/list_update.vader | 191 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 201 insertions(+), 6 deletions(-) create mode 100644 test/list_update.vader diff --git a/autoload/vimwiki/lst.vim b/autoload/vimwiki/lst.vim index 0e10151..118a7a4 100644 --- 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 index 4ccc4cf..72bd6b3 100644 --- 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 new file mode 100644 index 0000000..9c5b10e --- /dev/null +++ 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): + \ + +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 + \ + +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 + \ + +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): + \ + +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 + \ + +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 + \ + +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