Editor (@NotNull Project project, @NotNull PsiFile targetFile, @NotNull PsiElement element) { TextRange range = element.getTextRange(); LOG.assertTrue(range != null, element.getClass()); int textOffset = range.getStartOffset(); if (IntentionPreviewUtils.isPreviewElement(targetFile)) { Editor editor = IntentionPreviewUtils.getPreviewEditor(); if (editor != null) { editor.getCaretModel().moveToOffset(textOffset); } return editor; } VirtualFile file = targetFile.getVirtualFile(); if (file == null) { file = PsiUtilCore.getVirtualFile(element); if (file == null) return null; } OpenFileDescriptor descriptor = new OpenFileDescriptor(project, file, textOffset); descriptor.setScrollType(ScrollType.MAKE_VISIBLE); // avoid centering caret in editor if it's already visible return FileEditorManager.getInstance(project).openTextEditor(descriptor, true); }