boolean (@NotNull ActionContext context, @NotNull ModStartTemplate template, @Nullable Editor editor) { VirtualFile file = actualize(template.file()); if (file == null) return false; Editor finalEditor = getEditor(context.project(), editor, file); if (finalEditor == null) return false; PsiFile psiFile = PsiManagerEx.getInstanceEx(context.project()).findFile(file); if (psiFile == null) return false; String name = requireNonNullElse(CommandProcessor.getInstance().getCurrentCommandName(), LangBundle.message("command.title.finishing.template")); WriteAction.run(() -> { TemplateBuilderImpl builder = new TemplateBuilderImpl(psiFile); for (ModStartTemplate.TemplateField field : template.fields()) { if (field instanceof ModStartTemplate.ExpressionField expr) { builder.replaceElement(psiFile, expr.range(), expr.expression()); } else if (field instanceof ModStartTemplate.DependantVariableField variableField) { builder.replaceElement(psiFile, variableField.range(), variableField.varName(), variableField.dependantVariableName(), variableField.alwaysStopAt()); } } final Template tmpl = builder.buildInlineTemplate(); finalEditor.getCaretModel().moveToOffset(0); TemplateManager.getInstance(context.project()).startTemplate(finalEditor, tmpl, new TemplateEditingAdapter() { @Override public void templateFinished(@NotNull Template tmpl, boolean brokenOff) { ModCommand next = ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> { return ReadAction.nonBlocking(() -> template.templateFinishFunction().apply(psiFile)).executeSynchronously(); }, name, true, context.project()); CommandProcessor.getInstance().executeCommand(context.project(), () -> executeInteractively(context, next, editor), name, null); } }); }); return true; }