From 3329a759f1d63f5c45cc13c43c74cac509133c1b Mon Sep 17 00:00:00 2001 From: Marko Stojanovic Date: Sun, 2 May 2021 23:36:21 +0200 Subject: [PATCH] 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 --- plugin/bullets.vim | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/plugin/bullets.vim b/plugin/bullets.vim index 525e5e9..c9bfbbd 100644 --- a/plugin/bullets.vim +++ b/plugin/bullets.vim @@ -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)