Search in sources :

Example 6 with RangeHighlighterEx

use of com.intellij.openapi.editor.ex.RangeHighlighterEx in project intellij-community by JetBrains.

the class Bookmark method getLine.

public int getLine() {
    int targetLine = myTarget.getLine();
    if (targetLine == -1)
        return targetLine;
    //What user sees in gutter
    RangeHighlighterEx highlighter = findMyHighlighter();
    if (highlighter != null && highlighter.isValid()) {
        Document document = getDocument();
        if (document != null) {
            return document.getLineNumber(highlighter.getStartOffset());
        }
    }
    RangeMarker marker = myTarget.getRangeMarker();
    if (marker != null && marker.isValid()) {
        Document document = marker.getDocument();
        return document.getLineNumber(marker.getStartOffset());
    }
    return targetLine;
}
Also used : RangeHighlighterEx(com.intellij.openapi.editor.ex.RangeHighlighterEx) RangeMarker(com.intellij.openapi.editor.RangeMarker) Document(com.intellij.openapi.editor.Document)

Example 7 with RangeHighlighterEx

use of com.intellij.openapi.editor.ex.RangeHighlighterEx in project intellij-community by JetBrains.

the class Bookmark method findMyHighlighter.

private RangeHighlighterEx findMyHighlighter() {
    final Document document = getDocument();
    if (document == null)
        return null;
    RangeHighlighterEx result = SoftReference.dereference(myHighlighterRef);
    if (result != null) {
        return result;
    }
    MarkupModelEx markup = (MarkupModelEx) DocumentMarkupModel.forDocument(document, myProject, true);
    final Document markupDocument = markup.getDocument();
    final int startOffset = 0;
    final int endOffset = markupDocument.getTextLength();
    final Ref<RangeHighlighterEx> found = new Ref<>();
    markup.processRangeHighlightersOverlappingWith(startOffset, endOffset, highlighter -> {
        GutterMark renderer = highlighter.getGutterIconRenderer();
        if (renderer instanceof MyGutterIconRenderer && ((MyGutterIconRenderer) renderer).myBookmark == this) {
            found.set(highlighter);
            return false;
        }
        return true;
    });
    result = found.get();
    myHighlighterRef = result == null ? null : new WeakReference<>(result);
    return result;
}
Also used : Ref(com.intellij.openapi.util.Ref) RangeHighlighterEx(com.intellij.openapi.editor.ex.RangeHighlighterEx) MarkupModelEx(com.intellij.openapi.editor.ex.MarkupModelEx) WeakReference(java.lang.ref.WeakReference) Document(com.intellij.openapi.editor.Document) GutterMark(com.intellij.codeInsight.daemon.GutterMark)

Example 8 with RangeHighlighterEx

use of com.intellij.openapi.editor.ex.RangeHighlighterEx in project intellij-community by JetBrains.

the class Bookmark method createHighlighter.

public RangeHighlighter createHighlighter(@NotNull MarkupModelEx markup) {
    final RangeHighlighterEx highlighter;
    int line = getLine();
    if (line >= 0) {
        highlighter = markup.addPersistentLineHighlighter(line, HighlighterLayer.ERROR + 1, null);
        if (highlighter != null) {
            highlighter.setGutterIconRenderer(new MyGutterIconRenderer(this));
            TextAttributes textAttributes = ObjectUtils.notNull(EditorColorsManager.getInstance().getGlobalScheme().getAttributes(CodeInsightColors.BOOKMARKS_ATTRIBUTES), new TextAttributes());
            Color stripeColor = ObjectUtils.notNull(textAttributes.getErrorStripeColor(), new JBColor(0x000000, 0xdbdbdb));
            highlighter.setErrorStripeMarkColor(stripeColor);
            highlighter.setErrorStripeTooltip(getBookmarkTooltip());
            TextAttributes attributes = highlighter.getTextAttributes();
            if (attributes == null) {
                attributes = new TextAttributes();
            }
            attributes.setBackgroundColor(textAttributes.getBackgroundColor());
            attributes.setForegroundColor(textAttributes.getForegroundColor());
            highlighter.setTextAttributes(attributes);
        }
    } else {
        highlighter = null;
    }
    myHighlighterRef = highlighter == null ? null : new WeakReference<>(highlighter);
    return highlighter;
}
Also used : RangeHighlighterEx(com.intellij.openapi.editor.ex.RangeHighlighterEx) JBColor(com.intellij.ui.JBColor) WeakReference(java.lang.ref.WeakReference) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) JBColor(com.intellij.ui.JBColor)

Example 9 with RangeHighlighterEx

use of com.intellij.openapi.editor.ex.RangeHighlighterEx in project intellij-community by JetBrains.

the class Bookmark method release.

