Search in sources :

Example 86 with RangeHighlighter

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

the class IdentifierHighlighterPass method getHighlights.

private List<HighlightInfo> getHighlights() {
    if (myReadAccessRanges.isEmpty() && myWriteAccessRanges.isEmpty()) {
        return Collections.emptyList();
    }
    Set<Pair<Object, TextRange>> existingMarkupTooltips = new HashSet<>();
    for (RangeHighlighter highlighter : myEditor.getMarkupModel().getAllHighlighters()) {
        existingMarkupTooltips.add(Pair.create(highlighter.getErrorStripeTooltip(), new TextRange(highlighter.getStartOffset(), highlighter.getEndOffset())));
    }
    List<HighlightInfo> result = new ArrayList<>(myReadAccessRanges.size() + myWriteAccessRanges.size());
    for (TextRange range : myReadAccessRanges) {
        ContainerUtil.addIfNotNull(result, createHighlightInfo(range, HighlightInfoType.ELEMENT_UNDER_CARET_READ, existingMarkupTooltips));
    }
    for (TextRange range : myWriteAccessRanges) {
        ContainerUtil.addIfNotNull(result, createHighlightInfo(range, HighlightInfoType.ELEMENT_UNDER_CARET_WRITE, existingMarkupTooltips));
    }
    return result;
}
Also used : RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) TextRange(com.intellij.openapi.util.TextRange) Pair(com.intellij.openapi.util.Pair)

Example 87 with RangeHighlighter

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

the class IndentsPass method createHighlighter.

@NotNull
private static RangeHighlighter createHighlighter(MarkupModel mm, TextRange range) {
    final RangeHighlighter highlighter = mm.addRangeHighlighter(range.getStartOffset(), range.getEndOffset(), 0, null, HighlighterTargetArea.EXACT_RANGE);
    highlighter.setCustomRenderer(RENDERER);
    return highlighter;
}
Also used : RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) NotNull(org.jetbrains.annotations.NotNull)

Example 88 with RangeHighlighter

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

the class LineMarkersUtil method setLineMarkersToEditor.

static void setLineMarkersToEditor(@NotNull Project project, @NotNull Document document, @NotNull Segment bounds, @NotNull Collection<LineMarkerInfo> markers, int group) {
    ApplicationManager.getApplication().assertIsDispatchThread();
    MarkupModelEx markupModel = (MarkupModelEx) DocumentMarkupModel.forDocument(document, project, true);
    HighlightersRecycler toReuse = new HighlightersRecycler();
    processLineMarkers(project, document, bounds, group, info -> {
        toReuse.recycleHighlighter(info.highlighter);
        return true;
    });
    if (LOG.isDebugEnabled()) {
        List<LineMarkerInfo> oldMarkers = DaemonCodeAnalyzerImpl.getLineMarkers(document, project);
        LOG.debug("LineMarkersUtil.setLineMarkersToEditor(markers: " + markers + ", group: " + group + "); oldMarkers: " + oldMarkers + "; reused: " + toReuse.forAllInGarbageBin().size());
    }
    for (final LineMarkerInfo info : markers) {
        PsiElement element = info.getElement();
        if (element == null) {
            continue;
        }
        TextRange textRange = element.getTextRange();
        if (textRange == null)
            continue;
        TextRange elementRange = InjectedLanguageManager.getInstance(project).injectedToHost(element, textRange);
        if (!TextRange.containsRange(bounds, elementRange)) {
            continue;
        }
        createOrReuseLineMarker(info, markupModel, toReuse);
    }
    for (RangeHighlighter highlighter : toReuse.forAllInGarbageBin()) {
        highlighter.dispose();
    }
}
Also used : LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) MarkupModelEx(com.intellij.openapi.editor.ex.MarkupModelEx) TextRange(com.intellij.openapi.util.TextRange) PsiElement(com.intellij.psi.PsiElement)

Example 89 with RangeHighlighter

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

the class ErrorStripeHandler method errorMarkerClicked.

