I’ve had a check through the code, and it all looks fine.
I gave it a run on Drafts 37.0 (225) on the following draft content.
- [ ] incomplete
- [x] complete
- [ ] incomplete
- [x] complete
- [ ] incomplete
It gave me this, which is what I would expect.
- [ ] incomplete
- [ ] incomplete
- [ ] incomplete
Does the above content work for you?
If it does, can you post a copy of the content that is failing - sanitised if necessary, and please post between triple backticks so tthe forum does not render it as Markdown:
```
Content goes here
```
Digging a little further, and not into the original issue…
Looking at the code, I purposefully gave it a try on this:
- [ ] incomplete
- [x] complete
- [ ] incomplete but with "- [x]" in the line
- [x] complete
- [ ] incomplete
- [X] complete
- [ ] incomplete
Which gives this … not exactly what I would hope for, but it is what I would expect.
- [ ] incomplete
- [ ] incomplete
- [X] complete
- [ ] incomplete
If you switch out the existing code for these two lines of code…
draft.content = draft.lines.filter(strLine => !strLine.toLowerCase().trim().startsWith("- [x] ")).join("\n");
draft.update();
Explanation
The first line is take the array of lines for the current draft and filter out anything that when trimmed of whitespace (leading/trailing) starts with a completed task (“x” or “X”), then join them back together and make that the content of the draft.
The last line explicitly updates the draft.
… the results will be the following; which I think is probably more what would be wanted.
- [ ] incomplete
- [ ] incomplete but with "- [x]" in the line
- [ ] incomplete
- [ ] incomplete
That should cover a few more edge cases and I think making the code a little better, but that point is certainly debatable