Skip to content

Conversation

@maishivamhoo123
Copy link
Contributor

Fix: Incorrect checkbox toggling when preceded by a codeblock checkbox

This PR fixes Issue #5319, where toggling a checkbox in view mode updates the wrong task if a checkbox inside a fenced code block appears earlier in the note.

What’s fixed

  • Checkboxes inside code blocks (``` or ~~~) are no longer counted as task items.
  • Task indexing now correctly ignores codeblock content.
  • The correct checkbox is always toggled.

A demo video is attached showing the bug and the expected behavior.

vid.mp4

Copy link
Contributor

@spaghetti-coder spaghetti-coder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick reaction, but found some issues with the solution.

export function isInsideCodeBlock(lines :string [] , index : number):boolean{
let inside = false;
for(let i = 0 ; i <= index ; i++){
if(lines[i].startsWith("```")){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't trap the following cases:

  1. When codeblock is embraced with ~~~ instead of ```
  2. When the codeblock has let's say 2 spaces offset:
The codeblock has 2 spaces offset
  ```
  - [ ] foo
  ```
- [ ] bar
  1. The following one will still make foo checked:
````
``` <- This will be rendered as a triple back quote inside the code block
- [ ] foo
````
- [ ] bar

let currentTaskIndex = 0;

for (let i = 0; i < lines.length; i++) {
if (isInsideCodeBlock(lines, i)) continue;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will unnecessarily slow down the execution. Better put the check inside the match block

return lines.join("\n");
}

export function isInsideCodeBlock(lines :string [] , index : number):boolean{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function only covers very straight scenarios. A sample when it fails

<!--
Some comments
```
More comments
-->
```
The function thinks this line is not in a codeblock
```

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry sir for inconvenience i will fix it please give me some time.

@boojack boojack closed this Dec 10, 2025
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.

3 participants