private void highlightLine(int index, NamedTextAttr namedTextAttr) { UIUtil.invokeAndWaitIfNeeded((Runnable) () -> { try { MarkupModelEx markupModel = myEditor.getMarkupModel(); final Document doc = markupModel.getDocument(); final int lineStartOffset = doc.getLineStartOffset(index); final int lineEndOffset = doc.getLineEndOffset(index); // IDEA-53203: add ERASE_MARKER for manually defined attributes markupModel.addRangeHighlighter(lineStartOffset, lineEndOffset, HighlighterLayer.SELECTION - 1, TextAttributes.ERASE_MARKER, HighlighterTargetArea.EXACT_RANGE); RangeHighlighter rangeHighlight = markupModel.addRangeHighlighter(lineStartOffset, lineEndOffset, HighlighterLayer.SELECTION - 1, namedTextAttr, HighlighterTargetArea.EXACT_RANGE); rangeHighlight.setErrorStripeMarkColor(namedTextAttr.getErrorStripeColor()); rangeHighlight.setErrorStripeTooltip(namedTextAttr.getName()); } catch (Exception e) { throw new RuntimeException(e); } }); }
@Override protected void changedUpdateImpl(@NotNull DocumentEvent e) { // todo Denis Zhdanov DocumentEventImpl event = (DocumentEventImpl)e; final boolean shouldTranslateViaDiff = isValid() && PersistentRangeMarkerUtil.shouldTranslateViaDiff(event, this); boolean wasTranslatedViaDiff = shouldTranslateViaDiff; if (shouldTranslateViaDiff) { wasTranslatedViaDiff = translatedViaDiff(e, event); } if (!wasTranslatedViaDiff) { super.changedUpdateImpl(e); if (isValid()) { myLine = getDocument().getLineNumber(getStartOffset()); int endLine = getDocument().getLineNumber(getEndOffset()); if (endLine != myLine) { setIntervalEnd(getDocument().getLineEndOffset(myLine)); } } } if (isValid() && getTargetArea() == HighlighterTargetArea.LINES_IN_RANGE) { setIntervalStart(DocumentUtil.getFirstNonSpaceCharOffset(getDocument(), myLine)); setIntervalEnd(getDocument().getLineEndOffset(myLine)); } }
private HighlighterSweep(@NotNull MarkupModelEx markupModel, int start, int end, final boolean onlyFullLine) { // we have to get all highlighters in advance and sort them by affected offsets // since these can be different from the real offsets the highlighters are sorted by in the tree. (See LINES_IN_RANGE perverts) final List<RangeHighlighterEx> list = new ArrayList<RangeHighlighterEx>(); markupModel.processRangeHighlightersOverlappingWith(myReverseIteration ? end : start, myReverseIteration ? start : end, new CommonProcessors.CollectProcessor<RangeHighlighterEx>(list) { @Override protected boolean accept(RangeHighlighterEx ex) { return !onlyFullLine || ex.getTargetArea() == HighlighterTargetArea.LINES_IN_RANGE; } }); highlighters = list.isEmpty() ? RangeHighlighterEx.EMPTY_ARRAY : list.toArray(new RangeHighlighterEx[list.size()]); Arrays.sort(highlighters, myReverseIteration ? BY_AFFECTED_END_OFFSET_REVERSED : RangeHighlighterEx.BY_AFFECTED_START_OFFSET); while (i < highlighters.length) { RangeHighlighterEx highlighter = highlighters[i++]; if (!skipHighlighter(highlighter)) { myNextHighlighter = highlighter; break; } } }
private void advanceSegmentHighlighters() { myDoc.advance(); myView.advance(); boolean fileEnd = myStartOffset == myDocument.getTextLength(); for (int i = myCurrentHighlighters.size() - 1; i >= 0; i--) { RangeHighlighterEx highlighter = myCurrentHighlighters.get(i); if (myReverseIteration ? highlighter.getAffectedAreaStartOffset() >= myStartOffset : fileEnd && highlighter.getTargetArea() == HighlighterTargetArea.LINES_IN_RANGE ? highlighter.getAffectedAreaEndOffset() < myStartOffset : highlighter.getAffectedAreaEndOffset() <= myStartOffset) { myCurrentHighlighters.remove(i); } } }
private HighlighterSweep(@NotNull MarkupModelEx markupModel, int start, int end, final boolean onlyFullLine) { // we have to get all highlighters in advance and sort them by affected offsets // since these can be different from the real offsets the highlighters are sorted by in the tree. (See LINES_IN_RANGE perverts) final List<RangeHighlighterEx> list = new ArrayList<RangeHighlighterEx>(); markupModel.processRangeHighlightersOverlappingWith(start, end, new CommonProcessors.CollectProcessor<RangeHighlighterEx>(list) { @Override protected boolean accept(RangeHighlighterEx ex) { return !onlyFullLine || ex.getTargetArea() == HighlighterTargetArea.LINES_IN_RANGE; } }); highlighters = list.isEmpty() ? RangeHighlighterEx.EMPTY_ARRAY : list.toArray(new RangeHighlighterEx[list.size()]); Arrays.sort(highlighters, RangeHighlighterEx.BY_AFFECTED_START_OFFSET); while (i < highlighters.length) { RangeHighlighterEx highlighter = highlighters[i++]; if (!skipHighlighter(highlighter)) { myNextHighlighter = highlighter; break; } } }
private static void linkFollowed(Editor editor, Collection<RangeHighlighter> ranges, final RangeHighlighter link) { MarkupModelEx markupModel = (MarkupModelEx)editor.getMarkupModel(); for (RangeHighlighter range : ranges) { TextAttributes oldAttr = range.getUserData(OLD_HYPERLINK_TEXT_ATTRIBUTES); if (oldAttr != null) { markupModel.setRangeHighlighterAttributes(range, oldAttr); range.putUserData(OLD_HYPERLINK_TEXT_ATTRIBUTES, null); } if (range == link) { range.putUserData(OLD_HYPERLINK_TEXT_ATTRIBUTES, range.getTextAttributes()); markupModel.setRangeHighlighterAttributes(range, getFollowedHyperlinkAttributes(range)); } } //refresh highlighter text attributes markupModel.addRangeHighlighter(0, 0, HYPERLINK_LAYER, getHyperlinkAttributes(), HighlighterTargetArea.EXACT_RANGE).dispose(); }
public void testRangeHighlighterLinesInRangeForLongLinePerformance() throws Exception { final int N = 50000; Document document = EditorFactory.getInstance().createDocument(StringUtil.repeatSymbol('x', 2 * N)); final MarkupModelEx markupModel = (MarkupModelEx)DocumentMarkupModel.forDocument(document, ourProject, true); for (int i=0; i<N-1;i++) { markupModel.addRangeHighlighter(2*i, 2*i+1, 0, null, HighlighterTargetArea.EXACT_RANGE); } markupModel.addRangeHighlighter(N / 2, N / 2 + 1, 0, null, HighlighterTargetArea.LINES_IN_RANGE); PlatformTestUtil.startPerformanceTest("slow highlighters lookup", (int)(N*Math.log(N)/1000), new ThrowableRunnable() { @Override public void run() { List<RangeHighlighterEx> list = new ArrayList<RangeHighlighterEx>(); CommonProcessors.CollectProcessor<RangeHighlighterEx> coll = new CommonProcessors.CollectProcessor<RangeHighlighterEx>(list); for (int i=0; i<N-1;i++) { list.clear(); markupModel.processRangeHighlightersOverlappingWith(2*i, 2*i+1, coll); assertEquals(2, list.size()); // 1 line plus one exact range marker } } }).assertTiming(); }
@NotNull private HighlightersSet installHighlighterSet(@NotNull Info info, @NotNull Editor editor) { final JComponent internalComponent = editor.getContentComponent(); internalComponent.addKeyListener(myEditorKeyListener); editor.getScrollingModel().addVisibleAreaListener(myVisibleAreaListener); final Cursor cursor = internalComponent.getCursor(); internalComponent.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); myFileEditorManager.addFileEditorManagerListener(myFileEditorManagerListener); List<RangeHighlighter> highlighters = new ArrayList<RangeHighlighter>(); TextAttributes attributes = myEditorColorsManager.getGlobalScheme().getAttributes(EditorColors.REFERENCE_HYPERLINK_COLOR); for (TextRange range : info.getRanges()) { TextAttributes attr = NavigationUtil.patchAttributesColor(attributes, range, editor); final RangeHighlighter highlighter = editor.getMarkupModel().addRangeHighlighter(range.getStartOffset(), range.getEndOffset(), HighlighterLayer.SELECTION + 1, attr, HighlighterTargetArea.EXACT_RANGE); highlighters.add(highlighter); } return new HighlightersSet(highlighters, editor, cursor, info); }
protected void syntaxError(String annotation, Token offendingToken) { // Annotation annot = new Annotation(20, 30, HighlightSeverity.ERROR, "Test!", "Test Message!"); // HighlightInfo info = HighlightInfo.fromAnnotation(annot); // List<HighlightInfo> al = new ArrayList<HighlightInfo>(); // al.add(info); // UpdateHighlightersUtil.setHighlightersToEditor(project, doc, 20, 30, al, null, 0) final TextAttributes attr = new TextAttributes(); attr.setForegroundColor(JBColor.RED); attr.setEffectColor(JBColor.RED); attr.setEffectType(EffectType.WAVE_UNDERSCORE); MarkupModel markupModel = editor.getMarkupModel(); RangeHighlighter h = markupModel.addRangeHighlighter(startIndex+offendingToken.getStartIndex(), startIndex+offendingToken.getStopIndex()+1, HighlighterLayer.ERROR, // layer attr, HighlighterTargetArea.EXACT_RANGE); h.putUserData(SYNTAX_HIGHLIGHTING_TAG, offendingToken); // store any non-null value to tag it }
@Override protected void changedUpdateImpl(DocumentEvent e) { // todo Denis Zhdanov DocumentEventImpl event = (DocumentEventImpl)e; final boolean shouldTranslateViaDiff = PersistentRangeMarkerUtil.shouldTranslateViaDiff(event, this); boolean wasTranslatedViaDiff = shouldTranslateViaDiff; if (shouldTranslateViaDiff) { wasTranslatedViaDiff = translatedViaDiff(e, event); } if (!wasTranslatedViaDiff) { super.changedUpdateImpl(e); if (isValid()) { setLine(getDocument().getLineNumber(getStartOffset())); int endLine = getDocument().getLineNumber(getEndOffset()); if (endLine != getLine()) { setIntervalEnd(getDocument().getLineEndOffset(getLine())); } } } if (isValid() && getTargetArea() == HighlighterTargetArea.LINES_IN_RANGE) { setIntervalStart(getDocument().getLineStartOffset(getLine())); setIntervalEnd(getDocument().getLineEndOffset(getLine())); } }
@Override public RangeHighlighterEx addRangeHighlighterAndChangeAttributes(int startOffset, int endOffset, int layer, TextAttributes textAttributes, @NotNull HighlighterTargetArea targetArea, boolean isPersistent, @Nullable Consumer<RangeHighlighterEx> changeAttributesAction) { ApplicationManager.getApplication().assertIsDispatchThread(); RangeHighlighterEx highlighter = isPersistent ? new PersistentRangeHighlighterImpl(this, startOffset, layer, targetArea, textAttributes) : new RangeHighlighterImpl(this, startOffset, endOffset, layer, targetArea, textAttributes, false, false); myCachedHighlighters = null; if (changeAttributesAction != null) { ((RangeHighlighterImpl)highlighter).changeAttributesNoEvents(changeAttributesAction); } fireAfterAdded(highlighter); return highlighter; }
private HighlightersSet installHighlighterSet(Info info, Editor editor) { final JComponent internalComponent = editor.getContentComponent(); internalComponent.addKeyListener(myEditorKeyListener); editor.getScrollingModel().addVisibleAreaListener(myVisibleAreaListener); final Cursor cursor = internalComponent.getCursor(); internalComponent.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); myFileEditorManager.addFileEditorManagerListener(myFileEditorManagerListener); List<RangeHighlighter> highlighters = new ArrayList<RangeHighlighter>(); TextAttributes attributes = myEditorColorsManager.getGlobalScheme().getAttributes(EditorColors.REFERENCE_HYPERLINK_COLOR); for (TextRange range : info.getRanges()) { final RangeHighlighter highlighter = editor.getMarkupModel().addRangeHighlighter(range.getStartOffset(), range.getEndOffset(), HighlighterLayer.SELECTION + 1, attributes, HighlighterTargetArea.EXACT_RANGE); highlighters.add(highlighter); } return new HighlightersSet(highlighters, editor, cursor, info); }
public Token addDecisionEventHighlighter(PreviewState previewState, MarkupModel markupModel, DecisionEventInfo info, Color errorStripeColor, EffectType effectType) { TokenStream tokens = previewState.parsingResult.parser.getInputStream(); Token startToken = tokens.get(info.startIndex); Token stopToken = tokens.get(info.stopIndex); TextAttributes textAttributes = new TextAttributes(JBColor.BLACK, JBColor.WHITE, errorStripeColor, effectType, Font.PLAIN); textAttributes.setErrorStripeColor(errorStripeColor); final RangeHighlighter rangeHighlighter = markupModel.addRangeHighlighter( startToken.getStartIndex(), stopToken.getStopIndex()+1, HighlighterLayer.ADDITIONAL_SYNTAX, textAttributes, HighlighterTargetArea.EXACT_RANGE); rangeHighlighter.putUserData(DECISION_EVENT_INFO_KEY, info); rangeHighlighter.setErrorStripeMarkColor(errorStripeColor); return startToken; }
public void highlightAndOfferHint(Editor editor, int offset, Interval sourceInterval, JBColor color, EffectType effectType, String hintText) { CaretModel caretModel = editor.getCaretModel(); final TextAttributes attr = new TextAttributes(); attr.setForegroundColor(color); attr.setEffectColor(color); attr.setEffectType(effectType); MarkupModel markupModel = editor.getMarkupModel(); markupModel.addRangeHighlighter( sourceInterval.a, sourceInterval.b, InputPanel.TOKEN_INFO_LAYER, // layer attr, HighlighterTargetArea.EXACT_RANGE ); if ( hintText.contains("<") ) { hintText = hintText.replaceAll("<", "<"); } // HINT caretModel.moveToOffset(offset); // info tooltip only shows at cursor :( HintManager.getInstance().showInformationHint(editor, hintText); }
@Override protected void changedUpdateImpl(@Nonnull DocumentEvent e) { // todo Denis Zhdanov DocumentEventImpl event = (DocumentEventImpl)e; final boolean shouldTranslateViaDiff = isValid() && PersistentRangeMarkerUtil.shouldTranslateViaDiff(event, getStartOffset(), getEndOffset()); boolean wasTranslatedViaDiff = shouldTranslateViaDiff; if (shouldTranslateViaDiff) { wasTranslatedViaDiff = translatedViaDiff(e, event); } if (!wasTranslatedViaDiff) { super.changedUpdateImpl(e); if (isValid()) { myLine = getDocument().getLineNumber(getStartOffset()); int endLine = getDocument().getLineNumber(getEndOffset()); if (endLine != myLine) { setIntervalEnd(getDocument().getLineEndOffset(myLine)); } } } if (isValid() && getTargetArea() == HighlighterTargetArea.LINES_IN_RANGE) { setIntervalStart(DocumentUtil.getFirstNonSpaceCharOffset(getDocument(), myLine)); setIntervalEnd(getDocument().getLineEndOffset(myLine)); } }
private HighlighterSweep(@Nonnull MarkupModelEx markupModel, int start, int end, final boolean onlyFullLine, final boolean onlyFontOrForegroundAffecting) { // we have to get all highlighters in advance and sort them by affected offsets // since these can be different from the real offsets the highlighters are sorted by in the tree. (See LINES_IN_RANGE perverts) final List<RangeHighlighterEx> list = new ArrayList<>(); markupModel.processRangeHighlightersOverlappingWith(myReverseIteration ? end : start, myReverseIteration ? start : end, new CommonProcessors.CollectProcessor<RangeHighlighterEx>(list) { @Override protected boolean accept(RangeHighlighterEx ex) { return (!onlyFullLine || ex.getTargetArea() == HighlighterTargetArea.LINES_IN_RANGE) && (!onlyFontOrForegroundAffecting || EditorUtil.attributesImpactFontStyleOrColor(ex.getTextAttributes())); } }); highlighters = list.isEmpty() ? RangeHighlighterEx.EMPTY_ARRAY : list.toArray(new RangeHighlighterEx[list.size()]); Arrays.sort(highlighters, myReverseIteration ? BY_AFFECTED_END_OFFSET_REVERSED : RangeHighlighterEx.BY_AFFECTED_START_OFFSET); while (i < highlighters.length) { RangeHighlighterEx highlighter = highlighters[i++]; if (!skipHighlighter(highlighter)) { myNextHighlighter = highlighter; break; } } }
private void advanceSegmentHighlighters() { myDoc.advance(); myView.advance(); boolean fileEnd = myStartOffset == myDocument.getTextLength(); for (int i = myCurrentHighlighters.size() - 1; i >= 0; i--) { RangeHighlighterEx highlighter = myCurrentHighlighters.get(i); if (myReverseIteration ? getAlignedStartOffset(highlighter) >= myStartOffset : fileEnd && highlighter.getTargetArea() == HighlighterTargetArea.LINES_IN_RANGE ? getAlignedEndOffset(highlighter) < myStartOffset : getAlignedEndOffset(highlighter) <= myStartOffset) { myCurrentHighlighters.remove(i); } } }
private void createStatusHighlighter() { int line1 = myPatchDeletionRange.start; int line2 = myPatchInsertionRange.end; Color color = getStatusColor(); if (isResolved()) { color = ColorUtil.mix(color, myViewer.getPatchEditor().getGutterComponentEx().getBackground(), 0.6f); } String tooltip = getStatusText(); EditorEx patchEditor = myViewer.getPatchEditor(); Document document = patchEditor.getDocument(); MarkupModelEx markupModel = patchEditor.getMarkupModel(); TextRange textRange = DiffUtil.getLinesRange(document, line1, line2); RangeHighlighter highlighter = markupModel.addRangeHighlighter(textRange.getStartOffset(), textRange.getEndOffset(), HighlighterLayer.LAST, null, HighlighterTargetArea.LINES_IN_RANGE); PairConsumer<Editor, MouseEvent> clickHandler = getResultRange() != null ? (e, event) -> myViewer.scrollToChange(this, Side.RIGHT, false) : null; highlighter.setLineMarkerRenderer(LineStatusMarkerRenderer.createRenderer(line1, line2, color, tooltip, clickHandler)); myHighlighters.add(highlighter); }
@Nullable private MyGutterOperation createOperation(@Nonnull OperationType type) { if (isResolved()) return null; EditorEx editor = myViewer.getPatchEditor(); Document document = editor.getDocument(); int line = getPatchRange().start; int offset = line == DiffUtil.getLineCount(document) ? document.getTextLength() : document.getLineStartOffset(line); RangeHighlighter highlighter = editor.getMarkupModel().addRangeHighlighter(offset, offset, HighlighterLayer.ADDITIONAL_SYNTAX, null, HighlighterTargetArea.LINES_IN_RANGE); return new MyGutterOperation(highlighter, type); }
/** * 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; }
@Nonnull private HighlightersSet installHighlighterSet(@Nonnull Info info, @Nonnull Editor editor) { final JComponent internalComponent = editor.getContentComponent(); internalComponent.addKeyListener(myEditorKeyListener); editor.getScrollingModel().addVisibleAreaListener(myVisibleAreaListener); final Cursor cursor = internalComponent.getCursor(); internalComponent.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); myFileEditorManager.addFileEditorManagerListener(myFileEditorManagerListener); List<RangeHighlighter> highlighters = new ArrayList<RangeHighlighter>(); TextAttributes attributes = myEditorColorsManager.getGlobalScheme().getAttributes(EditorColors.REFERENCE_HYPERLINK_COLOR); for (TextRange range : info.getRanges()) { TextAttributes attr = NavigationUtil.patchAttributesColor(attributes, range, editor); final RangeHighlighter highlighter = editor.getMarkupModel().addRangeHighlighter(range.getStartOffset(), range.getEndOffset(), HighlighterLayer.SELECTION + 1, attr, HighlighterTargetArea.EXACT_RANGE); highlighters.add(highlighter); } return new HighlightersSet(highlighters, editor, cursor, info); }
private RangeHighlighter createRangeHighlighter(Document document, Editor editor, int fromLine, int toLine, TextAttributes attributes) { int lineStartOffset = document.getLineStartOffset(Math.max(0, fromLine)); int lineEndOffset = document.getLineEndOffset(Math.max(0, toLine)); return editor.getMarkupModel().addRangeHighlighter( lineStartOffset, lineEndOffset, 3333, attributes, HighlighterTargetArea.LINES_IN_RANGE ); }
@NotNull RangeHighlighterEx addRangeHighlighterAndChangeAttributes(int startOffset, int endOffset, int layer, TextAttributes textAttributes, @NotNull HighlighterTargetArea targetArea, boolean isPersistent, Consumer<RangeHighlighterEx> changeAttributesAction);
@Override @NotNull public RangeHighlighter addRangeHighlighter(int startOffset, int endOffset, int layer, @Nullable TextAttributes textAttributes, @NotNull HighlighterTargetArea targetArea) { throw new ProcessCanceledException(); }
@NotNull @Override public RangeHighlighterEx addRangeHighlighterAndChangeAttributes(int startOffset, int endOffset, int layer, TextAttributes textAttributes, @NotNull HighlighterTargetArea targetArea, boolean isPersistent, Consumer<RangeHighlighterEx> changeAttributesAction) { throw new ProcessCanceledException(); }
static PersistentRangeHighlighterImpl create(@NotNull MarkupModel model, int offset, int layer, @NotNull HighlighterTargetArea target, @Nullable TextAttributes textAttributes, boolean normalizeStartOffset) { int line = model.getDocument().getLineNumber(offset); int startOffset = normalizeStartOffset ? model.getDocument().getLineStartOffset(line) : offset; return new PersistentRangeHighlighterImpl(model, startOffset, line, layer, target, textAttributes); }
private PersistentRangeHighlighterImpl(@NotNull MarkupModel model, int startOffset, int line, int layer, @NotNull HighlighterTargetArea target, @Nullable TextAttributes textAttributes) { super(model, startOffset, model.getDocument().getLineEndOffset(line), layer, target, textAttributes, false, false); myLine = line; }
@Override @NotNull public RangeHighlighter addLineHighlighter(int lineNumber, int layer, TextAttributes textAttributes) { if (isNotValidLine(lineNumber)) { throw new IndexOutOfBoundsException("lineNumber:" + lineNumber + ". Must be in [0, " + (getDocument().getLineCount() - 1) + "]"); } int offset = DocumentUtil.getFirstNonSpaceCharOffset(getDocument(), lineNumber); return addRangeHighlighter(offset, offset, layer, textAttributes, HighlighterTargetArea.LINES_IN_RANGE); }
@Override @Nullable public RangeHighlighterEx addPersistentLineHighlighter(int lineNumber, int layer, TextAttributes textAttributes) { if (isNotValidLine(lineNumber)) { return null; } int offset = DocumentUtil.getFirstNonSpaceCharOffset(getDocument(), lineNumber); return addRangeHighlighter(PersistentRangeHighlighterImpl.create(this, offset, layer, HighlighterTargetArea.LINES_IN_RANGE, textAttributes, false), null); }
@NotNull @Override public RangeHighlighterEx addRangeHighlighterAndChangeAttributes(int startOffset, int endOffset, int layer, TextAttributes textAttributes, @NotNull HighlighterTargetArea targetArea, boolean isPersistent, @Nullable Consumer<RangeHighlighterEx> changeAttributesAction) { return addRangeHighlighter(isPersistent ? PersistentRangeHighlighterImpl.create(this, startOffset, layer, targetArea, textAttributes, true) : new RangeHighlighterImpl(this, startOffset, endOffset, layer, targetArea, textAttributes, false, false), changeAttributesAction); }
@Override @NotNull public RangeHighlighter addRangeHighlighter(int startOffset, int endOffset, int layer, TextAttributes textAttributes, @NotNull HighlighterTargetArea targetArea) { return addRangeHighlighterAndChangeAttributes(startOffset, endOffset, layer, textAttributes, targetArea, false, null); }
@Override @NotNull public RangeHighlighter addRangeHighlighter(final int startOffset, final int endOffset, final int layer, final TextAttributes textAttributes, @NotNull final HighlighterTargetArea targetArea) { TextRange hostRange = myDocument.injectedToHost(new ProperTextRange(startOffset, endOffset)); return myHostModel.addRangeHighlighter(hostRange.getStartOffset(), hostRange.getEndOffset(), layer, textAttributes, targetArea); }
@NotNull @Override public RangeHighlighterEx addRangeHighlighterAndChangeAttributes(int startOffset, int endOffset, int layer, TextAttributes textAttributes, @NotNull HighlighterTargetArea targetArea, boolean isPersistent, Consumer<RangeHighlighterEx> changeAttributesAction) { TextRange hostRange = myDocument.injectedToHost(new ProperTextRange(startOffset, endOffset)); return myHostModel.addRangeHighlighterAndChangeAttributes(hostRange.getStartOffset(), hostRange.getEndOffset(), layer, textAttributes, targetArea, isPersistent, changeAttributesAction); }
public void addRangeHighlighter(final boolean left, int start, int end, final TextAttributes attributes) { if (left) { myAppender1.getEditor().getMarkupModel().addRangeHighlighter(start, end, HighlighterLayer.SELECTION - 3, attributes, HighlighterTargetArea.EXACT_RANGE); } else { myAppender2.getEditor().getMarkupModel().addRangeHighlighter(start, end, HighlighterLayer.SELECTION - 3, attributes, HighlighterTargetArea.EXACT_RANGE); } }
@Nullable public Color getPastFileEndBackground() { boolean isInCaretRow = myEditor.getCaretModel().getLogicalPosition().line >= myDocument.getLineCount() - 1; Color caret = isInCaretRow && myCaretRowAttributes != null ? myCaretRowAttributes.getBackgroundColor() : null; ContainerUtil.quickSort(myCurrentHighlighters, LayerComparator.INSTANCE); //noinspection ForLoopReplaceableByForEach for (int i = 0; i < myCurrentHighlighters.size(); i++) { RangeHighlighterEx highlighter = myCurrentHighlighters.get(i); if (caret != null && highlighter.getLayer() < HighlighterLayer.CARET_ROW) { return caret; } if (highlighter.getTargetArea() != HighlighterTargetArea.LINES_IN_RANGE || myDocument.getLineNumber(highlighter.getEndOffset()) < myDocument.getLineCount() - 1) { continue; } TextAttributes textAttributes = highlighter.getTextAttributes(); if (textAttributes != null) { Color backgroundColor = textAttributes.getBackgroundColor(); if (backgroundColor != null) return backgroundColor; } } return caret; }
@NotNull private RangeHighlighter createHyperlink(final int highlightStartOffset, final int highlightEndOffset, @Nullable final TextAttributes highlightAttributes, @NotNull final HyperlinkInfo hyperlinkInfo, @Nullable TextAttributes followedHyperlinkAttributes) { TextAttributes textAttributes = highlightAttributes != null ? highlightAttributes : getHyperlinkAttributes(); final RangeHighlighter highlighter = myEditor.getMarkupModel().addRangeHighlighter(highlightStartOffset, highlightEndOffset, HYPERLINK_LAYER, textAttributes, HighlighterTargetArea.EXACT_RANGE); associateHyperlink(highlighter, hyperlinkInfo, followedHyperlinkAttributes); return highlighter; }
protected void setTextToEditor(String text) { myEditor.getMarkupModel().removeAllHighlighters(); myEditor.getDocument().setText(text); myEditor.getHighlighter().setText(text); if (myTextAttributes != null) { myEditor.getMarkupModel().addRangeHighlighter(0, myEditor.getDocument().getTextLength(), HighlighterLayer.ADDITIONAL_SYNTAX, myTextAttributes, HighlighterTargetArea.EXACT_RANGE); } ((EditorImpl)myEditor).resetSizes(); ((EditorImpl)myEditor).setPaintSelection(mySelected); SelectionModel selectionModel = myEditor.getSelectionModel(); selectionModel.setSelection(0, mySelected ? myEditor.getDocument().getTextLength() : 0); }
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(); } }