Issue 4: List folding doesn't work
Using new list functions to determine list fold level. As a regression there is no folds for multilined list item's text. 1. item 1 2. item 2 multilined that is not folded now 3. item 3 Previous method was able to fold item 2. I am not sure if we should fix it or not.
This commit is contained in:
parent
b26591437b
commit
e30aa56722
@ -109,6 +109,7 @@ function! s:get_item(lnum) "{{{
|
|||||||
return item
|
return item
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
||||||
let item.cb = matches[3]
|
let item.cb = matches[3]
|
||||||
|
|
||||||
if matches[1] != ''
|
if matches[1] != ''
|
||||||
@ -570,7 +571,6 @@ function! s:update_state(item) "{{{
|
|||||||
endif
|
endif
|
||||||
endfunction "}}}
|
endfunction "}}}
|
||||||
|
|
||||||
|
|
||||||
"Creates checkbox in a list item.
|
"Creates checkbox in a list item.
|
||||||
"Returns: 1 if successful
|
"Returns: 1 if successful
|
||||||
function! s:create_cb(item) "{{{
|
function! s:create_cb(item) "{{{
|
||||||
@ -896,7 +896,6 @@ function! vimwiki#lst#remove_cb_in_list() "{{{
|
|||||||
call s:update_state(s:get_parent(first_item))
|
call s:update_state(s:get_parent(first_item))
|
||||||
endfunction "}}}
|
endfunction "}}}
|
||||||
|
|
||||||
|
|
||||||
function! vimwiki#lst#change_marker_in_list(new_mrkr) "{{{
|
function! vimwiki#lst#change_marker_in_list(new_mrkr) "{{{
|
||||||
let cur_item = s:get_corresponding_item(line('.'))
|
let cur_item = s:get_corresponding_item(line('.'))
|
||||||
let first_item = s:get_first_item_in_list(cur_item, 0)
|
let first_item = s:get_first_item_in_list(cur_item, 0)
|
||||||
@ -1103,7 +1102,6 @@ function! s:indent_multiline(prev_item, lnum) "{{{
|
|||||||
endif
|
endif
|
||||||
endfunction "}}}
|
endfunction "}}}
|
||||||
|
|
||||||
|
|
||||||
function! vimwiki#lst#kbd_o() "{{{
|
function! vimwiki#lst#kbd_o() "{{{
|
||||||
let fold_end = foldclosedend('.')
|
let fold_end = foldclosedend('.')
|
||||||
let lnum = (fold_end == -1) ? line('.') : fold_end
|
let lnum = (fold_end == -1) ? line('.') : fold_end
|
||||||
@ -1160,7 +1158,7 @@ function! s:create_marker(lnum) "{{{
|
|||||||
endif
|
endif
|
||||||
endfunction "}}}
|
endfunction "}}}
|
||||||
|
|
||||||
function! s:cr_on_empty_list_item(lnum, behavior)
|
function! s:cr_on_empty_list_item(lnum, behavior) "{{{
|
||||||
if a:behavior == 1
|
if a:behavior == 1
|
||||||
"just make a new list item
|
"just make a new list item
|
||||||
normal! gi
|
normal! gi
|
||||||
@ -1212,18 +1210,18 @@ function! s:cr_on_empty_list_item(lnum, behavior)
|
|||||||
endif
|
endif
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction "}}}
|
||||||
|
|
||||||
function! s:cr_on_empty_line(lnum, behavior)
|
function! s:cr_on_empty_line(lnum, behavior) "{{{
|
||||||
if a:behavior == 2 || a:behavior == 3
|
if a:behavior == 2 || a:behavior == 3
|
||||||
normal! gi
|
normal! gi
|
||||||
call s:create_marker(a:lnum+1)
|
call s:create_marker(a:lnum+1)
|
||||||
elseif a:behavior == 1 || a:behavior == 4
|
elseif a:behavior == 1 || a:behavior == 4
|
||||||
normal! gi
x
|
normal! gi
x
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction "}}}
|
||||||
|
|
||||||
function! s:cr_on_list_item(lnum, behavior, cur_col)
|
function! s:cr_on_list_item(lnum, behavior, cur_col) "{{{
|
||||||
if a:behavior == 2 || a:behavior == 4 || (a:cur_col == 0 && getline(a:lnum) =~ '\s$')
|
if a:behavior == 2 || a:behavior == 4 || (a:cur_col == 0 && getline(a:lnum) =~ '\s$')
|
||||||
" || (cur_item.lnum < s:get_last_line_of_item(cur_item))
|
" || (cur_item.lnum < s:get_last_line_of_item(cur_item))
|
||||||
normal! gi
|
normal! gi
|
||||||
@ -1239,7 +1237,7 @@ function! s:cr_on_list_item(lnum, behavior, cur_col)
|
|||||||
call s:change_level(a:lnum+1, a:lnum+1, 'increase', 0)
|
call s:change_level(a:lnum+1, a:lnum+1, 'increase', 0)
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction "}}}
|
||||||
|
|
||||||
function! vimwiki#lst#kbd_cr(normal, just_mrkr) "{{{
|
function! vimwiki#lst#kbd_cr(normal, just_mrkr) "{{{
|
||||||
let lnum = line('.')
|
let lnum = line('.')
|
||||||
@ -1318,7 +1316,7 @@ function! vimwiki#lst#get_list_margin() "{{{
|
|||||||
endif
|
endif
|
||||||
endfunction "}}}
|
endfunction "}}}
|
||||||
|
|
||||||
function! vimwiki#lst#setup_marker_infos()
|
function! vimwiki#lst#setup_marker_infos() "{{{
|
||||||
let s:multiple_bullet_chars = []
|
let s:multiple_bullet_chars = []
|
||||||
for i in keys(g:vimwiki_bullet_types)
|
for i in keys(g:vimwiki_bullet_types)
|
||||||
if g:vimwiki_bullet_types[i] == 1
|
if g:vimwiki_bullet_types[i] == 1
|
||||||
@ -1352,4 +1350,20 @@ function! vimwiki#lst#setup_marker_infos()
|
|||||||
let g:vimwiki_rxListNumber = '$^'
|
let g:vimwiki_rxListNumber = '$^'
|
||||||
endif
|
endif
|
||||||
|
|
||||||
endfunction
|
endfunction "}}}
|
||||||
|
|
||||||
|
fun! vimwiki#lst#fold_level(lnum) "{{{
|
||||||
|
let cur_item = s:get_item(a:lnum)
|
||||||
|
if cur_item.type != 0
|
||||||
|
let parent_item = s:get_parent(cur_item)
|
||||||
|
let child_item = s:get_first_child(cur_item)
|
||||||
|
let next_item = s:get_next_child_item(parent_item, cur_item)
|
||||||
|
if child_item.type != 0
|
||||||
|
return 'a1'
|
||||||
|
elseif next_item.type == 0
|
||||||
|
return 's1'
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
return '='
|
||||||
|
endf "}}}
|
||||||
|
@ -115,7 +115,8 @@ function! s:get_li_level(lnum) "{{{
|
|||||||
if VimwikiGet('syntax') == 'media'
|
if VimwikiGet('syntax') == 'media'
|
||||||
let level = vimwiki#u#count_first_sym(getline(a:lnum))
|
let level = vimwiki#u#count_first_sym(getline(a:lnum))
|
||||||
else
|
else
|
||||||
let level = (indent(a:lnum) / &sw)
|
" let level = (indent(a:lnum) / &sw)
|
||||||
|
let level = indent(a:lnum)
|
||||||
endif
|
endif
|
||||||
return level
|
return level
|
||||||
endfunction "}}}
|
endfunction "}}}
|
||||||
@ -133,53 +134,7 @@ function! s:get_start_list(rx_item, lnum) "{{{
|
|||||||
endfunction "}}}
|
endfunction "}}}
|
||||||
|
|
||||||
function! VimwikiFoldListLevel(lnum) "{{{
|
function! VimwikiFoldListLevel(lnum) "{{{
|
||||||
let line = getline(a:lnum)
|
return vimwiki#lst#fold_level(a:lnum)
|
||||||
|
|
||||||
"" XXX Disabled: Header/section folding...
|
|
||||||
"if line =~ g:vimwiki_rxHeader
|
|
||||||
" return '>'.vimwiki#u#count_first_sym(line)
|
|
||||||
"endif
|
|
||||||
|
|
||||||
"let nnline = getline(a:lnum+1)
|
|
||||||
|
|
||||||
"" Unnecessary?
|
|
||||||
"if nnline =~ g:vimwiki_rxHeader
|
|
||||||
" return '<'.vimwiki#u#count_first_sym(nnline)
|
|
||||||
"endif
|
|
||||||
"" Very slow when called on every single line!
|
|
||||||
"let base_level = s:get_base_level(a:lnum)
|
|
||||||
|
|
||||||
"FIXME does not work correctly
|
|
||||||
let base_level = 0
|
|
||||||
|
|
||||||
if line =~ g:vimwiki_rxListItem
|
|
||||||
let [nnum, nline] = s:find_forward(g:vimwiki_rxListItem, a:lnum)
|
|
||||||
let level = s:get_li_level(a:lnum)
|
|
||||||
let leveln = s:get_li_level(nnum)
|
|
||||||
let adj = s:get_li_level(s:get_start_list(g:vimwiki_rxListItem, a:lnum))
|
|
||||||
|
|
||||||
if leveln > level
|
|
||||||
return ">".(base_level+leveln-adj)
|
|
||||||
" check if multilined list item
|
|
||||||
elseif (nnum-a:lnum) > 1
|
|
||||||
\ && (nline =~ g:vimwiki_rxListItem || nnline !~ '^\s*$')
|
|
||||||
return ">".(base_level+level+1-adj)
|
|
||||||
else
|
|
||||||
return (base_level+level-adj)
|
|
||||||
endif
|
|
||||||
else
|
|
||||||
" process multilined list items
|
|
||||||
let [pnum, pline] = s:find_backward(g:vimwiki_rxListItem, a:lnum)
|
|
||||||
if pline =~ g:vimwiki_rxListItem
|
|
||||||
if indent(a:lnum) >= indent(pnum) && line !~ '^\s*$'
|
|
||||||
let level = s:get_li_level(pnum)
|
|
||||||
let adj = s:get_li_level(s:get_start_list(g:vimwiki_rxListItem, pnum))
|
|
||||||
return (base_level+level+1-adj)
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
return base_level
|
|
||||||
endfunction "}}}
|
endfunction "}}}
|
||||||
" Folding list items }}}
|
" Folding list items }}}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user