Search in sources :

Example 81 with RangeHighlighter

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

the class CallHierarchyNodeDescriptor method navigate.

public void navigate(boolean requestFocus) {
    if (!myNavigateToReference) {
        PsiElement element = getPsiElement();
        if (element instanceof Navigatable && ((Navigatable) element).canNavigate()) {
            ((Navigatable) element).navigate(requestFocus);
        }
        return;
    }
    final PsiReference firstReference = myReferences.get(0);
    final PsiElement element = firstReference.getElement();
    if (element == null)
        return;
    final PsiElement callElement = element.getParent();
    if (callElement instanceof Navigatable && ((Navigatable) callElement).canNavigate()) {
        ((Navigatable) callElement).navigate(requestFocus);
    } else {
        final PsiFile psiFile = callElement.getContainingFile();
        if (psiFile == null || psiFile.getVirtualFile() == null)
            return;
        FileEditorManager.getInstance(myProject).openFile(psiFile.getVirtualFile(), requestFocus);
    }
    Editor editor = PsiUtilBase.findEditor(callElement);
    if (editor != null) {
        HighlightManager highlightManager = HighlightManager.getInstance(myProject);
        EditorColorsManager colorManager = EditorColorsManager.getInstance();
        TextAttributes attributes = colorManager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
        ArrayList<RangeHighlighter> highlighters = new ArrayList<>();
        for (PsiReference psiReference : myReferences) {
            final PsiElement eachElement = psiReference.getElement();
            if (eachElement != null) {
                final PsiElement eachMethodCall = eachElement.getParent();
                if (eachMethodCall != null) {
                    final TextRange textRange = eachMethodCall.getTextRange();
                    highlightManager.addRangeHighlight(editor, textRange.getStartOffset(), textRange.getEndOffset(), attributes, false, highlighters);
                }
            }
        }
    }
}
Also used : RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) HighlightManager(com.intellij.codeInsight.highlighting.HighlightManager) ArrayList(java.util.ArrayList) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) TextRange(com.intellij.openapi.util.TextRange) EditorColorsManager(com.intellij.openapi.editor.colors.EditorColorsManager) Editor(com.intellij.openapi.editor.Editor) Navigatable(com.intellij.pom.Navigatable)

Example 82 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 83 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 84 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)

Example 85 with RangeHighlighter

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

the class VcsPreviewPanel method addHighlighter.

private void addHighlighter(@NotNull Range range, @NotNull ColorKey colorKey) {
    TextRange textRange = DiffUtil.getLinesRange(myEditor.getDocument(), range.getLine1(), range.getLine2());
    RangeHighlighter highlighter = LineStatusMarkerRenderer.createRangeHighlighter(range, textRange, myEditor.getMarkupModel());
    highlighter.setLineMarkerRenderer(new LineStatusMarkerRenderer(range) {

        @Override
        public boolean canDoAction(MouseEvent e) {
            return isInsideMarkerArea(e);
        }

        @Override
        public void doAction(Editor editor, MouseEvent e) {
            myDispatcher.getMulticaster().selectionInPreviewChanged(colorKey.getExternalName());
        }
    });
}
Also used : RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) LineStatusMarkerRenderer(com.intellij.openapi.vcs.ex.LineStatusMarkerRenderer) MouseEvent(java.awt.event.MouseEvent) TextRange(com.intellij.openapi.util.TextRange) Editor(com.intellij.openapi.editor.Editor)

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