obsidian-tasks icon indicating copy to clipboard operation
obsidian-tasks copied to clipboard

Support editing existing tasks from the API

Open Leonezz opened this issue 1 year ago • 4 comments

⚠️ 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:

  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

Leonezz avatar May 10 '23 13:05 Leonezz

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.

claremacrae avatar May 10 '23 13:05 claremacrae

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.

Leonezz avatar May 10 '23 14:05 Leonezz

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

knoxy5467 avatar Feb 13 '24 00:02 knoxy5467

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.

claremacrae avatar Feb 13 '24 22:02 claremacrae