Editor (@NotNull PsiFile file, @NotNull Project project) { Document document = PsiDocumentManager.getInstance(project).getDocument(file); // may return editor injected in current selection in the host editor, not for the file passed as argument VirtualFile virtualFile = file.getVirtualFile(); if (virtualFile == null) { return null; } if (virtualFile instanceof VirtualFileWindow) { virtualFile = ((VirtualFileWindow)virtualFile).getDelegate(); } Editor editor = FileEditorManager.getInstance(project).openTextEditor(new OpenFileDescriptor(project, virtualFile, -1), false); if (editor == null || editor instanceof EditorWindow || editor.isDisposed()) return editor; if (document instanceof DocumentWindowImpl) { InjectedEditorWindowTrackerImpl tracker = (InjectedEditorWindowTrackerImpl)ApplicationManager.getApplication().getService(InjectedEditorWindowTracker.class); return tracker.createEditor((DocumentWindowImpl)document, (EditorImpl)editor, file); } return editor; }