obsidian-tasks-group / obsidian-tasks

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

cursor changes place when checking task in same line in Live Preview #1424

Open imeed166 opened 1 year ago

imeed166 commented 1 year ago

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

Expected Behavior

When checking a task and the cursor is in the same line, the cursor should stay in its place.

Current behaviour

When checking a task and the cursor is in the same line, the cursor changes place by itself.

https://user-images.githubusercontent.com/38974541/209313787-b184b2fc-d15e-4e61-b153-bf782f13157c.mov

Steps to reproduce

  1. Create a task
  2. Put cursor on same line
  3. Check the task

Which Operating Systems are you using?

Obsidian Version

1.1.8

Tasks Plugin Version

1.20.0

Checks

Possible solution

No response

claremacrae commented 1 year ago

Hi,

I don't think there is enough info to exactly reproduce the behaviour shown in your video, as when you complete the task, it does not get a done date added, which means I do not think that Tasks is doing the completion - and therefore Tasks would not be changing the cursor position.

Did you turn off the Tasks setting for adding Done date when completing a task?

Do you have a global filter enabled? If so, what is it please?

imeed166 commented 1 year ago

Yes, I have disabled adding the done date when checking the task in the setting.

I don't have a global filter

Here are my settings :

image

image

claremacrae commented 1 year ago

Thank you. Please could you run the command Show debug info in Obsidian - click 'Copy to clipboard' and paste the output in this issue, inside a text block, like this:

```text
[paste here]
imeed166 commented 1 year ago
SYSTEM INFO:
    Obsidian version: v1.1.9
    Installer version: v1.1.9
    Operating system: Darwin Kernel Version 21.4.0: Fri Mar 18 00:45:05 PDT 2022; root:xnu-8020.101.4~15/RELEASE_X86_64 21.4.0
    Login status: not logged in
    Insider build toggle: off
    Live preview: on
    Legacy editor: off
    Base theme: dark
    Community theme: none
    Snippets enabled: 0
    Restricted mode: off
    Plugins installed: 6
    Plugins enabled: 1
        1: Tasks v1.20.0

RECOMMENDATIONS:
    Community plugins: for bugs, please first try updating all your plugins to latest. If still not fixed, please try to make the issue happen in the Sandbox Vault or disable community plugins.
claremacrae commented 1 year ago

I believe what is happening is that #1103 fixed the cursor position when the command Tasks: Toggle task done is run to toggle the command. All the code for calculating cursor positions is in src/Commands/ToggleDone.ts.

However, when the command is toggled in Live Preview by clicking on the checkbox, the cursor position jumps to the beginning of the line. When toggling a task in Live Preview, the code is in src/LivePreviewExtension.ts - and it does nothing to retain the cursor position.

claremacrae commented 1 year ago

For developers: there is a write-up of how Tasks handles state changes in:

https://github.com/obsidian-tasks-group/obsidian-tasks/blob/main/CONTRIBUTING.md#how-does-tasks-handle-status-changes

claremacrae commented 1 year ago

For now, if this is inconveniencing you, the workaround to keep the cursor in the same position is to bind a hotkey to the Tasks: Toggle task done command and use that to toggle the task on the line where the cursor is.

claremacrae commented 1 year ago

I'm afraid this is in a complex area of the code, and not likely to be something that will be fixed soon, unless anyone volunteers to help.