Don't insert marker character with o or O within a code block.

Previously if a code block was part of a list and o or O was used a new
list marker would be inserted. Also moved the is_codeblock check
function to utils file for use elsewhere.
This commit is contained in:
Rane Brown 2019-10-16 22:27:26 -06:00
parent 1f85a3c855
commit a42cd58636
2 changed files with 23 additions and 18 deletions

View File

@ -1471,10 +1471,12 @@ function! vimwiki#lst#kbd_o()
"inserting and deleting the x is necessary
"because otherwise the indent is lost
exe 'normal!' "ox\<C-H>"
if parent.type != 0
call s:clone_marker_from_to(parent.lnum, cur_item.lnum+1)
else
call s:indent_multiline(cur_item, cur_item.lnum+1)
if !vimwiki#u#is_codeblock(lnum)
if parent.type != 0
call s:clone_marker_from_to(parent.lnum, cur_item.lnum+1)
else
call s:indent_multiline(cur_item, cur_item.lnum+1)
endif
endif
startinsert!
endfunction
@ -1483,10 +1485,12 @@ endfunction
function! vimwiki#lst#kbd_O()
exe 'normal!' "Ox\<C-H>"
let cur_ln = line('.')
if getline(cur_ln+1) !~# '^\s*$'
call s:clone_marker_from_to(cur_ln+1, cur_ln)
else
call s:clone_marker_from_to(cur_ln-1, cur_ln)
if !vimwiki#u#is_codeblock(cur_ln)
if getline(cur_ln+1) !~# '^\s*$'
call s:clone_marker_from_to(cur_ln+1, cur_ln)
else
call s:clone_marker_from_to(cur_ln-1, cur_ln)
endif
endif
startinsert!
endfunction
@ -1548,15 +1552,6 @@ 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)
@ -1565,7 +1560,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 || s:is_codeblock(a:lnum)
if lst.type == 0 || vimwiki#u#is_codeblock(a:lnum)
" don't insert new bullet if not part of a list
return
else

View File

@ -93,3 +93,13 @@ function vimwiki#u#map_key(mode, key, plug, ...)
endif
endif
endfunction
function! vimwiki#u#is_codeblock(lnum)
let syn_g = synIDattr(synID(a:lnum,1,1),'name')
if syn_g =~# 'textSnip.*' || syn_g =~# 'VimwikiPre.*' || syn_g =~# '.*Comment'
return 1
else
return 0
endif
endfunction