add RecomputeCheckboxes command #164
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Here we add a new
RecomputeCheckboxescommand that scans the current list under the cursor, then recomputes partials, preserving checkbox leaf state (and uses those leaves as a source of truth).Rationale
Partial checkbox computation is currently only triggered when checkboxes are toggled (via
toggle_checkboxes_nested()via theToggleCheckboxcommand), but there are a lot of ways that underlying state can change without triggering computation, including:Here I've minimally added the
RecomputeCheckboxescommand to allow a full compute of checkboxes in the list.Edge cases
Partial checkboxes without children
I've decided to treat these as unchecked (with the assumption that it's better for for users to manually mark these as checked themselves if necessary).
Non-checkbox content in lists
To make the minimal change in this PR, I'm leaving the current behavior: non-checkbox children are treated as unchecked checkboxes. For example, the following lists will be recomputed as follows:
I'd like to follow-up with another PR that allows
s:sibling_checkbox_status()to handle non-checkbox content, but the change is a bit more involved (since it requires a bit of checking to avoid division-by-zero).bullets.vim/plugin/bullets.vim
Lines 1468 to 1480 in 8f420b5
Possible future work
Having this function can enable something like a
bullets_recompute_checkboxes_on_changeconfig variable that functions similarly tobullets_renumber_on_change, but that can likewise be handled in a future PR.Thank you for reviewing!