@Nullable private Editor getAnEditor(@NotNull Document doc) { Editor[] editors = EditorFactory.getInstance().getEditors(doc); if (editors.length > 0) { return editors[0]; } else { return null; } } }
/** * Gets the editor for the virtual file within the editor manager. * * @param manager The file editor manager * @param file The virtual file get the editor for * @return The matching editor or null if no match was found */ @Nullable public static Editor getEditor(@NotNull final FileEditorManager manager, @Nullable final VirtualFile file) { if (file == null) { return null; } final Document doc = FileDocumentManager.getInstance().getDocument(file); if (doc == null) { return null; } final Editor[] editors = EditorFactory.getInstance().getEditors(doc, manager.getProject()); if (editors.length > 0) { return editors[0]; } return null; }
private static void resetCursor(@NotNull VirtualFile virtualFile, Project proj, boolean insert) { logger.debug("resetCursor"); Document doc = FileDocumentManager.getInstance().getDocument(virtualFile); if (doc == null) return; // Must be no text editor (such as image) Editor[] editors = EditorFactory.getInstance().getEditors(doc, proj); if (logger.isDebugEnabled()) { logger.debug("There are " + editors.length + " editors for virtual file " + virtualFile.getName()); } for (Editor editor : editors) { editor.getSettings().setBlockCursor(!insert); } }
public void selectionChanged(@NotNull SelectionEvent selectionEvent) { final Editor editor = selectionEvent.getEditor(); final Document document = editor.getDocument(); if (myMakingChanges || (document instanceof DocumentEx && ((DocumentEx) document).isInEventsHandling())) { return; } myMakingChanges = true; try { final com.intellij.openapi.util.TextRange newRange = selectionEvent.getNewRange(); for (Editor e : EditorFactory.getInstance().getEditors(document)) { if (!e.equals(editor)) { e.getSelectionModel().setSelection(newRange.getStartOffset(), newRange.getEndOffset()); } } } finally { myMakingChanges = false; } } }
Editor[] editors = EditorFactory.getInstance().getEditors(document); if (editors.length > 0) { VisualPosition position = editors[0].getSelectionModel().getSelectionStartPosition();
Editor[] editors = EditorFactory.getInstance().getEditors(event.getDocument(), proj); for (Editor editor : editors) { Collection hls = EditorData.getLastHighlights(editor);
private void highlightSearch(final boolean noSmartCase) { Project[] projects = ProjectManager.getInstance().getOpenProjects(); for (Project project : projects) { Editor current = FileEditorManager.getInstance(project).getSelectedTextEditor(); Editor[] editors = current == null ? null : EditorFactory.getInstance().getEditors(current.getDocument(), project); if (editors == null) { continue; } for (final Editor editor : editors) { String els = EditorData.getLastSearch(editor); if (!showSearchHighlight) { removeSearchHighlight(editor); continue; } else if (lastSearch != null && lastSearch.equals(els)) { continue; } else if (lastSearch == null) { continue; } removeSearchHighlight(editor); highlightSearchLines(editor, lastSearch, 0, -1, shouldIgnoreCase(lastSearch, noSmartCase)); EditorData.setLastSearch(editor, lastSearch); } } }
/** * Handles an action of adding new template. * Ignores action if selected file is not a {@link IgnoreFile} instance, otherwise shows GeneratorDialog. * * @param e action event */ @Override public void actionPerformed(@NotNull AnActionEvent e) { final Project project = e.getData(CommonDataKeys.PROJECT); final PsiFile file = e.getData(CommonDataKeys.PSI_FILE); if (project == null || !(file instanceof IgnoreFile)) { return; } String content = file.getText(); Document document = file.getViewProvider().getDocument(); if (document != null) { Editor[] editors = EditorFactory.getInstance().getEditors(document); if (editors.length > 0) { String selectedText = editors[0].getSelectionModel().getSelectedText(); if (!StringUtil.isEmpty(selectedText)) { content = selectedText; } } } new UserTemplateDialog(project, content).show(); }
@NotNull public static List<Editor> findEditorsFrom(@NotNull Document document) { return Lists.newArrayList(EditorFactory.getInstance().getEditors(document)); }
public Editor getEditor(VirtualFile vfile) { final FileDocumentManager fdm = FileDocumentManager.getInstance(); final Document doc = fdm.getDocument(vfile); if (doc == null) return null; EditorFactory factory = EditorFactory.getInstance(); final Editor[] editors = factory.getEditors(doc, previewPanel.project); if ( editors.length==0 ) { // no editor found for this file. likely an out-of-sequence issue // where Intellij is opening a project and doesn't fire events // in order we'd expect. return null; } return editors[0]; // hope just one }
currentHighlightedDoc = rangeMarker.getDocument(); Editor[] editors = EditorFactory.getInstance().getEditors(rangeMarker.getDocument(), project); List<Segment> segments = Stream.concat(flows.stream() .flatMap(f -> f.locations().stream()
@Override public void documentChanged(DocumentEvent event) { Document document = event.getDocument(); Editor[] editors = editorFactory.getEditors(document); for (Editor editor : editors) { Project project = editor.getProject(); if (project == null) { return; } PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(document); syncedElementHighlighter.highlightStatement(editor, psiFile); } } }