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

Avoid trailing spaces in task creation [via Auto Suggest] #1014

Open bergis opened 2 years ago

bergis commented 2 years ago

Expected Behavior

When creating or editing a task in a note (not through the modal) and use on of the drop down quick adds (like "scheduled date" -> "today") an extra space after is added. If this is the last entry of the task and I press enter I expect the trailing space to be removed.

Current behaviour

When creating or editing a task in a note (not through the modal) and use on of the drop down quick adds (like "scheduled date" -> "today") an extra space after the date is added. If this is the last entry of the task and I press enter the trailing space is left behind.

This triggers 009-no-trailing-spaces when linting the markdown file. ( https://github.com/updownpress/markdown-lint/blob/master/rules/009-no-trailing-spaces.md )

Steps to reproduce

When creating or editing a task in a note (not through the modal) and use on of the drop down quick adds (like "scheduled date" -> "today") an extra space after the date is added. If this is the last entry of the task and I press enter the trailing space is left behind.

Which Operating Systems are you using?

Obsidian Version

0.15.9

Tasks Plugin Version

1.11.1

Checks

bergis commented 2 years ago

To keep the issue clean I was trying to be concise in the template. So adding this here: Thanks for a awsome plugin! So powerful! Great work!

claremacrae commented 2 years ago

Yes, I do agree that this would be nice to have. Thank you for reporting it.

It's helpful to have the markdown-lint reference too.

/CC @esm7 for info.

AnnaKornfeldSimpson commented 2 years ago

@bergis As a temporary workaround, you might want to check out the community plugin Obsidian Linter, which can autofix a number of markdownlint issues if you configure it to. I have mine set to "lint on save" so that I get the benefits of not needing to type the spaces in the middle of typing a task but the trailing one is removed automatically. (Note that Obsidian Linter is currently autofix only; it will not highlight the errors that it is going to fix the way some Markdownlint IDE integrations do, so consider backing up your notes before running the linter. But I have found it to be worth the setup effort!)

esm7 commented 2 years ago

That's indeed an annoying issue. There are two cases here that I can think about:

  1. If the minimal match is configured as 0, and the 'Enter' sign is shown in the popup as a way to enter a new line, it's easy to remove trailing spaces before executing the new line.
  2. For the more general case, when the completion popup is not displayed when pressing Enter, this is more complicated. The plugin can register to key presses and on every Enter pressed in the document try to understand if it's a task line and if spaces need to be trimmed, but that's a pretty big mechanism to accomplish something very specific. I wish there could be something simpler but I can't think of any.

P.S: we can also reformat task lines on save, similarly to the approach of Obsidian Linter, but isn't this too intrusive for a tasks plugin?

claremacrae commented 2 years ago

Does the completion mechanism add a space after every time it inserts some text? Could that space addition code be removed - and would it all then just work? (Apart from breaking people's muscle memory)

esm7 commented 2 years ago

It indeed adds a space after every text insertion; we could change that, but wouldn't that be spilling the baby with the bathwater? Especially on mobile, on which I think the ability to enter task details with almost no typing is a key functionality.

Giving it a thought overnight, I actually now think that lightly touching-up a note's tasks when the cursor moves away from its line, if it was added by completion, is very reasonable and doable. It should be configurable because I can also see the added value in this trailing space for some users, again, especially on mobile. We know a trailing space at the end of the line to be "wrong", but it allows jumping back and forth between lines and notes to add more details to tasks without extra key presses.

AnnaKornfeldSimpson commented 2 years ago

I agree with esm7 here: I like the feature of the added space after insertion, even on non-mobile, and would find the additional effort of adding multiple spaces during insertion significantly more than deleting the extra space at the end of the line (or running Linter).

if it was added by completion

Out of curiosity, @esm7 how would you detect that?

esm7 commented 2 years ago

I have some more thoughts about this; checking how other auto-complete GUIs work (e.g. Android swipe keyboards), there's also the option of internally marking the line as "space pending", and adding it only if the user continues typing or chooses another selection without moving the cursor. (Unless someone else picks it up first, I will work on this within a few weeks. I'm in a family vacation until the end of the month so unable to do much maintenance here.)

claremacrae commented 2 years ago

Hi @esm7,

Oooh, that's a nice idea.

Thank you for the offer. No hurry - have a nice holiday!