Search in sources :

Example 56 with RangeHighlighter

use of com.intellij.openapi.editor.markup.RangeHighlighter in project intellij-community by JetBrains.

the class CodeInsightTestFixtureImpl method findAllGutters.

@Override
@NotNull
public List<GutterMark> findAllGutters() {
    final Project project = getProject();
    final SortedMap<Integer, List<GutterMark>> result = new TreeMap<>();
    List<HighlightInfo> infos = doHighlighting();
    for (HighlightInfo info : infos) {
        addGutterIconRenderer(info.getGutterIconRenderer(), info.startOffset, result);
    }
    RangeHighlighter[] highlighters = DocumentMarkupModel.forDocument(myEditor.getDocument(), project, true).getAllHighlighters();
    for (final RangeHighlighter highlighter : highlighters) {
        if (!highlighter.isValid())
            continue;
        addGutterIconRenderer(highlighter.getGutterIconRenderer(), highlighter.getStartOffset(), result);
    }
    return ContainerUtil.concat(result.values());
}
Also used : Project(com.intellij.openapi.project.Project) RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) NotNull(org.jetbrains.annotations.NotNull)

Example 57 with RangeHighlighter

use of com.intellij.openapi.editor.markup.RangeHighlighter in project intellij-community by JetBrains.

the class CodeInsightTestFixtureImpl method findGutters.

private void findGutters(Processor<GutterMark> processor) {
    int offset = myEditor.getCaretModel().getOffset();
    final Collection<HighlightInfo> infos = doHighlighting();
    for (HighlightInfo info : infos) {
        if (info.endOffset >= offset && info.startOffset <= offset) {
            final GutterMark renderer = info.getGutterIconRenderer();
            if (renderer != null && !processor.process(renderer)) {
                return;
            }
        }
    }
    RangeHighlighter[] highlighters = DocumentMarkupModel.forDocument(myEditor.getDocument(), getProject(), true).getAllHighlighters();
    for (RangeHighlighter highlighter : highlighters) {
        if (highlighter.getEndOffset() >= offset && highlighter.getStartOffset() <= offset) {
            GutterMark renderer = highlighter.getGutterIconRenderer();
            if (renderer != null && !processor.process(renderer)) {
                return;
            }
        }
    }
}
Also used : RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) GutterMark(com.intellij.codeInsight.daemon.GutterMark) ExtensionPoint(com.intellij.openapi.extensions.ExtensionPoint)

Example 58 with RangeHighlighter

use of com.intellij.openapi.editor.markup.RangeHighlighter in project intellij-community by JetBrains.

the class ApplyPatchChange method createStatusHighlighter.

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);
}
Also used : RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) EditorEx(com.intellij.openapi.editor.ex.EditorEx) MarkupModelEx(com.intellij.openapi.editor.ex.MarkupModelEx) MouseEvent(java.awt.event.MouseEvent) JBColor(com.intellij.ui.JBColor) TextRange(com.intellij.openapi.util.TextRange) Document(com.intellij.openapi.editor.Document) Editor(com.intellij.openapi.editor.Editor)

Example 59 with RangeHighlighter

use of com.intellij.openapi.editor.markup.RangeHighlighter in project intellij-community by JetBrains.

the class EditorImplTest method testChangingHighlightersInBulkModeListener.

public void testChangingHighlightersInBulkModeListener() throws Exception {
    DocumentBulkUpdateListener.Adapter listener = new DocumentBulkUpdateListener.Adapter() {

        @Override
        public void updateFinished(@NotNull Document doc) {
            if (doc == myEditor.getDocument()) {
                myEditor.getMarkupModel().addRangeHighlighter(7, 8, 0, null, HighlighterTargetArea.EXACT_RANGE);
            }
        }
    };
    getProject().getMessageBus().connect(getTestRootDisposable()).subscribe(DocumentBulkUpdateListener.TOPIC, listener);
    initText("abcdef");
    DocumentEx document = (DocumentEx) myEditor.getDocument();
    runWriteCommand(() -> {
        DocumentUtil.executeInBulk(document, true, () -> {
            document.insertString(3, "\n\n");
        });
    });
    RangeHighlighter[] highlighters = myEditor.getMarkupModel().getAllHighlighters();
    assertEquals(1, highlighters.length);
    assertEquals(7, highlighters[0].getStartOffset());
    assertEquals(8, highlighters[0].getEndOffset());
}
Also used : DocumentEx(com.intellij.openapi.editor.ex.DocumentEx) RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) NotNull(org.jetbrains.annotations.NotNull) DocumentBulkUpdateListener(com.intellij.openapi.editor.ex.DocumentBulkUpdateListener)

Example 60 with RangeHighlighter

use of com.intellij.openapi.editor.markup.RangeHighlighter in project intellij-community by JetBrains.

the class EditorImplTest method testChangingHighlightersAfterClearingFoldingsDuringFoldingBatchUpdate.

public void testChangingHighlightersAfterClearingFoldingsDuringFoldingBatchUpdate() throws Exception {
    initText("abc\n\ndef");
    addCollapsedFoldRegion(2, 6, "...");
    runFoldingOperation(() -> {
        ((FoldingModelEx) myEditor.getFoldingModel()).clearFoldRegions();
        myEditor.getMarkupModel().addRangeHighlighter(7, 8, 0, new TextAttributes(null, null, null, null, Font.BOLD), HighlighterTargetArea.EXACT_RANGE);
    });
    RangeHighlighter[] highlighters = myEditor.getMarkupModel().getAllHighlighters();
    assertEquals(1, highlighters.length);
    assertEquals(7, highlighters[0].getStartOffset());
    assertEquals(8, highlighters[0].getEndOffset());
}
Also used : RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) FoldingModelEx(com.intellij.openapi.editor.ex.FoldingModelEx)

Aggregations

RangeHighlighter (com.intellij.openapi.editor.markup.RangeHighlighter)97 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)26 TextRange (com.intellij.openapi.util.TextRange)22 HighlightManager (com.intellij.codeInsight.highlighting.HighlightManager)18 Editor (com.intellij.openapi.editor.Editor)15 ArrayList (java.util.ArrayList)15 NotNull (org.jetbrains.annotations.NotNull)15 EditorColorsManager (com.intellij.openapi.editor.colors.EditorColorsManager)10 Project (com.intellij.openapi.project.Project)10 RelativePoint (com.intellij.ui.awt.RelativePoint)8 Nullable (org.jetbrains.annotations.Nullable)8 Document (com.intellij.openapi.editor.Document)7 EditorEx (com.intellij.openapi.editor.ex.EditorEx)7 MarkupModelEx (com.intellij.openapi.editor.ex.MarkupModelEx)7 MarkupModel (com.intellij.openapi.editor.markup.MarkupModel)7 PsiElement (com.intellij.psi.PsiElement)6 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)5 EditorWindow (com.intellij.injected.editor.EditorWindow)4 Result (com.intellij.openapi.application.Result)4 LogicalPosition (com.intellij.openapi.editor.LogicalPosition)4