Skip to content

Conversation

@xs
Copy link
Contributor

@xs xs commented Sep 13, 2025

Description

Here we add a new RecomputeCheckboxes command 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 the ToggleCheckbox command), but there are a lot of ways that underlying state can change without triggering computation, including:

  • inserting lines with new checkbox bullets
  • deleting lines with checkbox bullets
  • manually editing checkbox content in insert mode

Here I've minimally added the RecomputeCheckboxes command 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:

- [x] parent
  - [x] checked child
  - [x] checked child
  
- [o] parent
  - [x] checked child
  - non-checkbox content
  - [x] checked child

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

for l:lnum in l:siblings
let l:indent = indent(l:lnum)
let l:bullet = s:closest_bullet_types(l:lnum, l:indent)
let l:bullet = s:resolve_bullet_type(l:bullet)
if !empty(l:bullet) && has_key(l:bullet, 'checkbox_marker')
let l:checkbox_content = l:bullet.checkbox_marker
if l:checkbox_content =~# '\v[xX' . l:checkbox_markers[-1] . ']'
" Checked
let l:checked += 1
endif
endif
endfor

Possible future work

Having this function can enable something like a bullets_recompute_checkboxes_on_change config variable that functions similarly to bullets_renumber_on_change, but that can likewise be handled in a future PR.

Thank you for reviewing!

@harshad1 harshad1 merged commit ab474fd into bullets-vim:master Dec 6, 2025
1 check passed
@harshad1
Copy link
Collaborator

harshad1 commented Dec 6, 2025

Looks good. Merging.

Apologies for the delay getting to this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants