Search in sources :

Example 31 with RangeHighlighter

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

the class EditorHyperlinkSupport method linkFollowed.

// todo fix link followed here!
private static void linkFollowed(Editor editor, Collection<RangeHighlighter> ranges, final RangeHighlighter link) {
    MarkupModelEx markupModel = (MarkupModelEx) editor.getMarkupModel();
    for (RangeHighlighter range : ranges) {
        TextAttributes oldAttr = range.getUserData(OLD_HYPERLINK_TEXT_ATTRIBUTES);
        if (oldAttr != null) {
            markupModel.setRangeHighlighterAttributes(range, oldAttr);
            range.putUserData(OLD_HYPERLINK_TEXT_ATTRIBUTES, null);
        }
        if (range == link) {
            range.putUserData(OLD_HYPERLINK_TEXT_ATTRIBUTES, range.getTextAttributes());
            markupModel.setRangeHighlighterAttributes(range, getFollowedHyperlinkAttributes(range));
        }
    }
    //refresh highlighter text attributes
    markupModel.addRangeHighlighter(0, 0, link.getLayer(), getHyperlinkAttributes(), HighlighterTargetArea.EXACT_RANGE).dispose();
}
Also used : RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) MarkupModelEx(com.intellij.openapi.editor.ex.MarkupModelEx) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes)

Example 32 with RangeHighlighter

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

the class EditorHyperlinkSupport method getHyperlinks.

private static List<RangeHighlighter> getHyperlinks(int startOffset, int endOffset, final Editor editor) {
    final MarkupModelEx markupModel = (MarkupModelEx) editor.getMarkupModel();
    final CommonProcessors.CollectProcessor<RangeHighlighterEx> processor = new CommonProcessors.CollectProcessor<>();
    markupModel.processRangeHighlightersOverlappingWith(startOffset, endOffset, new FilteringProcessor<>(rangeHighlighterEx -> rangeHighlighterEx.isValid() && getHyperlinkInfo(rangeHighlighterEx) != null, processor));
    return new ArrayList<>(processor.getResults());
}
Also used : EditorMouseAdapter(com.intellij.openapi.editor.event.EditorMouseAdapter) UIUtil(com.intellij.util.ui.UIUtil) HyperlinkInfoBase(com.intellij.execution.filters.HyperlinkInfoBase) Document(com.intellij.openapi.editor.Document) EditorUtil(com.intellij.openapi.editor.ex.util.EditorUtil) EditorColorsManager(com.intellij.openapi.editor.colors.EditorColorsManager) MarkupModelEx(com.intellij.openapi.editor.ex.MarkupModelEx) LinkedHashMap(com.intellij.util.containers.hash.LinkedHashMap) ArrayList(java.util.ArrayList) NavigatableAdapter(com.intellij.pom.NavigatableAdapter) FilteringProcessor(com.intellij.util.FilteringProcessor) CodeInsightColors(com.intellij.openapi.editor.colors.CodeInsightColors) RangeHighlighterEx(com.intellij.openapi.editor.ex.RangeHighlighterEx) HighlighterLayer(com.intellij.openapi.editor.markup.HighlighterLayer) Map(java.util.Map) RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) Project(com.intellij.openapi.project.Project) EditorEx(com.intellij.openapi.editor.ex.EditorEx) OccurenceNavigator(com.intellij.ide.OccurenceNavigator) CommonProcessors(com.intellij.util.CommonProcessors) Filter(com.intellij.execution.filters.Filter) Collection(java.util.Collection) Key(com.intellij.openapi.util.Key) Editor(com.intellij.openapi.editor.Editor) LogicalPosition(com.intellij.openapi.editor.LogicalPosition) MouseMotionAdapter(java.awt.event.MouseMotionAdapter) MouseEvent(java.awt.event.MouseEvent) EditorMouseEvent(com.intellij.openapi.editor.event.EditorMouseEvent) HighlighterTargetArea(com.intellij.openapi.editor.markup.HighlighterTargetArea) java.awt(java.awt) HyperlinkInfo(com.intellij.execution.filters.HyperlinkInfo) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) NotNull(org.jetbrains.annotations.NotNull) RelativePoint(com.intellij.ui.awt.RelativePoint) Consumer(com.intellij.util.Consumer) MarkupModelEx(com.intellij.openapi.editor.ex.MarkupModelEx) RangeHighlighterEx(com.intellij.openapi.editor.ex.RangeHighlighterEx) ArrayList(java.util.ArrayList) CommonProcessors(com.intellij.util.CommonProcessors)

