Don't check a [-] list item when its parent is [X] checked

This commit is contained in:
EinfachToll 2018-11-30 17:02:38 +01:00
parent a653e2d8c2
commit fa36bf3838

View File

@ -299,6 +299,13 @@ function! s:regexp_of_marker(item)
endfunction endfunction
" Returns: Whether or not the checkbox of a list item is [X] or [-]
function! s:is_closed(item)
let state = a:item.cb
return state ==# vimwiki#vars#get_syntaxlocal('listsyms_list')[-1]
\ || state ==# vimwiki#vars#get_global('listsym_rejected')
endfunction
" --------------------------------------------------------- " ---------------------------------------------------------
" functions for navigating between items " functions for navigating between items
" --------------------------------------------------------- " ---------------------------------------------------------
@ -756,10 +763,15 @@ function! s:set_state(item, new_rate)
endfunction endfunction
"Set state of the list item to [ ] or [o] or whatever " Sets the state of the list item to [ ] or [o] or whatever. Updates the states of its child items.
"Updates the states of its child items " If the new state should be [X] or [-], the state of the current list item is changed to this
function! s:set_state_plus_children(item, new_rate) " state, but if a child item already has [X] or [-] it is left alone.
call s:set_state(a:item, a:new_rate) function! s:set_state_plus_children(item, new_rate, ...)
let retain_checked_and_rejected = a:0 > 0 && a:1 > 0
if !(retain_checked_and_rejected && s:is_closed(a:item))
call s:set_state(a:item, a:new_rate)
endif
let child_item = s:get_first_child(a:item) let child_item = s:get_first_child(a:item)
while 1 while 1
@ -767,7 +779,7 @@ function! s:set_state_plus_children(item, new_rate)
break break
endif endif
if child_item.cb != '' if child_item.cb != ''
call s:set_state_plus_children(child_item, a:new_rate) call s:set_state_plus_children(child_item, a:new_rate, 1)
endif endif
let child_item = s:get_next_child_item(a:item, child_item) let child_item = s:get_next_child_item(a:item, child_item)
endwhile endwhile
@ -866,8 +878,7 @@ function! s:remove_cb(item)
endfunction endfunction
"Change state of checkbox " Change state of the checkboxes in the lines of the given range
"in the lines of the given range
function! s:change_cb(from_line, to_line, new_rate) function! s:change_cb(from_line, to_line, new_rate)
let from_item = s:get_corresponding_item(a:from_line) let from_item = s:get_corresponding_item(a:from_line)
if from_item.type == 0 if from_item.type == 0
@ -894,7 +905,7 @@ function! s:change_cb(from_line, to_line, new_rate)
endfunction endfunction
" Toggles checkbox between two states in the lines of the given range, creates chceckboxes (with " Toggles checkbox between two states in the lines of the given range, creates checkboxes (with
" a:start_rate as state) if there aren't any. " a:start_rate as state) if there aren't any.
function! s:toggle_create_cb(from_line, to_line, state1, state2, start_rate) function! s:toggle_create_cb(from_line, to_line, state1, state2, start_rate)
let from_item = s:get_corresponding_item(a:from_line) let from_item = s:get_corresponding_item(a:from_line)