Skip to content

feat: Add the ability to launch the task modal to edit an existing line #3528

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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

justise
Copy link
Contributor

@justise justise commented Jul 5, 2025

Types of changes

Changes visible to users:

Internal changes:

  • Tests (prefix: test - additions and improvements to unit tests and the smoke tests)

Description

Expose an editTaskLineModal(taskLine: string) : Promise<string> method in the API.

This method takes the content of the task and populates the values into the tasks modal.

The return value is the newly edited tasks markdown, or empty if the modal is canceled.

  • Expose the new API Method
  • Tests for the new API method
  • Update the documentation to document how to use the new API
  • Remove the known limitation of the API stating you cannot edit a task
  • Also extended the mocks to include a mock of the Modal class
  • Typed the parameters for the TasksModal, this helps to ensure the mocks of the Task modal are importing all the right properties which I encountered and didn't realize why allTasks wasn't being passed.

Motivation and Context

This will support external plugins to interact with tasks by leveraging the Obsidian Tasks API. Without this, plugins cannot enter the tasks edit modal, they'll require users to launch it themselves.

Fixes #1945.

How has this been tested?

[x] Unit tests for the new editTaskLineModal() internal method
[x] Unit tests for the API method to ensure it calls
[ ] Smoke Testing

Screenshots (if appropriate)

API, n/a

Checklist

Terms

@justise justise force-pushed the edit-modal-api-v2 branch from 0bd8e12 to 3a16d5f Compare July 5, 2025 23:53
@justise
Copy link
Contributor Author

justise commented Jul 6, 2025

Next, I need to smoke test and add smoke tests for the tasks edit api

@claremacrae claremacrae added scope: scripting Issues to do with custom filters, custom sorting and similar scope: edit task The Create or edit task modal/dialog labels Jul 6, 2025
@claremacrae
Copy link
Collaborator

Hi @justise, many thanks for doing this.

I have a few suggestions for the docs... I'll wait until you make it non-Draft, and then to save your time, I'll make the edits and push them to your branch.

@claremacrae
Copy link
Collaborator

claremacrae commented Jul 6, 2025

I've done two smoke tests for it, having built the plugin with the code on this PR.

Both worked great!!! 😄

Test 1

  1. Paste this in the developer console.
const tasksApi = this.app.plugins.plugins['obsidian-tasks-plugin'].apiV1;
let editedTaskLine = await tasksApi.editTaskLineModal('- [ ] #task Do every day 🔼 🔁 every day ➕ 2025-07-06 ⏳ 2025-07-06');
console.log(editedTaskLine);
  1. Change the Status to Done

Result:

- [ ] #task Do every day 🔼 🔁 every day ⏳ 2025-07-07
- [x] #task Do every day 🔼 🔁 every day ➕ 2025-07-06 ⏳ 2025-07-06 ✅ 2025-07-06
undefined

Test 2 - changed Tasks settings

  1. Reverse the order of Recurring tasks in the Tasks settings
  2. Paste the same lines in the developer console.
const tasksApi = this.app.plugins.plugins['obsidian-tasks-plugin'].apiV1;
let editedTaskLine = await tasksApi.editTaskLineModal('- [ ] #task Do every day 🔼 🔁 every day ➕ 2025-07-06 ⏳ 2025-07-06');
console.log(editedTaskLine);
  1. Change the Status to Done

Result is the same lines returned but correctly in the opposite order:

- [x] #task Do every day 🔼 🔁 every day ➕ 2025-07-06 ⏳ 2025-07-06 ✅ 2025-07-06
- [ ] #task Do every day 🔼 🔁 every day ⏳ 2025-07-07

@claremacrae claremacrae added scope: for plugin developers Tools for use by plugin developers, including the Tasks API and removed scope: scripting Issues to do with custom filters, custom sorting and similar labels Jul 6, 2025
@justise
Copy link
Contributor Author

justise commented Jul 7, 2025

Thanks. Want me to add those to the smoke tests docs?

Admittedly I haven't yet smoke tested myself but could mark it ready for review now to unblock till I can do some manual testing.

@claremacrae
Copy link
Collaborator

Thanks. Want me to add those to the smoke tests docs?

Admittedly I haven't yet smoke tested myself but could mark it ready for review now to unblock till I can do some manual testing.

Just one of them will be fine.

If you could add it to the Demo page I linked in #3509 (comment), that would be ideal - just so we don't forget about how to test it in future...

@claremacrae
Copy link
Collaborator

Personally, I don't feel a need for any more manual testing. I can't think of anything that could go wrong, based on the smoke testing already done.

(The automated tests of the Modal via the API are mostly testing mocks, as far as I can tell, rather than testing actual behaviour - but there is already very thorough other testing of the actual API behaviour - so in the case I'm happy with the smoke testing being sufficient..)

@justise
Copy link
Contributor Author

justise commented Jul 10, 2025

Pushing some smoke test documentation, hope its decent. :)

@justise justise marked this pull request as ready for review July 10, 2025 15:55
Copy link

@claremacrae
Copy link
Collaborator

Pushing some smoke test documentation, hope its decent. :)

Thank you! I will review this as soon as I can.

## `editTaskLineModal(taskLine: string): Promise<string>;`

> [!released]
This method was introduced in Tasks X.X.X.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Version needs updating

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you asked:
https://publish.obsidian.md/tasks-contributing/Documentation/Version+numbers+in+documentation

It’s on my list to edit that version to X.Y.Z and then the release script will set the version number automatically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope: edit task The Create or edit task modal/dialog scope: for plugin developers Tools for use by plugin developers, including the Tasks API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support editing existing tasks from the API
2 participants