Example 33 with RangeHighlighter

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

the class EditorHyperlinkSupport method getNextOccurrence.

@Nullable
public static OccurenceNavigator.OccurenceInfo getNextOccurrence(final Editor editor, final int delta, final Consumer<RangeHighlighter> action) {
    final List<RangeHighlighter> ranges = getHyperlinks(0, editor.getDocument().getTextLength(), editor);
    if (ranges.isEmpty()) {
        return null;
    }
    int i;
    for (i = 0; i < ranges.size(); i++) {
        RangeHighlighter range = ranges.get(i);
        if (range.getUserData(OLD_HYPERLINK_TEXT_ATTRIBUTES) != null) {
            break;
        }
    }
    i %= ranges.size();
    int newIndex = i;
    while (newIndex < ranges.size() && newIndex >= 0) {
        newIndex = (newIndex + delta + ranges.size()) % ranges.size();
        final RangeHighlighter next = ranges.get(newIndex);
        HyperlinkInfo info = getHyperlinkInfo(next);
        assert info != null;
        if (info.includeInOccurenceNavigation()) {
            boolean inCollapsedRegion = editor.getFoldingModel().getCollapsedRegionAtOffset(next.getStartOffset()) != null;
            if (!inCollapsedRegion) {
                return new OccurenceNavigator.OccurenceInfo(new NavigatableAdapter() {

                    @Override
                    public void navigate(final boolean requestFocus) {
                        action.consume(next);
                        linkFollowed(editor, ranges, next);
                    }
                }, newIndex == -1 ? -1 : newIndex + 1, ranges.size());
            }
        }
        if (newIndex == i) {
            // cycled through everything, found no next/prev hyperlink
            break;
        }
    }
    return null;
}
Also used : RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) NavigatableAdapter(com.intellij.pom.NavigatableAdapter) RelativePoint(com.intellij.ui.awt.RelativePoint) HyperlinkInfo(com.intellij.execution.filters.HyperlinkInfo) Nullable(org.jetbrains.annotations.Nullable)

Example 34 with RangeHighlighter

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

the class RangeMarkerTest method testRangeHighlighterIteratorOrder.

public void testRangeHighlighterIteratorOrder() throws Exception {
    Document document = EditorFactory.getInstance().createDocument("1234567890");
    final MarkupModelEx markupModel = (MarkupModelEx) DocumentMarkupModel.forDocument(document, ourProject, true);
    RangeHighlighter exact = markupModel.addRangeHighlighter(3, 6, 0, null, HighlighterTargetArea.EXACT_RANGE);
    RangeHighlighter line = markupModel.addRangeHighlighter(4, 5, 0, null, HighlighterTargetArea.LINES_IN_RANGE);
    List<RangeHighlighter> list = new ArrayList<>();
    markupModel.processRangeHighlightersOverlappingWith(2, 9, new CommonProcessors.CollectProcessor<>(list));
    assertEquals(Arrays.asList(line, exact), list);
}
Also used : RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) MarkupModelEx(com.intellij.openapi.editor.ex.MarkupModelEx) CommonProcessors(com.intellij.util.CommonProcessors)

Example 35 with RangeHighlighter

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

the class IdentifierHighlighterPass method clearMyHighlights.

public static void clearMyHighlights(Document document, Project project) {
    MarkupModel markupModel = DocumentMarkupModel.forDocument(document, project, true);
    for (RangeHighlighter highlighter : markupModel.getAllHighlighters()) {
        Object tooltip = highlighter.getErrorStripeTooltip();
        if (!(tooltip instanceof HighlightInfo)) {
            continue;
        }
        HighlightInfo info = (HighlightInfo) tooltip;
        if (info.type == HighlightInfoType.ELEMENT_UNDER_CARET_READ || info.type == HighlightInfoType.ELEMENT_UNDER_CARET_WRITE) {
            highlighter.dispose();
        }
    }
}
Also used : RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) DocumentMarkupModel(com.intellij.openapi.editor.impl.DocumentMarkupModel) MarkupModel(com.intellij.openapi.editor.markup.MarkupModel)

Aggregations

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