Skip to content
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

apiV1.executeToggleTaskDoneCommand does not modify the note [by design - add to the docs] #3287

Open
3 of 8 tasks
ctrl-q opened this issue Jan 25, 2025 · 9 comments
Open
3 of 8 tasks
Labels
scope: documentation Improvements or additions to documentation scope: for plugin developers Tools for use by plugin developers, including the Tasks API

Comments

@ctrl-q
Copy link

ctrl-q commented Jan 25, 2025

⚠️ Check issue is valid.

⚠️ Check that this issue hasn't been reported before.

Steps to reproduce

  1. Open a note named Untitled
  2. Paste in a task with the text - [ ] This is a task 📅 2024-04-24
  3. Open the Obsidian Developer Tools Console
  4. Run the following command:
app.plugins.plugins['obsidian-tasks-plugin'].apiV1.executeToggleTaskDoneCommand('- [ ] This is a task 📅 2024-04-24', 'Untitled')

Expected Behavior

The note should be updated with the task marked as completed

Current behaviour

The note is not updated

Which Operating Systems are you using?

  • Android
  • iPhone/iPad
  • Linux
  • macOS
  • Windows

Obsidian Version

1.7.7

Tasks Plugin Version

7.14.0

Checks

  • I have tried it with all other plugins disabled and the error still occurs

Possible solution

No response

@ctrl-q ctrl-q added the type: bug Something isn't working label Jan 25, 2025
@claremacrae claremacrae added the scope: for plugin developers Tools for use by plugin developers, including the Tasks API label Jan 25, 2025
@claremacrae
Copy link
Collaborator

You are correct, it does not modify the note.

My guess is that you have not found the documentation that explains how it works.
https://publish.obsidian.md/tasks/Advanced/Tasks+Api

@claremacrae claremacrae added the invalid This doesn't seem right label Jan 25, 2025
@claremacrae claremacrae changed the title apiV1.executeToggleTaskDoneCommand does not modify the note apiV1.executeToggleTaskDoneCommand does not modify the note [by design] Jan 25, 2025
@claremacrae
Copy link
Collaborator

claremacrae commented Jan 25, 2025

The following request covers adding the ability for the API to modify an existing task line.

Feel free to up-vote it and subscribe to it.

@ctrl-q
Copy link
Author

ctrl-q commented Jan 25, 2025

You are correct, it does not modify the note.

My guess is that you have not found the documentation that explains how it works. https://publish.obsidian.md/tasks/Advanced/Tasks+Api

I did. The documentation mentions that it "Executes the 'Tasks: Toggle task done' command on the supplied line string".

I guess this is more of a documentation question at this point, then.

"Simulate" seems like a more accurate verb than "Execute" in this scenario.

The fact that the method requires the file path adds to the confusion. I can input any random string there and get the same result, regardless of whether or not the task exists in my vault, let alone in that path

@claremacrae
Copy link
Collaborator

Current behaviour

Ah - apologies, I misread which of the two functions you are using.

You are using the recently-added one, and yes, it does indeed take an existing task line.

The important bit in that documentation is that it returns the edited string:

Image

Tasks has no idea where the line came from, and in fact this functionality was written by the maintainer of the Kanban plugin, where there will not even be a markdown-editing-view open.

So it is still the responsibility of the caller to write the line to the correct place in their file.

What are you trying to do?

I would normally expect Tasks plugin users to use one of the many built-in ways of toggle a task:

https://publish.obsidian.md/tasks/Editing/Toggling+and+Editing+Statuses

So what is your scenario? Why put the cursor on a line and run a plugin API instead?

@claremacrae
Copy link
Collaborator

Yes, the console output shows the returned result of the function, and it is the toggled task line:

Image

@ctrl-q
Copy link
Author

ctrl-q commented Jan 26, 2025

I use the Full Calendar plugin to display my tasks. I can provide a callback that is called when I check the task from my calendar, allowing me to actually check it in my note.

I'll just wrap the executeToggleTaskDoneCommand result in a app.vault.process now that I know it doesn't actually modify the file. The documentation led me to believe it did

@claremacrae
Copy link
Collaborator

Do you have any suggestions for improvements to the wording of the documentation?

@claremacrae claremacrae added question Further information is requested scope: documentation Improvements or additions to documentation and removed invalid This doesn't seem right labels Jan 26, 2025
@ctrl-q
Copy link
Author

ctrl-q commented Jan 27, 2025

It's rather subjective, but I might go with:

"Simulates the 'Tasks: Toggle task done' command on the supplied line string. It returns a string representing the task if it had been toggled, updated according to a user's preferences, accounting for recurrence rules and completed status."

@claremacrae claremacrae removed the question Further information is requested label Jan 29, 2025
@claremacrae claremacrae changed the title apiV1.executeToggleTaskDoneCommand does not modify the note [by design] apiV1.executeToggleTaskDoneCommand does not modify the note [by design - add to the docs] Feb 1, 2025
@claremacrae
Copy link
Collaborator

I've removed the bug label - and added a documentation label, to remind me to clarify the documentation.

@claremacrae claremacrae removed the type: bug Something isn't working label Feb 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope: documentation Improvements or additions to documentation scope: for plugin developers Tools for use by plugin developers, including the Tasks API
Projects
None yet
Development

No branches or pull requests

2 participants