obsidian-tasks-group / obsidian-tasks

Task management for the Obsidian knowledge base.
https://publish.obsidian.md/tasks/
MIT License
2.24k stars 221 forks source link

Support editing existing tasks from the API #1945

Open Leonezz opened 1 year ago

Leonezz commented 1 year ago

⚠️ Please check that this feature request hasn't been suggested before.

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

  1. firstly locate to the task item explicitly by opening the file and moving cursor to the position,
  2. 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

claremacrae commented 1 year ago

Hi, thanks for the suggestion.

There was already a pull request for this:

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.

Leonezz commented 1 year ago

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.

knoxy5467 commented 4 months ago

where should I look to start making changes to make this happen?

claremacrae commented 4 months ago

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.