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
This commit is contained in:
Lionel Flandrin 2019-07-31 17:47:06 +01:00
parent 0c561e5341
commit dcd68a6781
3 changed files with 201 additions and 6 deletions

View File

@ -419,11 +419,13 @@ function! s:get_next_line(lnum, ...)
while cur_ln <= line('$') && getline(cur_ln) !~# vimwiki#vars#get_syntaxlocal('rxPreEnd') while cur_ln <= line('$') && getline(cur_ln) !~# vimwiki#vars#get_syntaxlocal('rxPreEnd')
let cur_ln += 1 let cur_ln += 1
endwhile endwhile
let next_line = cur_ln let next_line = cur_ln + 1
else else
let next_line = nextnonblank(a:lnum+1) let next_line = a:lnum + 1
endif endif
let next_line = nextnonblank(next_line)
if a:0 > 0 && getline(next_line) =~# vimwiki#vars#get_syntaxlocal('rxHeader') if a:0 > 0 && getline(next_line) =~# vimwiki#vars#get_syntaxlocal('rxHeader')
let next_line = s:get_next_line(next_line, 1) let next_line = s:get_next_line(next_line, 1)
endif endif
@ -440,19 +442,19 @@ endfunction
"Returns: lnum-1 in most cases, but skips blank lines and preformatted text "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 "0 in case of nonvalid line and a header, because a header ends every list
function! s:get_prev_line(lnum) 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') if getline(cur_ln) =~# vimwiki#vars#get_syntaxlocal('rxPreEnd')
let cur_ln = a:lnum - 1
while 1 while 1
if cur_ln == 0 || getline(cur_ln) =~# vimwiki#vars#get_syntaxlocal('rxPreStart') if cur_ln == 0 || getline(cur_ln) =~# vimwiki#vars#get_syntaxlocal('rxPreStart')
break break
endif endif
let cur_ln -= 1 let cur_ln -= 1
endwhile endwhile
let prev_line = cur_ln
endif endif
let prev_line = prevnonblank(cur_ln)
if prev_line < 0 || prev_line > line('$') || if prev_line < 0 || prev_line > line('$') ||
\ getline(prev_line) =~# vimwiki#vars#get_syntaxlocal('rxHeader') \ getline(prev_line) =~# vimwiki#vars#get_syntaxlocal('rxHeader')
return 0 return 0

View File

@ -3471,6 +3471,8 @@ https://github.com/vimwiki-backup/vimwiki/issues.
2.5 (in progress)~ 2.5 (in progress)~
New:~ 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 #711: Allow forcing VimwikiAll2HTML with !
* PR #702: Make remapping documentation more accessible to newer vim users * PR #702: Make remapping documentation more accessible to newer vim users
* PR #673: Add :VimwikiGoto key mapping. * PR #673: Add :VimwikiGoto key mapping.

191
test/list_update.vader Normal file
View File

@ -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