3

I have figured out that I can use $SELECTION$ as a parameter to live template functions inside the "EDIT VARIABLES" modal. However, it will only work if I invoke it the "Surround with Live Template" hotkey. However, only templates which have $SELECTION$ written in the "Template Text" area will appear as an option for "Surround with Live Template". If $SELECTION$ appears in the "EDIT VARIABLES" modal, but not in the "Template Text" area, then the template will not appear in "Surround with Live Template".

The problem with this is that I don't want to use the raw value of $SELECTION$ in the "Template Text" area.

How can I make the template appear in "Surround with Live Template" without $SELECTION$ being in the "Template Text" area, yet being in the "EDIT VARIABLES" modal?

The reason I want to do this is that I want to run a regularExpression() on the $SELECTION$ and output the resultant string to the template body.

The following picture show my current work around. It allows me to invoke the template as a surround template, and it places the $END$ cursor just before $SELECTION$. This makes it easy to select the $SELECTION$ after invoking the template so that it can be deleted manually. enter image description here

This document is not revealing pertaining to this issue. https://www.jetbrains.com/help/webstorm/template-variables.html

Croolsby
  • 1,416
  • 1
  • 14
  • 14
  • 2
    `$SELECTION$` has to be in a template body to be considered as "Surround" kind. Tha's the whole idea: to surround selected text with some other stuff. If you need to use some selected text as a parameter, consider copying it into clipboard and use appropriate function when assigning it to other variable. – LazyOne Apr 02 '19 at 18:13
  • @LazyOne Thank you. Your suggested work around is good. – Croolsby Apr 02 '19 at 21:01

1 Answers1

1

This was a bug. Currently, Live Templates containing a reference to the SELECTION variable inside another template variable expression are correctly recognized as a Surround template. This was fixed at the end of 2019, see https://youtrack.jetbrains.com/issue/IDEA-225455.

Bas Leijdekkers
  • 23,709
  • 4
  • 70
  • 68