Search in sources :

Example 16 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 17 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 18 with RangeHighlighterEx

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

the class RangeMarkerTest method testRangeHighlighterLinesInRangeForLongLinePerformance.

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), () -> {
        List<RangeHighlighterEx> list = new ArrayList<>();
        CommonProcessors.CollectProcessor<RangeHighlighterEx> coll = new CommonProcessors.CollectProcessor<>(list);
        for (int i = 0; i < N - 1; i++) {
            list.clear();
            markupModel.processRangeHighlightersOverlappingWith(2 * i, 2 * i + 1, coll);
            // 1 line plus one exact range marker
            assertEquals(2, list.size());
        }
    }).useLegacyScaling().assertTiming();
}
Also used : MarkupModelEx(com.intellij.openapi.editor.ex.MarkupModelEx) RangeHighlighterEx(com.intellij.openapi.editor.ex.RangeHighlighterEx) CommonProcessors(com.intellij.util.CommonProcessors)

Example 19 with RangeHighlighterEx

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

the class HighlightingSessionImpl method queueDisposeHighlighterFor.

void queueDisposeHighlighterFor(@NotNull HighlightInfo info) {
    RangeHighlighterEx highlighter = info.getHighlighter();
    if (highlighter == null)
        return;
    // that highlighter may have been reused for another info
    myEDTQueue.offer(() -> {
        Object actualInfo = highlighter.getErrorStripeTooltip();
        if (actualInfo == info && info.getHighlighter() == highlighter)
            highlighter.dispose();
    });
}
Also used : RangeHighlighterEx(com.intellij.openapi.editor.ex.RangeHighlighterEx)

Example 20 with RangeHighlighterEx

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

the class DaemonRespondToChangesTest method testErrorDisappearsRightAfterTypingInsideVisibleAreaWhileDaemonContinuesToChugAlong.

public void testErrorDisappearsRightAfterTypingInsideVisibleAreaWhileDaemonContinuesToChugAlong() throws Throwable {
    String text = "class X{\nint xxx;\n{\nint i = <selection>null</selection><caret>;\n" + StringUtil.repeat("{ this.hashCode(); }\n\n\n", 10000) + "}}";
    configureByText(StdFileTypes.JAVA, text);
    ((EditorImpl) myEditor).getScrollPane().getViewport().setSize(100, 100);
    DaemonCodeAnalyzerSettings.getInstance().setImportHintEnabled(true);
    myEditor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
    ((EditorImpl) myEditor).getScrollPane().getViewport().setViewPosition(new Point(0, 0));
    ((EditorImpl) myEditor).getScrollPane().getViewport().setExtentSize(new Dimension(100, 100000));
    ProperTextRange visibleRange = VisibleHighlightingPassFactory.calculateVisibleRange(getEditor());
    assertTrue(visibleRange.getLength() > 0);
    final Document document = myEditor.getDocument();
    assertTrue(visibleRange.getLength() < document.getTextLength());
    List<HighlightInfo> err1 = highlightErrors();
    HighlightInfo info = assertOneElement(err1);
    final String errorDescription = "Incompatible types. Found: 'null', required: 'int'";
    assertEquals(errorDescription, info.getDescription());
    MarkupModelEx model = (MarkupModelEx) DocumentMarkupModel.forDocument(document, myProject, false);
    final boolean[] errorRemoved = { false };
    model.addMarkupModelListener(getTestRootDisposable(), new MarkupModelListener.Adapter() {

        @Override
        public void beforeRemoved(@NotNull RangeHighlighterEx highlighter) {
            Object tt = highlighter.getErrorStripeTooltip();
            if (!(tt instanceof HighlightInfo))
                return;
            String description = ((HighlightInfo) tt).getDescription();
            if (errorDescription.equals(description)) {
                errorRemoved[0] = true;
                List<TextEditorHighlightingPass> passes = myDaemonCodeAnalyzer.getPassesToShowProgressFor(document);
                GeneralHighlightingPass ghp = null;
                for (TextEditorHighlightingPass pass : passes) {
                    if (pass instanceof GeneralHighlightingPass && pass.getId() == Pass.UPDATE_ALL) {
                        assert ghp == null : ghp;
                        ghp = (GeneralHighlightingPass) pass;
                    }
                }
                assertNotNull(ghp);
                boolean finished = ghp.isFinished();
                assertFalse(finished);
            }
        }
    });
    type("1");
    List<HighlightInfo> errors = highlightErrors();
    assertEmpty(errors);
    assertTrue(errorRemoved[0]);
}
Also used : EditorImpl(com.intellij.openapi.editor.impl.EditorImpl) ProperTextRange(com.intellij.openapi.util.ProperTextRange) 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