Clean up code by reusing code
This commit is contained in:
parent
20afe48edd
commit
7fe98bd20c
@ -808,10 +808,9 @@ function! s:remove_cb(item) "{{{
|
|||||||
return item
|
return item
|
||||||
endfunction "}}}
|
endfunction "}}}
|
||||||
|
|
||||||
|
"Change state of checkbox
|
||||||
"Increment checkbox between [ ] and [X]
|
|
||||||
"in the lines of the given range
|
"in the lines of the given range
|
||||||
function! vimwiki#lst#decrement_cb(from_line, to_line) "{{{
|
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
|
||||||
return
|
return
|
||||||
@ -819,31 +818,40 @@ function! vimwiki#lst#decrement_cb(from_line, to_line) "{{{
|
|||||||
|
|
||||||
let parent_items_of_lines = []
|
let parent_items_of_lines = []
|
||||||
|
|
||||||
if from_item.cb != ''
|
for cur_ln in range(from_item.lnum, a:to_line)
|
||||||
|
let cur_item = s:get_item(cur_ln)
|
||||||
"if from_line has CB, toggle it and set all siblings to the same new state
|
if cur_item.type != 0 && cur_item.cb != ''
|
||||||
let rate_first_line = s:get_rate(from_item)
|
call s:set_state_plus_children(cur_item, a:new_rate)
|
||||||
let n=len(g:vimwiki_listsyms_list)
|
let cur_parent_item = s:get_parent(cur_item)
|
||||||
let new_rate = max([rate_first_line - 100/(n-1)-1, 0])
|
if index(parent_items_of_lines, cur_parent_item) == -1
|
||||||
|
call insert(parent_items_of_lines, cur_parent_item)
|
||||||
for cur_ln in range(from_item.lnum, a:to_line)
|
|
||||||
let cur_item = s:get_item(cur_ln)
|
|
||||||
if cur_item.type != 0 && cur_item.cb != ''
|
|
||||||
call s:set_state_plus_children(cur_item, new_rate)
|
|
||||||
let cur_parent_item = s:get_parent(cur_item)
|
|
||||||
if index(parent_items_of_lines, cur_parent_item) == -1
|
|
||||||
call insert(parent_items_of_lines, cur_parent_item)
|
|
||||||
endif
|
|
||||||
endif
|
endif
|
||||||
endfor
|
endif
|
||||||
|
endfor
|
||||||
endif
|
|
||||||
|
|
||||||
for parent_item in parent_items_of_lines
|
for parent_item in parent_items_of_lines
|
||||||
call s:update_state(parent_item)
|
call s:update_state(parent_item)
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
endfunction "}}}
|
endfunction "}}}
|
||||||
|
|
||||||
|
"Decrement checkbox between [ ] and [X]
|
||||||
|
"in the lines of the given range
|
||||||
|
function! vimwiki#lst#decrement_cb(from_line, to_line) "{{{
|
||||||
|
let from_item = s:get_corresponding_item(a:from_line)
|
||||||
|
if from_item.type == 0
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
|
||||||
|
"if from_line has CB, decrement it and set all siblings to the same new state
|
||||||
|
let rate_first_line = s:get_rate(from_item)
|
||||||
|
let n=len(g:vimwiki_listsyms_list)
|
||||||
|
let new_rate = max([rate_first_line - 100/(n-1)-1, 0])
|
||||||
|
|
||||||
|
call s:change_cb(a:from_line, a:to_line, new_rate)
|
||||||
|
|
||||||
|
endfunction "}}}
|
||||||
|
|
||||||
"Increment checkbox between [ ] and [X]
|
"Increment checkbox between [ ] and [X]
|
||||||
"in the lines of the given range
|
"in the lines of the given range
|
||||||
function! vimwiki#lst#increment_cb(from_line, to_line) "{{{
|
function! vimwiki#lst#increment_cb(from_line, to_line) "{{{
|
||||||
@ -852,31 +860,12 @@ function! vimwiki#lst#increment_cb(from_line, to_line) "{{{
|
|||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let parent_items_of_lines = []
|
"if from_line has CB, increment it and set all siblings to the same new state
|
||||||
|
let rate_first_line = s:get_rate(from_item)
|
||||||
|
let n=len(g:vimwiki_listsyms_list)
|
||||||
|
let new_rate = min([rate_first_line + 100/(n-1)+1, 100])
|
||||||
|
|
||||||
if from_item.cb != ''
|
call s:change_cb(a:from_line, a:to_line, new_rate)
|
||||||
|
|
||||||
"if from_line has CB, toggle it and set all siblings to the same new state
|
|
||||||
let rate_first_line = s:get_rate(from_item)
|
|
||||||
let n=len(g:vimwiki_listsyms_list)
|
|
||||||
let new_rate = min([rate_first_line + 100/(n-1)+1, 100])
|
|
||||||
|
|
||||||
for cur_ln in range(from_item.lnum, a:to_line)
|
|
||||||
let cur_item = s:get_item(cur_ln)
|
|
||||||
if cur_item.type != 0 && cur_item.cb != ''
|
|
||||||
call s:set_state_plus_children(cur_item, new_rate)
|
|
||||||
let cur_parent_item = s:get_parent(cur_item)
|
|
||||||
if index(parent_items_of_lines, cur_parent_item) == -1
|
|
||||||
call insert(parent_items_of_lines, cur_parent_item)
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
endfor
|
|
||||||
|
|
||||||
endif
|
|
||||||
|
|
||||||
for parent_item in parent_items_of_lines
|
|
||||||
call s:update_state(parent_item)
|
|
||||||
endfor
|
|
||||||
|
|
||||||
endfunction "}}}
|
endfunction "}}}
|
||||||
|
|
||||||
@ -888,8 +877,6 @@ function! vimwiki#lst#toggle_cb(from_line, to_line) "{{{
|
|||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let parent_items_of_lines = []
|
|
||||||
|
|
||||||
if from_item.cb == ''
|
if from_item.cb == ''
|
||||||
|
|
||||||
"if from_line has no CB, make a CB in every selected line
|
"if from_line has no CB, make a CB in every selected line
|
||||||
@ -906,29 +893,20 @@ function! vimwiki#lst#toggle_cb(from_line, to_line) "{{{
|
|||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
|
for parent_item in parent_items_of_lines
|
||||||
|
call s:update_state(parent_item)
|
||||||
|
endfor
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|
||||||
"if from_line has CB, toggle it and set all siblings to the same new state
|
"if from_line has CB, toggle it and set all siblings to the same new state
|
||||||
let rate_first_line = s:get_rate(from_item)
|
let rate_first_line = s:get_rate(from_item)
|
||||||
let new_rate = rate_first_line == 100 ? 0 : 100
|
let new_rate = rate_first_line == 100 ? 0 : 100
|
||||||
|
|
||||||
for cur_ln in range(from_item.lnum, a:to_line)
|
call s:change_cb(a:from_line, a:to_line, new_rate)
|
||||||
let cur_item = s:get_item(cur_ln)
|
|
||||||
if cur_item.type != 0 && cur_item.cb != ''
|
|
||||||
call s:set_state_plus_children(cur_item, new_rate)
|
|
||||||
let cur_parent_item = s:get_parent(cur_item)
|
|
||||||
if index(parent_items_of_lines, cur_parent_item) == -1
|
|
||||||
call insert(parent_items_of_lines, cur_parent_item)
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
endfor
|
|
||||||
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
for parent_item in parent_items_of_lines
|
|
||||||
call s:update_state(parent_item)
|
|
||||||
endfor
|
|
||||||
|
|
||||||
endfunction "}}}
|
endfunction "}}}
|
||||||
|
|
||||||
function! vimwiki#lst#remove_cb(first_line, last_line) "{{{
|
function! vimwiki#lst#remove_cb(first_line, last_line) "{{{
|
||||||
|
Loading…
Reference in New Issue
Block a user