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

can a template action be based on the "current selection" in the editor? #44

Closed
luckman212 opened this issue Jan 16, 2021 · 4 comments
Closed
Assignees
Labels
question Further information is requested

Comments

@luckman212
Copy link

Not sure if I am even asking this in the right way, but here's my use case:

I'd like to create a template that uses the current selected word or phrase as a parameter for the template. One example could be a "turn selection into linked Google search":

  1. hightlight a word e.g. "Zettel"
  2. activate Templater, with template containing something like:
[{{tp_selection}}](https://www.google.com/search?q={{tp_selection:urlencoded=true}})
  1. have that selection replaced with [Zettel](https://www.google.com/search?q=Zettel)

Is this possible today or somehow in the future?

@luckman212 luckman212 added the question Further information is requested label Jan 16, 2021
@luckman212 luckman212 changed the title can a template action based on the "current selection" in the editor? can a template action be based on the "current selection" in the editor? Jan 16, 2021
@luckman212
Copy link
Author

luckman212 commented Jan 16, 2021

current poor man's hack is to copy the word to the clipboard first and then use this as the template src:

w=$(pbpaste)
q=$(python3 -c 'import sys; from urllib.parse import quote; print(quote(sys.argv[1]));' "$w")
echo "[$w](https://www.google.com/search?q=$q)"

@luckman212
Copy link
Author

Seems operating on the current selection is indeed possible, see https://github.com/lukeleppan/better-word-count/blob/master/src/main.ts#L33 for an example

@SilentVoid13
Copy link
Owner

Hello @luckman212, that's a good internal template idea !
I'll probably add this one in the next release, thanks for the suggestion.

@SilentVoid13
Copy link
Owner

SilentVoid13 commented Apr 6, 2021

Hey @luckman212, sorry for the late response, this has been implemented as of Templater 1.0.0!
If you update, you will now be able to use <% tp.file.selection() %> to access your current selection.
Tell me if this works for you.
Closing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants