Fix 'VimwikiReturn 3 5' behavior within code blocks.

Previously a new list marker would get added when working within a code
block that was part of a list. This change excludes code blocks from
list marker creation.
This commit is contained in:
Rane Brown 2019-08-23 14:42:07 -06:00
parent e814c6ad93
commit a17a9826bd
2 changed files with 77 additions and 1 deletions

View File

@ -1546,6 +1546,14 @@ function! s:cr_on_empty_list_item(lnum, behavior)
endif
endfunction
function! s:is_codeblock(lnum)
let syn_g = synIDattr(synID(a:lnum,1,1),'name')
if syn_g =~# 'textSnip*' || syn_g =~# 'VimwikiPre*'
return 1
else
return 0
endif
endfunction
function! s:cr_on_empty_line(lnum, behavior)
let lst = s:get_corresponding_item(a:lnum)
@ -1555,7 +1563,7 @@ function! s:cr_on_empty_line(lnum, behavior)
exe 'normal!' "gi\<CR>x\<C-H>\<ESC>"
if a:behavior == 2 || a:behavior == 3
if lst.type == 0
if lst.type == 0 || s:is_codeblock(a:lnum)
" don't insert new bullet if not part of a list
return
else

View File

@ -41,6 +41,74 @@ Expect (Extended list):
- New sub item
- Item 5
Given vimwiki (List with code block):
- Item 1
- Item 2
- Item 3 that is split across multiple lines
This is the second line.
This is the third line.
- Item 4
- Sub item 1
- Sub item split across multiple lines
This is the second line.
This is the third line.
```
int x = 2 + 2;
return 0;
```
- Item 5
```c
int x = 2 + 2;
return 0;
```
- Item 6 that is split
Across multiple lines.
Done.
Do (CR and CR in code block):
4j
A\<CR>Another item\<Esc>
6j
A\<CR>int y = 1;\<Esc>
1j
A\<CR>x = x + y;\<Esc>
4j
A\<CR>int y = 2;\<Esc>
3j
A\<CR>A new bullet doesn't get added here, oh well.\<Esc>
3j
A\<CR>Done and Done\<Esc>
Expect (No list continuation in code block):
- Item 1
- Item 2
- Item 3 that is split across multiple lines
This is the second line.
This is the third line.
- Another item
- Item 4
- Sub item 1
- Sub item split across multiple lines
This is the second line.
This is the third line.
```
int y = 1;
int x = 2 + 2;
x = x + y;
return 0;
```
- Item 5
```c
int y = 2;
int x = 2 + 2;
return 0;
```
A new bullet doesn't get added here, oh well.
- Item 6 that is split
Across multiple lines.
Done.
- Done and Done
Given vimwiki (List from help file):
1. item
---