How do I create a live template with an expression using another variable?

2.8k Views Asked by At

In Intellij IDEA 15.0.3 (build #IU-143.1821) I'm trying to create a live template which will let me input a JavaScript function name (in camelCase), and create a constant (IN_UPPER_CASE).

For example, when I'm typing the template abbreviation, and then sendUserNameAndPassword, the template should expand to

export const SEND_USERNAME_AND_PASSWORD = 'SEND_USERNAME_AND_PASSWORD';

export function sendUserNameAndPassword() {

}

I have created this template:

export const $CONSTANT_NAME$ = '$CONSTANT_NAME$';

export function $FUNCTION_NAME$() {
   $END$
}

and within the Edit variables dialog, I have the following variables:

Name          | Expression                      | Default value | Skip if defined
FUNCTION_NAME |                                 |               |
CONSTANT_NAME | capitalizeAndUnderscore(String) |               |        x 

Clearly, I would like to have the Expression to be capitalizeAndUnderscore(FUNCTION_NAME) and not capitalizeAndUnderscore(String), but when I replace String with anything else, the expression is reset to capitalizeAndUnderscore(String) as soon as I move to another field in the dialog.

What am I missing here?

1

There are 1 best solutions below

1
On BEST ANSWER

This seems to be a confirmed bug in Intellij IDEA: https://youtrack.jetbrains.com/issue/IDEA-132965

The current workaround is, in short: After editing an expression, do not move to another field or press Return, instead; click directly on the OK button. This will save your edit.
You will then have to reopen the Edit variables dialog to do more edits.