Markdown List delete completed tasks action no longer working

I have an action that’s no longer working. I’ve been using it for ages and it’s called delete completed tasks (.md lists) — though I likely renamed it from whatever it was originally called.

It just does… nothing now (under latest macOS & iOS/iPadOS releases). Possibly since the recent Drafts 37 release, though I can’t be certain.

I don’t see anything related to Markdown list item deletion on the Action Directory, so maybe this Action’s been retired?

If you share the action you have (keep it unlisted and post the link), others can then take a look. At the moment it would be mostly guesswork.

1 Like

Great idea! I don’t think there’s anything sensitive in it — and I certainly didn’t write it originally — but it’s not too long and doesn’t look too complicated to my non-programmer eyes. :slight_smile:

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 :slight_smile:

1 Like

My completed tasks were badly formatted — so they weren’t matching the test-string in the Action (I had no space between the - and the opening [

Such a rookie mistake. :man_facepalming:

Thanks for giving my head a shake for me!

:sunglasses::+1::+1: