obsidian-tasks
obsidian-tasks copied to clipboard
Support editing existing tasks from the API
⚠️ Please check that this feature request hasn't been suggested before.
- [X] I searched previous Ideas in Discussions didn't find any similar feature requests.
- [X] I searched previous Issues didn't find any similar feature requests.
🔖 Feature description
Currently Tasks plugin provides one API createTaskLineModal
that allows create a task-edit-or-create modal from custom code. But clearly the API does not support editing from an existing task cause there is no way to tell it which task item to be edited. However, it will be a great help if one could pass location of task items (in form of <filename, position in the file>) and enable editing.
✔️ Solution
Allow arguments that describe position of a specific task item when calling the API, so that editing could be performed on an existing task item.
❓ Alternatives
Currently I have to:
- firstly locate to the task item explicitly by opening the file and moving cursor to the position,
- call the task-edit-or-create modal by:
this.app.commands.commands['obsidian-tasks-plugin:edit-task'] .editorCheckCallback(false, editor, view)
But it is disturbing since the note is required to be opened.
📝 Additional Context
No response
Hi, thanks for the suggestion.
There was already a pull request for this:
- #1786
It got closed because it came in too late for the already huge 2.0.0 release - and so would have been a breaking change after the 2.0.0 release if it had been merged.
Just to set expectations...
I do not expect the new API function will take a filename and line number though.
It will take a task line as a string, and return the modified line back to the caller.
So the responsibility for reading the file, and saving the edited line will be with the caller.
Thanks for the information! Glad to know you have plans for this functionality, and it is better that the api returns the result instead of modifying the underlying note.
where should I look to start making changes to make this happen?
where should I look to start making changes to make this happen?
Thank you. Please read the comment above: https://github.com/obsidian-tasks-group/obsidian-tasks/issues/1945#issuecomment-1542259481.
It shows an earlier attempt to do this, but unfortunately would have been a breaking change to the API.
But it should give you a good idea.
The relevant source files can be found from that PR.
I hope that helps.