com.intellij.openapi.editor.markup.MarkupModel Java Examples
The following examples show how to use
com.intellij.openapi.editor.markup.MarkupModel.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SyntaxInfoBuilder.java From consulo with Apache License 2.0 | 6 votes |
private MarkupModelRangeIterator(@Nullable MarkupModel markupModel, @Nonnull EditorColorsScheme colorsScheme, int startOffset, int endOffset) { myStartOffset = startOffset; myEndOffset = endOffset; myColorsScheme = colorsScheme; myDefaultForeground = colorsScheme.getDefaultForeground(); myDefaultBackground = colorsScheme.getDefaultBackground(); myUnsupportedModel = !(markupModel instanceof MarkupModelEx); if (myUnsupportedModel) { myIterator = null; return; } myIterator = ((MarkupModelEx)markupModel).overlappingIterator(startOffset, endOffset); try { findNextSuitableRange(); } catch (RuntimeException | Error e) { myIterator.dispose(); throw e; } }
Example #2
Source File: NavigationUtil.java From consulo with Apache License 2.0 | 6 votes |
/** * Patches attributes to be visible under debugger active line */ @SuppressWarnings("UseJBColor") public static TextAttributes patchAttributesColor(TextAttributes attributes, @Nonnull TextRange range, @Nonnull Editor editor) { if (attributes.getForegroundColor() == null && attributes.getEffectColor() == null) return attributes; MarkupModel model = DocumentMarkupModel.forDocument(editor.getDocument(), editor.getProject(), false); if (model != null) { if (!((MarkupModelEx)model).processRangeHighlightersOverlappingWith(range.getStartOffset(), range.getEndOffset(), highlighter -> { if (highlighter.isValid() && highlighter.getTargetArea() == HighlighterTargetArea.LINES_IN_RANGE) { TextAttributes textAttributes = highlighter.getTextAttributes(); if (textAttributes != null) { Color color = textAttributes.getBackgroundColor(); return !(color != null && color.getBlue() > 128 && color.getRed() < 128 && color.getGreen() < 128); } } return true; })) { TextAttributes clone = attributes.clone(); clone.setForegroundColor(Color.orange); clone.setEffectColor(Color.orange); return clone; } } return attributes; }
Example #3
Source File: UnifiedEditorRangeHighlighter.java From consulo with Apache License 2.0 | 6 votes |
public void apply(@javax.annotation.Nullable Project project, @Nonnull Document document) { MarkupModel model = DocumentMarkupModel.forDocument(document, project, true); for (Element piece : myPieces) { RangeHighlighterEx delegate = piece.getDelegate(); if (!delegate.isValid()) continue; RangeHighlighter highlighter = model .addRangeHighlighter(piece.getStart(), piece.getEnd(), delegate.getLayer(), delegate.getTextAttributes(), delegate.getTargetArea()); highlighter.setEditorFilter(delegate.getEditorFilter()); highlighter.setCustomRenderer(delegate.getCustomRenderer()); highlighter.setErrorStripeMarkColor(delegate.getErrorStripeMarkColor()); highlighter.setErrorStripeTooltip(delegate.getErrorStripeTooltip()); highlighter.setGutterIconRenderer(delegate.getGutterIconRenderer()); highlighter.setLineMarkerRenderer(delegate.getLineMarkerRenderer()); highlighter.setLineSeparatorColor(delegate.getLineSeparatorColor()); highlighter.setThinErrorStripeMark(delegate.isThinErrorStripeMark()); highlighter.setLineSeparatorPlacement(delegate.getLineSeparatorPlacement()); highlighter.setLineSeparatorRenderer(delegate.getLineSeparatorRenderer()); } }
Example #4
Source File: FocusModeModel.java From consulo with Apache License 2.0 | 6 votes |
private void applyFocusMode(@Nonnull Segment focusRange) { EditorColorsScheme scheme = ObjectUtils.notNull(myEditor.getColorsScheme(), EditorColorsManager.getInstance().getGlobalScheme()); Color background = scheme.getDefaultBackground(); //noinspection UseJBColor Color foreground = Registry.getColor(ColorUtil.isDark(background) ? "editor.focus.mode.color.dark" : "editor.focus.mode.color.light", Color.GRAY); TextAttributes attributes = new TextAttributes(foreground, background, background, LINE_UNDERSCORE, Font.PLAIN); myEditor.putUserData(FOCUS_MODE_ATTRIBUTES, attributes); MarkupModel markupModel = myEditor.getMarkupModel(); DocumentEx document = myEditor.getDocument(); int textLength = document.getTextLength(); int start = focusRange.getStartOffset(); int end = focusRange.getEndOffset(); if (start <= textLength) myFocusModeMarkup.add(markupModel.addRangeHighlighter(0, start, LAYER, attributes, EXACT_RANGE)); if (end <= textLength) myFocusModeMarkup.add(markupModel.addRangeHighlighter(end, textLength, LAYER, attributes, EXACT_RANGE)); myFocusModeRange = document.createRangeMarker(start, end); }
Example #5
Source File: FilteredIndentsHighlightingPass.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 5 votes |
@NotNull private static RangeHighlighter createHighlighter(MarkupModel mm, TextRange range) { final RangeHighlighter highlighter = mm.addRangeHighlighter(range.getStartOffset(), range.getEndOffset(), 0, null, HighlighterTargetArea.EXACT_RANGE); highlighter.setCustomRenderer(RENDERER); return highlighter; }
Example #6
Source File: SyntaxInfoBuilder.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull static MyMarkupIterator createMarkupIterator(@Nonnull EditorHighlighter highlighter, @Nonnull CharSequence text, @Nonnull EditorColorsScheme schemeToUse, @Nonnull MarkupModel markupModel, int startOffsetToUse, int endOffset) { CompositeRangeIterator iterator = new CompositeRangeIterator(schemeToUse, new HighlighterRangeIterator(highlighter, startOffsetToUse, endOffset), new MarkupModelRangeIterator(markupModel, schemeToUse, startOffsetToUse, endOffset)); return new MyMarkupIterator(text, iterator, schemeToUse); }
Example #7
Source File: DefaultHighlightInfoProcessor.java From consulo with Apache License 2.0 | 5 votes |
@Override public void highlightsInsideVisiblePartAreProduced(@Nonnull final HighlightingSession session, @Nullable Editor editor, @Nonnull final List<? extends HighlightInfo> infos, @Nonnull TextRange priorityRange, @Nonnull TextRange restrictRange, final int groupId) { final PsiFile psiFile = session.getPsiFile(); final Project project = psiFile.getProject(); final Document document = PsiDocumentManager.getInstance(project).getDocument(psiFile); if (document == null) return; final long modificationStamp = document.getModificationStamp(); final TextRange priorityIntersection = priorityRange.intersection(restrictRange); List<? extends HighlightInfo> infoCopy = new ArrayList<>(infos); ((HighlightingSessionImpl)session).applyInEDT(() -> { if (modificationStamp != document.getModificationStamp()) return; if (priorityIntersection != null) { MarkupModel markupModel = DocumentMarkupModel.forDocument(document, project, true); EditorColorsScheme scheme = session.getColorsScheme(); UpdateHighlightersUtil.setHighlightersInRange(project, document, priorityIntersection, scheme, infoCopy, (MarkupModelEx)markupModel, groupId); } if (editor != null && !editor.isDisposed()) { // usability: show auto import popup as soon as possible if (!DumbService.isDumb(project)) { ShowAutoImportPassFactory siFactory = TextEditorHighlightingPassFactory.EP_NAME.findExtensionOrFail(project, ShowAutoImportPassFactory.class); TextEditorHighlightingPass highlightingPass = siFactory.createHighlightingPass(psiFile, editor); if (highlightingPass != null) { highlightingPass.doApplyInformationToEditor(); } } repaintErrorStripeAndIcon(editor, project); } }); }
Example #8
Source File: IdentifierHighlighterPass.java From consulo with Apache License 2.0 | 5 votes |
public static void clearMyHighlights(Document document, Project project) { MarkupModel markupModel = DocumentMarkupModel.forDocument(document, project, true); for (RangeHighlighter highlighter : markupModel.getAllHighlighters()) { Object tooltip = highlighter.getErrorStripeTooltip(); if (!(tooltip instanceof HighlightInfo)) { continue; } HighlightInfo info = (HighlightInfo)tooltip; if (info.type == HighlightInfoType.ELEMENT_UNDER_CARET_READ || info.type == HighlightInfoType.ELEMENT_UNDER_CARET_WRITE) { highlighter.dispose(); } } }
Example #9
Source File: LineStatusTracker.java From consulo with Apache License 2.0 | 5 votes |
@Override @RequiredUIAccess protected void createHighlighter(@Nonnull Range range) { myApplication.assertIsDispatchThread(); if (range.getHighlighter() != null) { LOG.error("Multiple highlighters registered for the same Range"); return; } if (myMode == Mode.SILENT) return; int first = range.getLine1() >= getLineCount(myDocument) ? myDocument.getTextLength() : myDocument.getLineStartOffset(range.getLine1()); int second = range.getLine2() >= getLineCount(myDocument) ? myDocument.getTextLength() : myDocument.getLineStartOffset(range.getLine2()); MarkupModel markupModel = DocumentMarkupModel.forDocument(myDocument, myProject, true); RangeHighlighter highlighter = LineStatusMarkerRenderer.createRangeHighlighter(range, new TextRange(first, second), markupModel); highlighter.setLineMarkerRenderer(LineStatusMarkerRenderer.createRenderer(range, (editor) -> { return new LineStatusTrackerDrawing.MyLineStatusMarkerPopup(this, editor, range); })); highlighter.setEditorFilter(MarkupEditorFilterFactory.createIsNotDiffFilter()); range.setHighlighter(highlighter); }
Example #10
Source File: BreakpointItem.java From consulo with Apache License 2.0 | 5 votes |
protected static void showInEditor(DetailView panel, VirtualFile virtualFile, int line) { TextAttributes attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(DebuggerColors.BREAKPOINT_ATTRIBUTES); DetailView.PreviewEditorState state = DetailView.PreviewEditorState.create(virtualFile, line, attributes); if (state.equals(panel.getEditorState())) { return; } panel.navigateInPreviewEditor(state); TextAttributes softerAttributes = attributes.clone(); Color backgroundColor = softerAttributes.getBackgroundColor(); if (backgroundColor != null) { softerAttributes.setBackgroundColor(ColorUtil.softer(backgroundColor)); } final Editor editor = panel.getEditor(); final MarkupModel editorModel = editor.getMarkupModel(); final MarkupModel documentModel = DocumentMarkupModel.forDocument(editor.getDocument(), editor.getProject(), false); for (RangeHighlighter highlighter : documentModel.getAllHighlighters()) { if (highlighter.getUserData(DebuggerColors.BREAKPOINT_HIGHLIGHTER_KEY) == Boolean.TRUE) { final int line1 = editor.offsetToLogicalPosition(highlighter.getStartOffset()).line; if (line1 != line) { editorModel.addLineHighlighter(line1, DebuggerColors.BREAKPOINT_HIGHLIGHTER_LAYER + 1, softerAttributes); } } } }
Example #11
Source File: RangeMarkerTest.java From consulo with Apache License 2.0 | 5 votes |
public void testRangeHighlighterDisposeVsRemoveAllConflict() throws Exception { Document document = EditorFactory.getInstance().createDocument("[xxxxxxxxxxxxxx]"); MarkupModel markupModel = DocumentMarkupModel.forDocument(document, ourProject, true); RangeMarker m = markupModel.addRangeHighlighter(1, 6, 0, null, HighlighterTargetArea.EXACT_RANGE); assertTrue(m.isValid()); markupModel.removeAllHighlighters(); assertFalse(m.isValid()); assertEmpty(markupModel.getAllHighlighters()); m.dispose(); assertFalse(m.isValid()); }
Example #12
Source File: RangeMarkerTest.java From consulo with Apache License 2.0 | 5 votes |
public void testRangeHighlightersRecreateBug() throws Exception { Document document = EditorFactory.getInstance().createDocument("[xxxxxxxxxxxxxx]"); MarkupModel markupModel = DocumentMarkupModel.forDocument(document, ourProject, true); for (int i=0; i<2; i++) { RangeMarker m = markupModel.addRangeHighlighter(1, 6, 0, null, HighlighterTargetArea.EXACT_RANGE); RangeMarker m2 = markupModel.addRangeHighlighter(2, 7, 0, null, HighlighterTargetArea.EXACT_RANGE); RangeMarker m3 = markupModel.addRangeHighlighter(1, 6, 0, null, HighlighterTargetArea.EXACT_RANGE); markupModel.removeAllHighlighters(); } }
Example #13
Source File: MyActionUtils.java From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License | 5 votes |
@NotNull public static List<RangeHighlighter> getRangeHighlightersAtOffset(Editor editor, int offset) { MarkupModel markupModel = editor.getMarkupModel(); // collect all highlighters and combine to make a single tool tip List<RangeHighlighter> highlightersAtOffset = new ArrayList<RangeHighlighter>(); for (RangeHighlighter r : markupModel.getAllHighlighters()) { int a = r.getStartOffset(); int b = r.getEndOffset(); // System.out.printf("#%d: %d..%d %s\n", i, a, b, r.toString()); if (offset >= a && offset < b) { // cursor is over some kind of highlighting highlightersAtOffset.add(r); } } return highlightersAtOffset; }
Example #14
Source File: EditorDocOps.java From KodeBeagle with Apache License 2.0 | 5 votes |
public final void addHighlighting(final List<Integer> linesForHighlighting, final Document document) { TextAttributes attributes = new TextAttributes(); JBColor color = JBColor.GREEN; attributes.setEffectColor(color); attributes.setEffectType(EffectType.SEARCH_MATCH); attributes.setBackgroundColor(HIGHLIGHTING_COLOR); Editor projectEditor = FileEditorManager.getInstance(windowObjects.getProject()).getSelectedTextEditor(); if (projectEditor != null) { PsiFile psiFile = PsiDocumentManager.getInstance(windowObjects.getProject()). getPsiFile(projectEditor.getDocument()); MarkupModel markupModel = projectEditor.getMarkupModel(); if (markupModel != null) { markupModel.removeAllHighlighters(); for (int line : linesForHighlighting) { line = line - 1; if (line < document.getLineCount()) { int startOffset = document.getLineStartOffset(line); int endOffset = document.getLineEndOffset(line); String lineText = document.getCharsSequence(). subSequence(startOffset, endOffset).toString(); int lineStartOffset = startOffset + lineText.length() - lineText.trim().length(); markupModel.addRangeHighlighter(lineStartOffset, endOffset, HighlighterLayer.ERROR, attributes, HighlighterTargetArea.EXACT_RANGE); if (psiFile != null && psiFile.findElementAt(lineStartOffset) != null) { HighlightUsagesHandler.doHighlightElements(projectEditor, new PsiElement[]{psiFile.findElementAt(lineStartOffset)}, attributes, false); } } } } } }
Example #15
Source File: CommentsDiffTool.java From review-board-idea-plugin with Apache License 2.0 | 5 votes |
private void updateHighLights(Editor editor) { MarkupModel markup = editor.getMarkupModel(); for (RangeHighlighter customRangeHighlighter : newCommentHighlighters) { markup.removeHighlighter(customRangeHighlighter); } newCommentHighlighters.clear(); int lineCount = markup.getDocument().getLineCount(); Map<Integer, List<Comment>> lineComments = lineComments(comments); for (Map.Entry<Integer, List<Comment>> entry : lineComments.entrySet()) { if (entry.getKey() > lineCount) continue; boolean hasNewComments = false; for (Comment comment : entry.getValue()) { if (comment.id == null) { hasNewComments = true; break; } } TextAttributes attributes = new TextAttributes(); if (hasNewComments) attributes.setBackgroundColor(JBColor.PINK); else attributes.setBackgroundColor(JBColor.YELLOW); RangeHighlighter rangeHighlighter = markup .addLineHighlighter(entry.getKey() - 1, HighlighterLayer.SELECTION + (hasNewComments ? 2 : 1), attributes); rangeHighlighter.setGutterIconRenderer(new CommentGutterIconRenderer()); newCommentHighlighters.add(rangeHighlighter); } }
Example #16
Source File: FilteredIndentsHighlightingPass.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 5 votes |
@NotNull private static RangeHighlighter createHighlighter(MarkupModel mm, TextRange range) { final RangeHighlighter highlighter = mm.addRangeHighlighter(range.getStartOffset(), range.getEndOffset(), 0, null, HighlighterTargetArea.EXACT_RANGE); highlighter.setCustomRenderer(RENDERER); return highlighter; }
Example #17
Source File: LSPDiagnosticsToMarkers.java From intellij-quarkus with Eclipse Public License 2.0 | 5 votes |
private void cleanMarkers(Editor editor) { Map<String, RangeHighlighter[]> allMarkers = getAllMarkers(editor); RangeHighlighter[] highlighters = allMarkers.get(languageServerId); MarkupModel markupModel = editor.getMarkupModel(); if (highlighters != null) { for (RangeHighlighter highlighter : highlighters) { markupModel.removeHighlighter(highlighter); } } allMarkers.remove(languageServerId); }
Example #18
Source File: TextComponentEditorImpl.java From consulo with Apache License 2.0 | 4 votes |
@Override @Nonnull public MarkupModel getMarkupModel() { throw new UnsupportedOperationException("Not implemented"); }
Example #19
Source File: UnifiedEditorRangeHighlighter.java From consulo with Apache License 2.0 | 4 votes |
public static void erase(@javax.annotation.Nullable Project project, @Nonnull Document document) { MarkupModel model = DocumentMarkupModel.forDocument(document, project, true); model.removeAllHighlighters(); }
Example #20
Source File: IndentsPass.java From consulo with Apache License 2.0 | 4 votes |
@Nonnull private static RangeHighlighter createHighlighter(MarkupModel mm, TextRange range) { final RangeHighlighter highlighter = mm.addRangeHighlighter(range.getStartOffset(), range.getEndOffset(), 0, null, HighlighterTargetArea.EXACT_RANGE); highlighter.setCustomRenderer(RENDERER); return highlighter; }
Example #21
Source File: ScopeHighlighter.java From consulo with Apache License 2.0 | 4 votes |
private void addHighlighter(TextRange r, int level, TextAttributes attr) { MarkupModel markupModel = myEditor.getMarkupModel(); RangeHighlighter highlighter = markupModel.addRangeHighlighter(r.getStartOffset(), r.getEndOffset(), level, attr, HighlighterTargetArea.EXACT_RANGE); myActiveHighliters.add(highlighter); }
Example #22
Source File: LazyEditor.java From consulo with Apache License 2.0 | 4 votes |
@Override @Nonnull public MarkupModel getMarkupModel() { return getEditor().getMarkupModel(); }
Example #23
Source File: Editor.java From consulo with Apache License 2.0 | 2 votes |
/** * Returns the markup model for the editor. This model contains editor-specific highlighters * (for example, highlighters added by "Highlight usages in file"), which are painted in addition * to the highlighters contained in the markup model for the document. * <p> * See also {@link com.intellij.openapi.editor.impl.DocumentMarkupModel.forDocument(Document, Project, boolean)} * {@link com.intellij.openapi.editor.ex.EditorEx#getFilteredDocumentMarkupModel()}. * * @return the markup model instance. */ @Nonnull MarkupModel getMarkupModel();