foam icon indicating copy to clipboard operation
foam copied to clipboard

Clicking the placeholder tooltip asks for template for new note

Open Dominic-DallOsto opened this issue 2 years ago • 3 comments

Fixes #995

Happy to work on this once we decide the best way of going about it.

At the moment this is just a minimal example with a lot of copy-pasting from create-note-from-template.ts (should the template selection logic be migrated to templates.ts, since at least some is already duplicated, and now a lot more?).

Current behaviour

  • clicking the placeholder tooltip text - you are asked which template you want to use, then the note is created
  • Holding Ctrl and hovering over the placeholder - the new note is already created with the default template before clicking. This seems undesirable?

For me at least, the majority of new notes I create are using a template so some option that makes this quickly accessible would be great. I think Ctrl+Alt+Click would be a bit painful in this respect?

Dominic-DallOsto avatar Aug 28 '22 14:08 Dominic-DallOsto

Thanks for looking into this @Dominic-DallOsto I like the idea of optionally providing the user with the choice of template to use for a placeholder. Currently the new-note.md template would be used, I think that is fine as a default behavior.

clicking the placeholder tooltip text - you are asked which template you want to use, then the note is created

Simply clicking I reckon should just use the new-note.md template, which is the current behavior

Holding Ctrl and hovering over the placeholder - the new note is already created with the default template before clicking. This seems undesirabled?

I wonder if more than ctrl/cmd we should use alt/option? Regardless of the modifier, this is the place where I would give the user the option to select the template to use

Thoughts?

riccardoferretti avatar Sep 01 '22 10:09 riccardoferretti

I think a nice workflow would be something like this

  • clicking the link (while holding Ctrl) creates a new note with the default template (works* at the moment)
  • there's a tooltip when hovering over the link - something like "create new note" (works at the moment)
  • there's a second tooltip when hovering over the link - something like "create new note with custom template" (new to add)

I don't think we can use Alt as a click modifier? At least for me it's used to place multiple cursors

Essentially, this would boil down to adding a Hover provider to placeholder wikilinks for the "create new note with custom template". We could also add a setting to specify the default template, or continue to use the existing default. Additionally, the fact that just hovering over the placeholder link and holding Ctrl already creates a new note doesn't seem like desired behaviour. Is this because of a Go To Definition provider?

Does that make sense?

Dominic-DallOsto avatar Sep 02 '22 09:09 Dominic-DallOsto

there's a second tooltip when hovering over the link - something like "create new note with custom template" (new to add)

To me is a trade-off of clarity vs clutter, and I believe in this specific case it can make sense to add it - but I'd have to see it in action to give e final answer to that

I don't think we can use Alt as a click modifier? At least for me it's used to place multiple cursors

Haven't tried this, for me as long as we have a modifier I think it's fine, it just needs to be in line with the existing UX of VS Code 👍

Essentially, this would boil down to adding a Hover provider to placeholder wikilinks for the "create new note with custom template"

Interesting approach, I like it. Important I think is that the hover doesn't interfere with the "Also referenced in ..." content, nor the link hover (which it wouldn't). So basically the only way to create using a template would be by clicking on this hover. (if we implement that as a command I guess it could also be triggered by a keyboard shortcut)

We could also add a setting to specify the default template, or continue to use the existing default

I am happy to simply use the default new-note.md template. In the future we might add a new-note-from-placeholder.md template if we think further customization is necessary.

the fact that just hovering over the placeholder link and holding Ctrl already creates a new note doesn't seem like desired behaviour. Is this because of a Go To Definition provider?

This should not happen in Foam, are you sure you are not also using Markdown Notes? I have seen people report similar issues with that extension

riccardoferretti avatar Sep 05 '22 10:09 riccardoferretti

Yep, Markdown Notes was causing that issue for me. Now things work.

image

What do you think?

I think the implementation could be refactored - I'm not sure the best place to modify the logic. At the moment I modified the open-resource command by introducing an extra parameter, but not sure this is the best way / might cause a problem if the command isn't built with OPEN_COMMAND.asURI?

Dominic-DallOsto avatar Sep 21 '22 21:09 Dominic-DallOsto

I updated the hover provider tests - hopefully that works now. Maybe the one testing this functionality specifically will need to be updated still.

Dominic-DallOsto avatar Sep 28 '22 08:09 Dominic-DallOsto

FYI #1076

riccardoferretti avatar Sep 29 '22 19:09 riccardoferretti

The PR has been merged, thanks for the wait! The work there should make yours much simpler here (forgive the conflict), let me know if the API works well for you

riccardoferretti avatar Sep 30 '22 17:09 riccardoferretti

I rebased to master and updated the code.

I'm not sure if I'm missing something, but I can't get the new command to fit the workflow. The hover text needs to include a link to a command that will ask for the template, then create a note using it. But the new create-note function needs me to already provide the template. If I ask the user for the template when creating the link, the template pop up appears when hovering over the placeholder link (which makes sense, but isn't what we want).

Ideally what I need is a function like "ask user for template then create note", or some way to achieve that which currently is through hacking open-resource.ts and templates.ts.

Or am I missing a simple way of wrapping create-note to do what I want?

Dominic-DallOsto avatar Oct 04 '22 22:10 Dominic-DallOsto

Ok, it works now. I edited the parameters for CREATE_NOTE though. If you prefer, I can move it to asUri. Or fold it into templatePath like you say.

Dominic-DallOsto avatar Oct 05 '22 22:10 Dominic-DallOsto

Ok, sorry for the delay. Tests are passing now on my end at least

Dominic-DallOsto avatar Oct 12 '22 08:10 Dominic-DallOsto

@allcontributors add @Dominic-DallOsto for code

riccardoferretti avatar Oct 12 '22 15:10 riccardoferretti

Amazing, thx!

riccardoferretti avatar Oct 12 '22 15:10 riccardoferretti

@riccardoferretti

I've put up a pull request to add @Dominic-DallOsto! :tada:

allcontributors[bot] avatar Oct 12 '22 15:10 allcontributors[bot]