public void release() {
    int line = getLine();
    if (line < 0) {
        return;
    }
    final Document document = getDocument();
    if (document == null)
        return;
    MarkupModelEx markup = (MarkupModelEx) DocumentMarkupModel.forDocument(document, myProject, true);
    final Document markupDocument = markup.getDocument();
    if (markupDocument.getLineCount() <= line)
        return;
    RangeHighlighterEx highlighter = findMyHighlighter();
    if (highlighter != null) {
        myHighlighterRef = null;
        highlighter.dispose();
    }
}
Also used : MarkupModelEx(com.intellij.openapi.editor.ex.MarkupModelEx) RangeHighlighterEx(com.intellij.openapi.editor.ex.RangeHighlighterEx) Document(com.intellij.openapi.editor.Document)

Example 10 with RangeHighlighterEx

use of com.intellij.openapi.editor.ex.RangeHighlighterEx in project intellij-community by JetBrains.

the class DaemonRespondToChangesTest method testLineMarkersDoNotBlinkOnBackSpaceRightBeforeMethodIdentifier.

public void testLineMarkersDoNotBlinkOnBackSpaceRightBeforeMethodIdentifier() throws Throwable {
    configureByText(JavaFileType.INSTANCE, "package x; \n" + "class  <caret>ToRun{\n" + "  public static void main(String[] args) {\n" + "  }\n" + "}");
    List<HighlightInfo> errors = highlightErrors();
    assertEmpty(errors);
    List<LineMarkerInfo> lineMarkers = DaemonCodeAnalyzerImpl.getLineMarkers(myEditor.getDocument(), getProject());
    assertSize(2, lineMarkers);
    backspace();
    final Collection<String> changed = new ArrayList<>();
    MarkupModelEx modelEx = (MarkupModelEx) DocumentMarkupModel.forDocument(getDocument(getFile()), getProject(), true);
    modelEx.addMarkupModelListener(getTestRootDisposable(), new MarkupModelListener() {

        @Override
        public void afterAdded(@NotNull RangeHighlighterEx highlighter) {
            changed(highlighter, ExceptionUtil.getThrowableText(new Throwable("after added")));
        }

        @Override
        public void beforeRemoved(@NotNull RangeHighlighterEx highlighter) {
            changed(highlighter, ExceptionUtil.getThrowableText(new Throwable("before removed")));
        }

        @Override
        public void attributesChanged(@NotNull RangeHighlighterEx highlighter, boolean renderersChanged, boolean fontStyleChanged) {
            changed(highlighter, ExceptionUtil.getThrowableText(new Throwable("changed")));
        }

        private void changed(@NotNull RangeHighlighterEx highlighter, String reason) {
            // not line marker
            if (highlighter.getTargetArea() != HighlighterTargetArea.LINES_IN_RANGE)
                return;
            List<LineMarkerInfo> lineMarkers = DaemonCodeAnalyzerImpl.getLineMarkers(myEditor.getDocument(), getProject());
            // not line marker
            if (ContainerUtil.find(lineMarkers, lm -> lm.highlighter == highlighter) == null)
                return;
            changed.add(highlighter + ": \n" + reason);
        }
    });
    assertEmpty(highlightErrors());
    assertSize(2, DaemonCodeAnalyzerImpl.getLineMarkers(myEditor.getDocument(), getProject()));
    assertEmpty(changed);
}
Also used : MarkupModelListener(com.intellij.openapi.editor.impl.event.MarkupModelListener) MarkupModelEx(com.intellij.openapi.editor.ex.MarkupModelEx) RangeHighlighterEx(com.intellij.openapi.editor.ex.RangeHighlighterEx) List(java.util.List)

Aggregations

RangeHighlighterEx (com.intellij.openapi.editor.ex.RangeHighlighterEx)23 MarkupModelEx (com.intellij.openapi.editor.ex.MarkupModelEx)13 Document (com.intellij.openapi.editor.Document)7 ArrayList (java.util.ArrayList)6 List (java.util.List)6 Editor (com.intellij.openapi.editor.Editor)5 MarkupModelListener (com.intellij.openapi.editor.impl.event.MarkupModelListener)5 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)5 NotNull (org.jetbrains.annotations.NotNull)5 RangeHighlighter (com.intellij.openapi.editor.markup.RangeHighlighter)4 Project (com.intellij.openapi.project.Project)4 RangeMarker (com.intellij.openapi.editor.RangeMarker)3 DocumentMarkupModel (com.intellij.openapi.editor.impl.DocumentMarkupModel)3 Pair (com.intellij.openapi.util.Pair)3 java.awt (java.awt)3 Nullable (org.jetbrains.annotations.Nullable)3 GutterMark (com.intellij.codeInsight.daemon.GutterMark)2 EditorColorsManager (com.intellij.openapi.editor.colors.EditorColorsManager)2 EditorColorsScheme (com.intellij.openapi.editor.colors.EditorColorsScheme)2 EditorEx (com.intellij.openapi.editor.ex.EditorEx)2