void (final PatternDescriptor descriptor) { WriteCommandAction.writeCommandAction(myProject).run(() -> { final Template template = descriptor.getTemplate(); if (template instanceof TemplateImpl) { String text = template.getString(); myEditor.getDocument().replaceString(0, myEditor.getDocument().getTextLength(), text); TemplateEditorUtil.setHighlighter(myEditor, ((TemplateImpl)template).getTemplateContext()); } else { myEditor.getDocument().replaceString(0, myEditor.getDocument().getTextLength(), ""); } }); }