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

Apply template to an existing file #850

Open
avados opened this issue Nov 30, 2021 · 8 comments
Open

Apply template to an existing file #850

avados opened this issue Nov 30, 2021 · 8 comments
Labels
foam-vscode Foam for VSCode extension in packages/foam-vscode help wanted Extra attention is needed
Milestone

Comments

@avados
Copy link

avados commented Nov 30, 2021

Hi, i am migrating form obsidian to foam, and i feature i am missing is to be able to change a file using a template.

Examples: i am taking quick notes and i would like to apply a "meeting template" format later on.

basically it would be adding the template at the top of the file, so we don't have to create a new file from template and copy paste everything in it.

Thanks.

@riccardoferretti
Copy link
Collaborator

I like the idea, and we could even use Foam mechanics to implement it in the following way:

  1. We could add a Apply template to current note
  2. The existing text of the note is populated as the ${FOAM_SELECTED_TEXT} property.
    In most templates, which don't use this property, the default behavior is to append its contents at the end of the template (mimicking what Obsidian does). But additionally one could have control over the location of the existing text by using a template that uses the variable explicitly.

@riccardoferretti riccardoferretti added foam-vscode Foam for VSCode extension in packages/foam-vscode help wanted Extra attention is needed labels Nov 30, 2021
@riccardoferretti
Copy link
Collaborator

(cc @movermeyer as he is our template expert)

@avados
Copy link
Author

avados commented Dec 1, 2021

Thanks @riccardoferretti you got the idea :)

@riccardoferretti riccardoferretti added this to the backlog milestone Dec 2, 2021
@movermeyer
Copy link
Collaborator

I like the idea.


@riccardoferretti If you use ${FOAM_SELECTED_TEXT}, you end up with a collision if the user had already selecting some text. So I'm not sure that we'd want to use the same variable. We could create a new one for this? #{FOAM_FILE_CONTENTS} or something.

Then yeah, implicitly append #{FOAM_FILE_CONTENTS} to the end of any template that doesn't explicitly mention it.

@riccardoferretti
Copy link
Collaborator

My mental model for Foam: Apply template to current note is basically "select the whole note, and apply the template to it", so in my mind I see quite literally the file content as being the selected text.

I am trying to map the scenarios where having both variables might be helpful, but I am finding it hard to think of one (except for serious hardcore-master-of-vim-like scenario).
That's why my 80/20/KISS approach (and the mental model above) makes favor using the FOAM_SELECTED_TEXT variable.

But I might be missing something, happy to hear other POVs.

@movermeyer
Copy link
Collaborator

@riccardoferretti That's very reasonable.

I agree that ideally we wouldn't bother with creating a new variable for this, and I agree that the use case for using both is a "serious hardcore-master-of-vim" use case that's not really worth worrying about / supporting.

That said, I mentioned it since its a bit of an abuse of the definition of FOAM_SELECTED_TEXT, so I was wondering if there was a reasonable way we could avoid this slight corruption.

Perhaps the command could literally select all text in the editor before creating the new note, so the user gets a very brief visual cue as to what happened.

@riccardoferretti
Copy link
Collaborator

Perhaps the command could literally select all text in the editor before creating the new note, so the user gets a very brief visual cue as to what happened.

I take from this that my mental model might not be clear to a user, fair point 😅

The approach of the brief selection for visual cue to the user could be interesting, definitely worth exploring.
We would also integrate the documentation (and possibly the text used in Foam: Create New Template) to make the user aware of the behavior.

@avados
Copy link
Author

avados commented Dec 3, 2021

What is happening to the text not selected?
For example, how would you handle the case:
I have a bunch of text selected in a middle of a paragraph and i apply the template, what happens to the non selected text? does it stays where it is and the template is added in place of the selected text?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
foam-vscode Foam for VSCode extension in packages/foam-vscode help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants