EditorEx (@Nullable Editor selectedEditor, @NotNull String fileName, @NotNull String templateText) { if (selectedEditor != null) { return (EditorEx)EditorFactory.getInstance().createEditor(selectedEditor.getDocument(), myProject); } final PsiFile file = createTempFile(myProject, fileName, templateText); assert file != null; myTempFiles.add(file); Document document = PsiDocumentManager.getInstance(myProject).getDocument(file); if (document == null) { document = EditorFactory.getInstance().createDocument(templateText); } VirtualFile virtualFile = file.getVirtualFile(); final EditorEx editor = (EditorEx)EditorFactory.getInstance().createEditor(document, myProject, virtualFile, false); editor.setFile(virtualFile); return editor; }