@Override
public void errorMarkerClicked(@NotNull ErrorStripeEvent e) {
    RangeHighlighter highlighter = e.getHighlighter();
    if (!highlighter.isValid())
        return;
    HighlightInfo info = findInfo(highlighter);
    if (info != null) {
        GotoNextErrorHandler.navigateToError(myProject, e.getEditor(), info);
    }
}
Also used : RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter)

Example 90 with RangeHighlighter

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

the class FindManagerImpl method highlightNextHighlighter.

private static boolean highlightNextHighlighter(RangeHighlighter[] highlighters, Editor editor, int offset, boolean isForward, boolean secondPass) {
    RangeHighlighter highlighterToSelect = null;
    Object wasNotFound = editor.getUserData(HIGHLIGHTER_WAS_NOT_FOUND_KEY);
    for (RangeHighlighter highlighter : highlighters) {
        int start = highlighter.getStartOffset();
        int end = highlighter.getEndOffset();
        if (highlighter.isValid() && start < end) {
            if (isForward && (start > offset || start == offset && secondPass)) {
                if (highlighterToSelect == null || highlighterToSelect.getStartOffset() > start)
                    highlighterToSelect = highlighter;
            }
            if (!isForward && (end < offset || end == offset && secondPass)) {
                if (highlighterToSelect == null || highlighterToSelect.getEndOffset() < end)
                    highlighterToSelect = highlighter;
            }
        }
    }
    if (highlighterToSelect != null) {
        expandFoldRegionsIfNecessary(editor, highlighterToSelect.getStartOffset(), highlighterToSelect.getEndOffset());
        editor.getSelectionModel().setSelection(highlighterToSelect.getStartOffset(), highlighterToSelect.getEndOffset());
        editor.getCaretModel().moveToOffset(highlighterToSelect.getStartOffset());
        ScrollType scrollType;
        if (secondPass) {
            scrollType = isForward ? ScrollType.CENTER_UP : ScrollType.CENTER_DOWN;
        } else {
            scrollType = isForward ? ScrollType.CENTER_DOWN : ScrollType.CENTER_UP;
        }
        editor.getScrollingModel().scrollToCaret(scrollType);
        editor.putUserData(HIGHLIGHTER_WAS_NOT_FOUND_KEY, null);
        return true;
    }
    if (wasNotFound == null) {
        editor.putUserData(HIGHLIGHTER_WAS_NOT_FOUND_KEY, Boolean.TRUE);
        String message = FindBundle.message("find.highlight.no.more.highlights.found");
        if (isForward) {
            AnAction action = ActionManager.getInstance().getAction(IdeActions.ACTION_FIND_NEXT);
            String shortcutsText = KeymapUtil.getFirstKeyboardShortcutText(action);
            if (shortcutsText.isEmpty()) {
                message = FindBundle.message("find.search.again.from.top.action.message", message);
            } else {
                message = FindBundle.message("find.search.again.from.top.hotkey.message", message, shortcutsText);
            }
        } else {
            AnAction action = ActionManager.getInstance().getAction(IdeActions.ACTION_FIND_PREVIOUS);
            String shortcutsText = KeymapUtil.getFirstKeyboardShortcutText(action);
            if (shortcutsText.isEmpty()) {
                message = FindBundle.message("find.search.again.from.bottom.action.message", message);
            } else {
                message = FindBundle.message("find.search.again.from.bottom.hotkey.message", message, shortcutsText);
            }
        }
        JComponent component = HintUtil.createInformationLabel(message);
        final LightweightHint hint = new LightweightHint(component);
        HintManagerImpl.getInstanceImpl().showEditorHint(hint, editor, HintManager.UNDER, HintManager.HIDE_BY_ANY_KEY | HintManager.HIDE_BY_TEXT_CHANGE | HintManager.HIDE_BY_SCROLLING, 0, false);
        return true;
    }
    if (!secondPass) {
        offset = isForward ? 0 : editor.getDocument().getTextLength();
        return highlightNextHighlighter(highlighters, editor, offset, isForward, true);
    }
    return false;
}
Also used : RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) LightweightHint(com.intellij.ui.LightweightHint) AnAction(com.intellij.openapi.actionSystem.AnAction) LightweightHint(com.intellij.ui.LightweightHint)

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