Skip to content

Commit 3329a75

Browse files
author
Marko Stojanovic
committed
fix #100 to correctly mark parent checkbox
Code is commented since the math is a bit tricky and not intuitive. And vimscript doesn't like floating point calculations
1 parent 486f97d commit 3329a75

1 file changed

Lines changed: 16 additions & 3 deletions

File tree

plugin/bullets.vim

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,9 +1238,22 @@ fun! s:sibling_checkbox_status(lnum)
12381238
endif
12391239
endif
12401240
endfor
1241-
let l:divisions = len(l:checkbox_markers) - 1.0
1242-
let l:completion = float2nr(ceil(l:divisions * l:checked / l:num_siblings))
1243-
return l:checkbox_markers[l:completion]
1241+
" we are interested in the number of markings that can give us sets of
1242+
" percentage to group the markings
1243+
let l:divisions = len(l:checkbox_markers) - 2.0
1244+
" Border case no need to calculate and it fixex the problem of the
1245+
" calculation below never being able to get this last number.
1246+
if l:checked ==# l:num_siblings
1247+
return l:checkbox_markers[len(l:checkbox_markers) - 1]
1248+
else
1249+
" 1.0 multiplication is to have float calculations.
1250+
" The calculation looks for a multiple of a percentage class to define
1251+
" which marker to use.
1252+
let l:ratio_checked = 1.0 * l:checked / l:num_siblings
1253+
let l:persentage_class = 1.0 / l:divisions
1254+
let l:completion = float2nr(ceil(l:ratio_checked / l:persentage_class))
1255+
return l:checkbox_markers[l:completion]
1256+
endif
12441257
endfun
12451258

12461259
fun! s:replace_char_in_line(lnum, chari, item)

0 commit comments

Comments
 (0)