Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create New Note Skips Asking Filename #640

Closed
smithalexk opened this issue May 17, 2021 · 3 comments · Fixed by #645
Closed

Create New Note Skips Asking Filename #640

smithalexk opened this issue May 17, 2021 · 3 comments · Fixed by #645
Labels
bug Something isn't working

Comments

@smithalexk
Copy link

  • Foam version: 0.13.3
  • Platform: Mac
  • Issue occur on the foam template repo: Yes

Summary
When I use the Foam: Create New Note command with a .foam/templates/new-note.md template present, I am not given an option for a name. Instead, it creates a note in the current directory called "New Note.md" using the new-note.md template.

This seems to be a bug when reading: https://github.com/movermeyer/foam/blob/mo.template_v2_proposal/docs/proposals/templates-v2.md#case-2-foamtemplatesnew-notemd-exists

Steps to reproduce

  1. Generate new foam workspace
  2. Create a new-note.md in .foam/templates (can be done by renaming the "your-first-template.md" file)
  3. Run the Foam: Create New Note command
@smithalexk smithalexk added the bug Something isn't working label May 17, 2021
@riccardoferretti
Copy link
Collaborator

cc @movermeyer as he is the best person to address the comment

@movermeyer
Copy link
Collaborator

Summary

Thanks @smithalexk for raising this issue. It is certainly not a great user experience. I've opened a PR to improve it.

The technical details

This is happening since the new-note.md template does not contain a reference to $FOAM_TITLE.

This behaviour of not asking for the title unless the template asks for it was intentional, as in the future we want things like Foam: Open Daily Note to use this same code to create a new note from template without prompting the user.

This decision lead to this confusing UX.

"Working as expected...incorrectly"

It's important to note that our imagined future of Foam: Open Daily Note uses the proposed metadata syntax to create a sensible filepath without requiring the user to enter a title:

(Disclaimer: proposed syntax below. Not official/formalized. May still change)

---
filepath: '${CURRENT_YEAR}-${CURRENT_MONTH}-${CURRENT_DATE}.md'
---

# ${CURRENT_YEAR}-${CURRENT_MONTH}-${CURRENT_DATE}

In this case, the template provides everything you need in order to create the note (filepath + file contents) without referencing $FOAM_TITLE, so there is no need to prompt the user.

In the code, this was implemented as "if the template doesn't mention $FOAM_TITLE, then there's nothing to prompt the user for".
However, the case presented in this PR shows that's not quite correct. Unlike the daily notes example, an empty template file provides the file contents, but not the filepath.
This is the crucial difference.

A solution?

In order to create a note from a template you need two things:

  1. the filepath
  2. the file contents.

In cases where the template doesn't explicitly specify the path using the metadata syntax (i.e. all current templates since the metadata syntax isn't implemented yet), we'll add $FOAM_TITLE to the list of variables to resolve, and use it as the filepath.

This will prompt the user for a title as they (reasonably) expect it to.

Then in the future when the template metadata block contains an explicit override of the filepath, we will stop adding $FOAM_TITLE, and whether or not the user gets prompted will depend on the contents of the filepath metadata.

@smithalexk
Copy link
Author

Great thanks @movermeyer, I appreciate the quick response!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants