I have this file template in WebStorm 2018.2:
#set($TestSuiteName = ${StringUtils.removeAndHump(${NAME}, "-")})
describe("#[[$TestSuiteName$]]#", () => {
it("should work", () =>
{
#[[$END$]]#
});
});
The important point of this question is the #[[$TestSuiteName$]]#
part of the template. What I want to achieve is, that $TestSuiteName
is replaced by the value calculated in the first template line and is selected for editing but can be accepted by pressing return.
All the template does right now is to print out "TestSuiteName" for the #[[$TestSuiteName$]]#
expression, which is not what I want. What it does right is to select the text "TestSuiteName" which it takes when I press return.
When I change the template to
#set($TestSuiteName = ${StringUtils.removeAndHump(${NAME}, "-")})
describe("$TestSuiteName", () => {
it("should work", () =>
{
#[[$END$]]#
});
});
then the filename is correctly camel-humped but it is not selected and the cursor jumps immediatly to the #[[$END$]]#
location.
What would be the correct way of getting the camel-humped filename selected for editing?
There is no way to do this currently:(
$VAR$
syntax has a special meaning in Webstorm templates - it's a kind of live template variable, a placeholder that allows placing cursor at certain position and editing a value when applying the template. To make such placeholders work, #[[$VAR$]]#
syntax is used to avoid conflicts with velocity variables (text in #[[]]#
is rendered as is - see http://velocity.apache.org/engine/1.7/user-guide.html#literals). That's why you get variable name instead of camel-humped file name when using #[[$TestSuiteName$]]#
.
We plan to provide a possibility to use the full power of live templates (live template functions, predefined variables, default values, etc.) in file templates. If you miss it, please vote for IDEA-161937, IDEA-173721 and linked tickets