Skip to content

Commit

Permalink
fix bullets-vim#100 to correctly mark parent checkbox
Browse files Browse the repository at this point in the history
Code is commented since the math is a bit tricky and not intuitive. And
vimscript doesn't like floating point calculations
  • Loading branch information
Marko Stojanovic committed May 2, 2021
1 parent 486f97d commit 3329a75
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions plugin/bullets.vim
Original file line number Diff line number Diff line change
Expand Up @@ -1238,9 +1238,22 @@ fun! s:sibling_checkbox_status(lnum)
endif
endif
endfor
let l:divisions = len(l:checkbox_markers) - 1.0
let l:completion = float2nr(ceil(l:divisions * l:checked / l:num_siblings))
return l:checkbox_markers[l:completion]
" we are interested in the number of markings that can give us sets of
" percentage to group the markings
let l:divisions = len(l:checkbox_markers) - 2.0
" Border case no need to calculate and it fixex the problem of the
" calculation below never being able to get this last number.
if l:checked ==# l:num_siblings
return l:checkbox_markers[len(l:checkbox_markers) - 1]
else
" 1.0 multiplication is to have float calculations.
" The calculation looks for a multiple of a percentage class to define
" which marker to use.
let l:ratio_checked = 1.0 * l:checked / l:num_siblings
let l:persentage_class = 1.0 / l:divisions
let l:completion = float2nr(ceil(l:ratio_checked / l:persentage_class))
return l:checkbox_markers[l:completion]
endif
endfun

fun! s:replace_char_in_line(lnum, chari, item)
Expand Down

0 comments on commit 3329a75

Please sign in to comment.