void () { Runnable restartTemplateRunnable = () -> { final TemplateState templateState = TemplateManagerImpl.getTemplateState(myEditor); if (templateState != null) { myEditor.putUserData(INTRODUCE_RESTART, true); try { SelectionModel selectionModel = myEditor.getSelectionModel(); if (selectionModel.hasSelection()) { mySelectedRange = myEditor.getDocument().createRangeMarker(selectionModel.getSelectionStart(), selectionModel.getSelectionEnd()); mySelectedRange.setGreedyToRight(true); mySelectedRange.setGreedyToLeft(true); } else { mySelectedRange = null; } final TextRange range = templateState.getCurrentVariableRange(); if (range != null) { final TextResult inputText = templateState.getVariableValue(PRIMARY_VARIABLE_NAME); final String inputName = inputText != null ? inputText.getText() : null; final V variable = getVariable(); if (inputName == null || variable == null || !isIdentifier(inputName, variable.getLanguage())) { final String[] names = suggestNames(isReplaceAllOccurrences(), getLocalVariable()); ApplicationManager.getApplication().runWriteAction(() -> myEditor.getDocument().replaceString(range.getStartOffset(), range.getEndOffset(), names[0])); } } templateState.gotoEnd(true); try { myShouldSelect = false; startInplaceIntroduceTemplate(); } finally { if (mySelectedRange != null) { mySelectedRange.dispose(); mySelectedRange = null; } myShouldSelect = true; } } finally { myEditor.putUserData(INTRODUCE_RESTART, false); } } updateTitle(getVariable()); }; CommandProcessor.getInstance().executeCommand(myProject, restartTemplateRunnable, getCommandName(), getCommandName()); }