SidOfc / mkdx

A vim plugin that adds some nice extra's for working with markdown documents
https://www.vim.org/scripts/script.php?script_id=5620
MIT License
482 stars 13 forks source link

allow toggling nested checkbox state from topmost item #158

Closed ckjoris closed 2 years ago

ckjoris commented 2 years ago

it was not possible to toggle checkbox state (of the whole tree) when cursor is on the topmost item (item 'a1' in example markdown)

- [ ] a1
  - [ ] b
    - [ ] b1
    - [ ] b2
  - [ ] c
    - [ ] c1
  - [ ] d

this PR fixes that

SidOfc commented 2 years ago

Hello there! Thank you for the PR. Will this always stay within the same list as well? e.g. what happens when I have multiple lists separated only by whitespace? e.g.

- [ ] a1
  - [ ] a1.1
    - [ ] a1.1.1
    - [ ] a1.1.2
  - [ ] a1.2
    - [ ] a1.2.1
    - [ ] a1.2.2

- [ ] b1
  - [ ] b1.1
    - [ ] b1.1.1
    - [ ] b1.1.2
  - [ ] b1.2
    - [ ] b1.2.1
    - [ ] b1.2.2

It's been long since I worked on this part and I myself can't remember everything about the intricate inner workings of this anymore. It does seem however that I added an explicit check for indent != 0 which seems to be negated at least partially by your changes.

ckjoris commented 2 years ago

Hi & thanks for reviewing. I just retested it - yes it stays within the same list. Both if lists are separated by whitespace, or if not separated at all.

It works because the second part here if ((startc < lnum) || (indent != 0) || (startc == lnum && indent == 0)) is only true if cursor is on the checkbox with 0 indent. In the second list, startc is not equal to lnum.

SidOfc commented 2 years ago

Thank you for clarifying and going through the effort of creating a PR @ckjoris! I don't see any other potential issues so I'm going to merge it 👍 Your contribution is appreciated!