obsidian-tasks-group / obsidian-tasks

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

When the Add/edit modal updates a task line, place the cursor at the end of the edited line #525

Open tiktuk opened 2 years ago

tiktuk commented 2 years ago

Expected Behavior

I expected the cursor to be at the end of the line to be able to continue writing out the task. I do this mainly to be able to add tags with autocomplete but also just being able to hit return and go to next line is nice.

Current Behavior

The cursor is inserted in front of the new task.

Steps to Reproduce

Create a new task using the modal.

Context (Environment)

schemar commented 2 years ago

Thanks. Related to #460.

Wenzel commented 1 year ago

This issue is still affecting me. @schemar are you still aware of this, or did you think that #460 fixed both bugs ?

I'm using obsidian tasks v1.20.0 and when I create a new tasks with CTRL+T (modal), the cursor is placed at the beginning of the line, which is really annoying when creating multiple tasks in a row.

claremacrae commented 1 year ago

Having looked at the behaviour of #1424 and at #460, I understand more about #460.

As its summary says, #460 specifically fixed the case when the user ran the Tasks: Toggle task done command.

That's a different area of code from running the modal.

There would need to be a different fix for this issue.

I would like to see some unifying of the existing code for toggling and editing tasks in different Obsidian Modes (Source, Live Preview and Reading). They differ in subtle ways, and I've tried a couple of times to catalogue the different behaviours and differences in implementation details, but got bogged down each time.

Unfortunately this means that a fix for this is unlikely to come any time soon.

claremacrae commented 1 year ago

Looking at this issue more closely, it is labelled as an enhancement, but the description is this:

The cursor is placed before the task when creating a new task using the modal

which reads as though it is describing a bug, as it does not say what the actual desired behaviour is.

I was confused by this.

What if the summary were phrased as:

When edits are saved by the modal, always leave the cursor at end of line (in Live Preview and Source modes)

In other words, don't worry about complicated things like trying to preserve the original cursor location when the modal was opened - just always leave the cursor at the end of the line, if the user accepted edits the modal.

@tiktuk @Wenzel are you happy with this simple proposed behaviour? I think it sounds like what you are both requesting.

Wenzel commented 1 year ago

hi @claremacrae

In other words, don't worry about complicated things like trying to preserve the original cursor location when the modal was opened - just always leave the cursor at the end of the line, if the user accepted edits the modal.

Yes that's what I meant, just put the cursor at the end of the line, so I can press ENTERand create another task right after.

Thanks ! :christmas_tree:

claremacrae commented 1 year ago

I would appreciate help on this, and will add the 'help wanted' label.

Steps to reproduce - For example in Source Mode - but same applies in Live Preview Mode

  1. Create any old note, in a vault with the Tasks plugin enabled
  2. Switch to Source Mode
  3. Put the cursor in a blank line
  4. Run Tasks: Create or edit task command 5.Type any old junk in the Description
  5. Click Apply

Actual behaviour:

The new task like is written out, like - [ ] asdfafasd The cursor is placed at the start of the line

Requested behaviour:

The new task like is written out, like - [ ] asdfafasd The cursor is placed at the end of the line

The Code

Here is some background info for anyone who might be interested in looking at the code.

It seems to me that the crucial bit of code for this issue is then the following. Can it be updated to place the cursor at the end of the last line in serialized - which is likely to have only 1 line - but I am not sure that will always be the case.

https://github.com/obsidian-tasks-group/obsidian-tasks/blob/d1479b811e208ccf66b9e1a9dabfaddd1f336e3b/src/Commands/CreateOrEdit.ts#L27-L32

I am not sure whether it's relevant, but there is another instance of the TaskModal and this is how it updates the task:

https://github.com/obsidian-tasks-group/obsidian-tasks/blob/54682d4f89cc42efda9d3f9050f9e40596365bf5/src/QueryRenderer.ts#L238-L243

Testing

Please test that the cursor is placed at the end of the line both in Source Mode and Live Preview.

Thank you in advance for any help offered.

tiktuk commented 1 year ago

Hi,

Thanks for working on this :) .

I would like to test it, but I don't know where to find the new code. Do you have a branch for this work?

claremacrae commented 1 year ago

What do you mean by the new code @tiktuk

tiktuk commented 1 year ago

Sorry, I thought you were asking for testing of a possible implementation of the behaviour with the newline at the end of the task.

(I just tested, and the behaviour is the same in source mode, btw.)

claremacrae commented 1 year ago

Ah no.

I would appreciate help on this, and will add the 'help wanted' label.

When I add the ‘help wanted’ label, to let other programmers know it is a particular issue I would like help on, I try to make an effort to write up enough detail about the code and the issue to get them started easily.

tiktuk commented 1 year ago

Got it, thanks :) .

hasanyilmaz commented 4 months ago

That issue still gives me a little pain. That happens only for newly created tasks from shortcut. "Create or edit Task"

If you create checkbox first, and edit it in window, there is no problem.

image