-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Fix/checkbox indexing codeblock #5321
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix/checkbox indexing codeblock #5321
Conversation
spaghetti-coder
left a comment
There was a problem hiding this 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("```")){ |
There was a problem hiding this comment.
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:
- When codeblock is embraced with
~~~instead of``` - When the codeblock has let's say 2 spaces offset:
The codeblock has 2 spaces offset
```
- [ ] foo
```
- [ ] bar
- The following one will still make
foochecked:
````
``` <- 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; |
There was a problem hiding this comment.
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{ |
There was a problem hiding this comment.
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
```
There was a problem hiding this comment.
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.
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
A demo video is attached showing the bug and the expected behavior.
vid.mp4