/** * Sets the insert/replace state of the editor. */ private void setInsertEditorState(@NotNull Editor editor, boolean value) { final EditorEx editorEx = ObjectUtils.tryCast(editor, EditorEx.class); if (editorEx == null) return; editorEx.setInsertMode(value); }
/** * Processes the user pressing the Insert key while in INSERT or REPLACE mode. This simply toggles the * Insert/Overwrite state which updates the status bar. * * @param editor The editor to toggle the state in */ public void processInsert(Editor editor) { final EditorEx editorEx = ObjectUtils.tryCast(editor, EditorEx.class); if (editorEx == null) return; editorEx.setInsertMode(!editorEx.isInsertMode()); CommandState.getInstance(editor).toggleInsertOverwrite(); }
/** * Creates and configures template preview editor. * * @param document virtual editor document * @param project current project * @return editor */ @NotNull public static Editor createPreviewEditor(@NotNull Document document, @Nullable Project project, boolean isViewer) { EditorEx editor = (EditorEx) EditorFactory.getInstance().createEditor(document, project, IgnoreFileType.INSTANCE, isViewer); editor.setCaretEnabled(!isViewer); final EditorSettings settings = editor.getSettings(); settings.setLineNumbersShown(false); settings.setAdditionalColumnsCount(1); settings.setAdditionalLinesCount(0); settings.setRightMarginShown(false); settings.setFoldingOutlineShown(false); settings.setLineMarkerAreaShown(false); settings.setIndentGuidesShown(false); settings.setVirtualSpace(false); settings.setWheelFontChangeEnabled(false); EditorColorsScheme colorsScheme = editor.getColorsScheme(); colorsScheme.setColor(EditorColors.CARET_ROW_COLOR, null); return editor; }
final EditorHighlighter highlighter = ((EditorEx)editor).getHighlighter(); HighlighterIterator iterator = highlighter.createIterator(caret - 2); IElementType tokenType = iterator.getTokenType(); final EditorHighlighter highlighter = ((EditorEx)editor).getHighlighter(); HighlighterIterator iterator = highlighter.createIterator(caret - 1); IElementType tokenType = iterator.getTokenType(); final EditorHighlighter highlighter = ((EditorEx)editor).getHighlighter(); HighlighterIterator iterator = highlighter.createIterator(caret - 2); final EditorHighlighter highlighter = ((EditorEx)editor).getHighlighter(); HighlighterIterator iterator = highlighter.createIterator(caret - 1); IElementType tokenType = iterator.getTokenType(); final EditorHighlighter highlighter = ((EditorEx) editor).getHighlighter(); HighlighterIterator iterator = highlighter.createIterator(caret - 1); IElementType tokenType = iterator.getTokenType();
private void updatePreviewHighlighter(EditorEx editor) { EditorColorsScheme scheme = editor.getColorsScheme(); editor.getSettings().setCaretRowShown(false); EditorHighlighter highlighter = this.createHighlighter(scheme); if (highlighter != null) { editor.setHighlighter(highlighter); } }
public static RangeMarker createRangeMarker(EditorEx editor) { final int offset = editor.getCaretModel().getOffset(); return editor.getDocument().createRangeMarker(offset, offset); }
private void attachHighlighter(final EditorEx editor) { EditorColorsScheme scheme = editor.getColorsScheme(); scheme.setColor(EditorColors.CARET_ROW_COLOR, null); editor.setHighlighter(createHighlighter(scheme)); }
@Override public void fileClosed(@NotNull FileEditorManager fileEditorManager, @NotNull VirtualFile virtualFile) { FileEditor[] editors = fileEditorManager.getEditors(virtualFile); for (FileEditor editor : editors) { EditorEx editorEx = getEditorEx(editor); if (editorEx != null) { Map<Expression, RangeHighlighterEx> m = highlighters.remove(editorEx); if (m != null) { m.forEach((expression, highlighter) -> editorEx.getMarkupModel().removeHighlighter(highlighter) ); } } } }
private DocumentFragment createDocumentFragment(EditorEx editorEx, FoldRegion fold) { final FoldingGroup group = fold.getGroup(); final int foldStart = fold.getStartOffset(); if (group != null) { final int endOffset = ((FoldingModelImpl) editorEx.getFoldingModel()).getEndOffset(group); return new DocumentFragment(editorEx.getDocument(), foldStart, endOffset); } final int oldEnd = fold.getEndOffset(); return new DocumentFragment(editorEx.getDocument(), foldStart, oldEnd); }
public OptionSet() { EditorSettingsExternalizable editorSettingsExternalizable = EditorSettingsExternalizable.getInstance(); CARET_ROW_SHOWN = editorSettingsExternalizable.isCaretRowShown(); USE_SOFT_WRAP = editorSettingsExternalizable.isUseSoftWraps(); COLUMN_HIGHTLIGHTING = true; HIGHTLIGHT_TAB_SEPARATOR = true; SHOW_INFO_BALLOON = true; TAB_HIGHLIGHT_COLOR = "-7984"; EDITOR_PRIO = EditorPrio.TEXT_FIRST; SHOW_TABLE_EDITOR_INFO_PANEL = true; TABLE_EDITOR_ROW_HEIGHT = TABLE_EDITOR_DEFAULT_ROW_HEIGHT; QUOTING_ENFORCED = false; TABLE_COLUMN_HIGHTLIGHTING = true; ZERO_BASED_COLUMN_NUMBERING = false; } }
private void processEditors(FileEditor[] editors, PsiDocumentManager documentManager) { try { for (FileEditor editor : editors) { EditorEx editorEx = getEditorEx(editor); if (editorEx != null) { highlighters.putIfAbsent(editorEx, new HashMap<>()); for (FoldRegion region : editorEx.getFoldingModel().getAllFoldRegions()) { processRegion(region, documentManager, editorEx); } FoldingListener foldingListener = new FoldingListener() { @Override public void onFoldRegionStateChange(@NotNull FoldRegion region) { processRegion(region, documentManager, editorEx); } @Override public void onFoldProcessingEnd() { } }; editorEx.getFoldingModel().addListener(foldingListener, editor); } } } catch (IndexNotReadyException e) { // ignore } }
@Override public List<HighlightInfo> compute() { final Project project = psiFile.getProject(); final DaemonCodeAnalyzerEx analyzer = DaemonCodeAnalyzerEx.getInstanceEx(project); // ensure we get fresh results; the restart also seems to // prevent the "process canceled" issue (see #30) PsiDocumentManager.getInstance(project).commitAllDocuments(); analyzer.restart(psiFile); // analyze! return analyzer.runMainPasses( psiFile, editor.getDocument(), progress); } }, progress);
public void eraseHighlight(List<RangeHighlighter> list) { for (RangeHighlighter l : list) { this.markupModelEx.removeHighlighter(l); } }
@NotNull @Override public JComponent getPanel() { return myEditor.getComponent(); }
@NotNull private TextAttributes getHighlightedTextAttributes(@NotNull EditorEx editorEx) { TextAttributes foldedTextAttributes = editorEx.getColorsScheme() .getAttributes(EditorColors.FOLDED_TEXT_ATTRIBUTES); if (foldedTextAttributes.getBackgroundColor() != null) { foldedTextAttributes.setForegroundColor(null); } foldedTextAttributes.setFontType(Font.PLAIN); return foldedTextAttributes; }
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; } } }
@Override public void handleInsert(@NotNull InsertionContext context, LookupElement item) { Editor editor = context.getEditor(); CharSequence documentText = context.getDocument().getImmutableCharSequence(); int offset = skipWhiteSpaces(editor.getCaretModel().getOffset(), documentText); if (documentText.charAt(offset) != '{') { Project project = context.getProject(); Template template = TemplateManager.getInstance(project).createTemplate("braces", "go", myOneLine ? "{$END$}" : " {\n$END$\n}"); template.setToReformat(true); TemplateManager.getInstance(project).startTemplate(editor, template); } else { editor.getCaretModel().moveToOffset(offset); ApplicationManager.getApplication().runWriteAction(() -> { EditorActionHandler enterAction = EditorActionManager.getInstance().getActionHandler(IdeActions.ACTION_EDITOR_START_NEW_LINE); enterAction.execute(editor, editor.getCaretModel().getCurrentCaret(), ((EditorEx)editor).getDataContext()); }); } }
public void installListeners(Editor editor) { if (editor instanceof EditorEx) { // Avoid showing the default context menu ((EditorEx) editor).setContextMenuGroupId("AntlrContextMenu"); } editor.addEditorMouseMotionListener(editorMouseListener); editor.addEditorMouseListener(editorMouseListener); }
private boolean isLBraceTokenBrace() { int offset = myFixture.getCaretOffset(); Editor editor = myFixture.getEditor(); CharSequence text = editor.getDocument().getCharsSequence(); FileType fileType = ElixirFileType.INSTANCE; HighlighterIterator iterator = ((EditorEx) editor).getHighlighter().createIterator(offset); return BraceMatchingUtil.isLBraceToken(iterator, text, fileType); } }
private void setCursors(boolean isBlock) { Editor[] editors = EditorFactory.getInstance().getAllEditors(); for (Editor editor : editors) { // Vim plugin should be turned on in insert mode ((EditorEx)editor).setInsertMode(true); editor.getSettings().setBlockCursor(isBlock); } }