obsidian-tasks-group / obsidian-tasks

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

Shortcut for launching the modal can trigger shortcuts inside the modal, to override default settings #2503

Open swoh816 opened 11 months ago

swoh816 commented 11 months ago

Please check that this issue hasn't been reported before.

Expected Behavior

'Create or edit Task' Modal shows Normal priority by default.

Current behaviour

If you set the shortcut for "Create or edit task" to Alt + l, the 'Create or edit Task' Modal pops up with the priority set to Low (which is set to Normal by default).

This is generally applicable: If you set the shortcut for "Create or edit task" the same as the shortcut for any of the items inside the 'Create or edit Task' Modal, the modal opens with the item being affected. For example, if you set the shortcut for "Create or edit task" to Alt + f, which is a shortcut for "Only future dates" inside 'Create or edit Task' Modal, using the shortcut in the document opens the modal with "Only future dates" disabled. ("Only future dates" is enabled by default.)

Thank you very much for the amazing plugin!

Steps to reproduce

  1. Change shortcut for "Create or edit task" to Alt + l
  2. Press Alt + l to open 'Create or edit Task' Modal
  3. You can find the priority is set to Low (the default behaviour is to have Normal priority)

Which Operating Systems are you using?

Obsidian Version

1.4.16

Tasks Plugin Version

5.2.0

Checks

Possible solution

Make shortcuts in the 'Create or edit Task' Modal active after the modal is loaded completely so that the modal's default behaviour is not affected by whatever shortcut was used for opening the modal.

claremacrae commented 11 months ago

Hi @swoh816, thank you for logging this. It's a new report, I've not seen it before.

I've edited the issue title to make it more specific.

claremacrae commented 11 months ago

I can confirm that this is reproducible on Mac.

  1. Set the hotkey for Tasks: Create or edit task to Ctrl + Opt + O
  2. Put the cursor on a blank line in Source or Live Preview Mode
  3. Type Ctrl + Opt + O

Expected: Priority is Normal Actual: Priority is Lowest

claremacrae commented 11 months ago

I've no experience to know how to fix this, and because Obsidian allows user control of the shortcuts for commands like opening the Tasks modal, I'm afraid it's not a priority for me personally to fix it. There are other more widely applicable ways I can spend my time on Tasks.

I can think of the following workarounds:

  1. Change the hotkey for Tasks: Create or edit task to a key that is not used in this modal.
  2. Turn off shortcuts in the modal.
claremacrae commented 11 months ago

I've added the 'help-wanted' label to this.

In case anyone with Svelte experience is interested in fixing this:

  1. The source file is src/ui/EditTask.svelte
  2. There is quite a comprehensive guide on Contributing to tasks.
  3. I would be available to pair with anyone with Svelte experience, to pool knowledge... Please use the email address in my GitHub profile to set up a session to work together.
claremacrae commented 10 months ago

I've noted this limitation in the docs - see https://github.com/obsidian-tasks-group/obsidian-tasks/commit/698565706f8f90ee3f3f73235c2f3010cc0b393a.

This will be published as part of the next Tasks release.

claremacrae commented 10 months ago

I wonder whether the following code is anything to do with the problem:

https://github.com/obsidian-tasks-group/obsidian-tasks/blob/7e9f420c448ee290071679c93af6b02e4290e616/src/ui/EditTask.svelte#L278-L286

And it's referenced on line 397 here:

https://github.com/obsidian-tasks-group/obsidian-tasks/blob/7e9f420c448ee290071679c93af6b02e4290e616/src/ui/EditTask.svelte#L394-L401

I expect that:

Maybe there's a fix around having the modal keep track of key-down events as well as key-up ones - and only acting on the key-up if it had previously seen the key-down.

I can imagine that will lead to corner cases with issues of timing of typing, and will be rather hard to test reliably.