com.intellij.openapi.editor.markup.RangeHighlighter Java Examples

The following examples show how to use com.intellij.openapi.editor.markup.RangeHighlighter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LSPDiagnosticsToMarkers.java    From intellij-quarkus with Eclipse Public License 2.0 6 votes vote down vote up
private void createMarkers(Editor editor, Document document, List<Diagnostic> diagnostics) {
    RangeHighlighter[] rangeHighlighters = new RangeHighlighter[diagnostics.size()];
    int index = 0;
    for(Diagnostic diagnostic : diagnostics) {
        int startOffset = LSPIJUtils.toOffset(diagnostic.getRange().getStart(), document);
        int endOffset = LSPIJUtils.toOffset(diagnostic.getRange().getEnd(), document);
        if (endOffset > document.getLineEndOffset(document.getLineCount() - 1)) {
            endOffset = document.getLineEndOffset(document.getLineCount() - 1);
        }
        int layer = getLayer(diagnostic.getSeverity());
        EffectType effectType = getEffectType(diagnostic.getSeverity());
        Color color = getColor(diagnostic.getSeverity());
        RangeHighlighter rangeHighlighter = editor.getMarkupModel().addRangeHighlighter(startOffset, endOffset, layer, new TextAttributes(editor.getColorsScheme().getDefaultForeground(), editor.getColorsScheme().getDefaultBackground(), color, effectType, Font.PLAIN), HighlighterTargetArea.EXACT_RANGE);
        rangeHighlighter.setErrorStripeTooltip(diagnostic);
        rangeHighlighters[index++] = rangeHighlighter;
    }
    Map<String, RangeHighlighter[]> allMarkers = getAllMarkers(editor);
    allMarkers.put(languageServerId, rangeHighlighters);

}
 
Example #2
Source File: DesktopEditorMarkupModelImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void getNearestHighlighters(MarkupModelEx markupModel, final int scrollBarY, final Collection<RangeHighlighter> nearest) {
  int startOffset = yPositionToOffset(scrollBarY - myMinMarkHeight, true);
  int endOffset = yPositionToOffset(scrollBarY + myMinMarkHeight, false);
  markupModel.processRangeHighlightersOverlappingWith(startOffset, endOffset, new Processor<RangeHighlighterEx>() {
    @Override
    public boolean process(RangeHighlighterEx highlighter) {
      if (highlighter.getErrorStripeMarkColor() != null) {
        ProperTextRange range = offsetsToYPositions(highlighter.getStartOffset(), highlighter.getEndOffset());
        if (scrollBarY >= range.getStartOffset() - myMinMarkHeight * 2 && scrollBarY <= range.getEndOffset() + myMinMarkHeight * 2) {
          nearest.add(highlighter);
        }
      }
      return true;
    }
  });
}
 
Example #3
Source File: EditorHyperlinkSupport.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
public Runnable getLinkNavigationRunnable(final LogicalPosition logical) {
  if (EditorUtil.inVirtualSpace(myEditor, logical)) {
    return null;
  }

  final RangeHighlighter range = findLinkRangeAt(myEditor.logicalPositionToOffset(logical));
  if (range != null) {
    final HyperlinkInfo hyperlinkInfo = getHyperlinkInfo(range);
    if (hyperlinkInfo != null) {
      return () -> {
        if (hyperlinkInfo instanceof HyperlinkInfoBase) {
          final Point point = myEditor.logicalPositionToXY(logical);
          final MouseEvent event = new MouseEvent(myEditor.getContentComponent(), 0, 0, 0, point.x, point.y, 1, false);
          ((HyperlinkInfoBase)hyperlinkInfo).navigate(myProject, new RelativePoint(event));
        }
        else {
          hyperlinkInfo.navigate(myProject);
        }
        linkFollowed(myEditor, getHyperlinks(0, myEditor.getDocument().getTextLength(), myEditor), range);
      };
    }
  }
  return null;
}
 
Example #4
Source File: FilteredIndentsHighlightingPass.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static void onWidgetIndentsChanged(EditorEx editor, WidgetIndentHitTester oldHitTester, WidgetIndentHitTester newHitTester) {
  final List<RangeHighlighter> highlighters = editor.getUserData(INDENT_HIGHLIGHTERS_IN_EDITOR_KEY);
  if (highlighters != null) {
    final Document doc = editor.getDocument();
    final int textLength = doc.getTextLength();
    for (RangeHighlighter highlighter : highlighters) {
      if (!highlighter.isValid()) {
        continue;
      }
      final LineRange range = getGuideLineRange(editor, highlighter);
      if (range != null) {
        final boolean before = WidgetIndentsHighlightingPass.isIndentGuideHidden(oldHitTester, range);
        final boolean after = WidgetIndentsHighlightingPass.isIndentGuideHidden(newHitTester, range);
        if (before != after) {
          int safeStart = min(highlighter.getStartOffset(), textLength);
          int safeEnd = min(highlighter.getEndOffset(), textLength);
          if (safeEnd > safeStart) {
            editor.repaint(safeStart, safeEnd);
          }
        }
      }
    }
  }
}
 
Example #5
Source File: InlinePreviewViewController.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void paint(@NotNull Editor editor, @NotNull RangeHighlighter highlighter, @NotNull Graphics g) {
  if (editor != getEditor()) {
    // Don't want to render on the wrong editor. This shouldn't happen.
    return;
  }
  if (getEditor().isPurePaintingMode()) {
    // Don't show previews in pure mode.
    return;
  }
  if (!highlighter.isValid()) {
    return;
  }
  if (getDescriptor() != null && !getDescriptor().widget.isValid()) {
    return;
  }
  final int lineHeight = editor.getLineHeight();
  paint(g, lineHeight);
}
 
Example #6
Source File: EditorHyperlinkSupport.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static void linkFollowed(Editor editor, Collection<? extends 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();
}
 
Example #7
Source File: ApplyPatchChange.java    From consulo with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #8
Source File: AbstractEditorAnnotation.java    From saros with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Removes all held range highlighters from the held editor and drops the held <code>Editor</code>
 * and all held <code>RangeHighlighter</code> references.
 *
 * <p>Does nothing if no editor is present.
 *
 * <p>This method should be used to remove the local representation of the annotation when the
 * editor for the corresponding file is closed.
 */
void removeLocalRepresentation() {
  if (editor == null) {
    return;
  }

  for (AnnotationRange annotationRange : annotationRanges) {
    RangeHighlighter rangeHighlighter = annotationRange.getRangeHighlighter();

    annotationRange.removeRangeHighlighter();

    if (rangeHighlighter == null || !rangeHighlighter.isValid()) {
      continue;
    }

    removeRangeHighlighter(editor, rangeHighlighter);
  }

  editor = null;
}
 
Example #9
Source File: FindManagerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
private boolean findNextUsageInFile(@Nonnull FileEditor fileEditor, @Nonnull SearchResults.Direction direction) {
  if (fileEditor instanceof TextEditor) {
    TextEditor textEditor = (TextEditor)fileEditor;
    Editor editor = textEditor.getEditor();
    editor.getCaretModel().removeSecondaryCarets();
    if (tryToFindNextUsageViaEditorSearchComponent(editor, direction)) {
      return true;
    }

    RangeHighlighter[] highlighters = ((HighlightManagerImpl)HighlightManager.getInstance(myProject)).getHighlighters(editor);
    if (highlighters.length > 0) {
      return highlightNextHighlighter(highlighters, editor, editor.getCaretModel().getOffset(), direction == SearchResults.Direction.DOWN, false);
    }
  }

  if (direction == SearchResults.Direction.DOWN) {
    return myFindUsagesManager.findNextUsageInFile(fileEditor);
  }
  return myFindUsagesManager.findPreviousUsageInFile(fileEditor);
}
 
Example #10
Source File: AnnotationManagerTest.java    From saros with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Mocks the method creating the actual range highlighters in the editor for the list of given
 * ranges to return the given range highlighter.
 *
 * <p>{@link #prepareMockAddRemoveRangeHighlighters()} must be called before the first call to
 * this methods and {@link #replayMockAddRemoveRangeHighlighters()} must be called after the last
 * call to this method to replay the added mocking logic.
 *
 * @param rangePairs the pairs of ranges and their highlighters with which to create the mock
 * @param textAttributes the text attributes of the annotation; either {@link
 *     #selectionTextAttributes} or {@link #contributionTextAttributes}
 * @param file the file of the annotation
 * @throws Exception see {@link PowerMock#expectPrivate(Object, Method, Object...)}
 */
private void mockAddRangeHighlightersWithGivenRangeHighlighters(
    List<Pair<Pair<Integer, Integer>, RangeHighlighter>> rangePairs,
    TextAttributes textAttributes,
    IFile file)
    throws Exception {

  for (Pair<Pair<Integer, Integer>, RangeHighlighter> rangePair : rangePairs) {
    Pair<Integer, Integer> range = rangePair.getLeft();

    RangeHighlighter rangeHighlighter = rangePair.getRight();

    int rangeStart = range.getLeft();
    int rangeEnd = range.getRight();

    PowerMock.expectPrivate(
            AbstractEditorAnnotation.class,
            "addRangeHighlighter",
            rangeStart,
            rangeEnd,
            editor,
            textAttributes,
            file)
        .andStubReturn(rangeHighlighter);
  }
}
 
Example #11
Source File: AnnotationManagerTest.java    From saros with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Calls {@link #mockAddContributionRangeHighlightersWithGivenRangeHighlighters(List)} with an
 * internally created list of mocked range highlighters.
 */
private void mockAddRangeHighlighters(
    List<Pair<Integer, Integer>> ranges, TextAttributes textAttributes, IFile file)
    throws Exception {

  List<Pair<Pair<Integer, Integer>, RangeHighlighter>> rangePairs =
      new ArrayList<>(ranges.size());

  for (Pair<Integer, Integer> range : ranges) {
    RangeHighlighter rangeHighlighter = mockRangeHighlighter(range.getLeft(), range.getRight());

    rangePairs.add(new ImmutablePair<>(range, rangeHighlighter));
  }

  mockAddRangeHighlightersWithGivenRangeHighlighters(rangePairs, textAttributes, file);
}
 
Example #12
Source File: InlinePreviewViewController.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void paint(@NotNull Editor editor, @NotNull RangeHighlighter highlighter, @NotNull Graphics g) {
  if (editor != getEditor()) {
    // Don't want to render on the wrong editor. This shouldn't happen.
    return;
  }
  if (getEditor().isPurePaintingMode()) {
    // Don't show previews in pure mode.
    return;
  }
  if (!highlighter.isValid()) {
    return;
  }
  if (getDescriptor() != null && !getDescriptor().widget.isValid()) {
    return;
  }
  final int lineHeight = editor.getLineHeight();
  paint(g, lineHeight);
}
 
Example #13
Source File: HighlightersRecycler.java    From consulo with Apache License 2.0 5 votes vote down vote up
RangeHighlighter pickupHighlighterFromGarbageBin(int startOffset, int endOffset, int layer){
  TextRange range = new TextRange(startOffset, endOffset);
  Collection<RangeHighlighter> collection = incinerator.get(range);
  for (RangeHighlighter highlighter : collection) {
    if (highlighter.isValid() && highlighter.getLayer() == layer) {
      incinerator.remove(range, highlighter);
      return highlighter;
    }
  }
  return null;
}
 
Example #14
Source File: UnifiedDiffChange.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private MyGutterOperation createOperation(@Nonnull Side sourceSide) {
  int offset = myEditor.getDocument().getLineStartOffset(myLine1);
  RangeHighlighter highlighter = myEditor.getMarkupModel().addRangeHighlighter(offset, offset,
                                                                               HighlighterLayer.ADDITIONAL_SYNTAX,
                                                                               null,
                                                                               HighlighterTargetArea.LINES_IN_RANGE);
  return new MyGutterOperation(sourceSide, highlighter);
}
 
Example #15
Source File: SimpleOnesideDiffViewer.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void clearDiffPresentation() {
  myPanel.resetNotifications();

  for (RangeHighlighter highlighter : myHighlighters) {
    highlighter.dispose();
  }
  myHighlighters.clear();
}
 
Example #16
Source File: IdentifierHighlighterPass.java    From consulo with Apache License 2.0 5 votes vote down vote up
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();
    }
  }
}
 
Example #17
Source File: MarkupModelImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void removeHighlighter(@Nonnull RangeHighlighter segmentHighlighter) {
  ApplicationManager.getApplication().assertIsDispatchThread();
  myCachedHighlighters = null;
  if (!segmentHighlighter.isValid()) return;

  boolean removed = treeFor(segmentHighlighter).removeInterval((RangeHighlighterEx)segmentHighlighter);
  LOG.assertTrue(removed);
}
 
Example #18
Source File: AbstractEditorAnnotation.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Removes the given range highlighter from the given editor.
 *
 * @param editor the editor from which to remove the range highlighter
 * @param rangeHighlighter the range highlighter to remove
 */
static void removeRangeHighlighter(
    @NotNull Editor editor, @NotNull RangeHighlighter rangeHighlighter) {
  EDTExecutor.invokeAndWait(
      () -> editor.getMarkupModel().removeHighlighter(rangeHighlighter),
      ModalityState.defaultModalityState());
}
 
Example #19
Source File: MyActionUtils.java    From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static DecisionEventInfo getHighlighterWithDecisionEventType(List<RangeHighlighter> highlighters, Class decisionEventType) {
	for (RangeHighlighter r : highlighters) {
		DecisionEventInfo eventInfo = r.getUserData(ProfilerPanel.DECISION_EVENT_INFO_KEY);
		if (eventInfo != null) {
			if (eventInfo.getClass() == decisionEventType) {
				return eventInfo;
			}
		}
	}
	return null;
}
 
Example #20
Source File: HighlightData.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void addHighlToView(final Editor view, EditorColorsScheme scheme, final Map<TextAttributesKey,String> displayText) {

    // XXX: Hack
    if (HighlighterColors.BAD_CHARACTER.equals(myHighlightType)) {
      return;
    }

    final TextAttributes attr = scheme.getAttributes(myHighlightType);
    if (attr != null) {
      UIUtil.invokeAndWaitIfNeeded((Runnable)() -> {
        try {
          // IDEA-53203: add ERASE_MARKER for manually defined attributes
          view.getMarkupModel().addRangeHighlighter(myStartOffset, myEndOffset, HighlighterLayer.ADDITIONAL_SYNTAX,
                                                    TextAttributes.ERASE_MARKER, HighlighterTargetArea.EXACT_RANGE);
          RangeHighlighter highlighter = view.getMarkupModel()
                  .addRangeHighlighter(myStartOffset, myEndOffset, HighlighterLayer.ADDITIONAL_SYNTAX, attr,
                                       HighlighterTargetArea.EXACT_RANGE);
          final Color errorStripeColor = attr.getErrorStripeColor();
          highlighter.setErrorStripeMarkColor(errorStripeColor);
          final String tooltip = displayText.get(myHighlightType);
          highlighter.setErrorStripeTooltip(tooltip);
        }
        catch (Exception e) {
          throw new RuntimeException(e);
        }
      });
    }
  }
 
Example #21
Source File: AnnotationRange.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new <code>AnnotationRange</code> with the given position. If there is currently no
 * local representation for the <code>AnnotationRange</code>, <code>null</code> should be passe as
 * the <code>RangeHighlighter</code>.
 *
 * <p>Both the given start and end point have to be positive integers. Furthermore, the start
 * position has to be smaller as or equal to the end position. If a <code>RangeHighlighter</code>
 * is given, it must match the given start and end position.
 *
 * @param start the start point of the annotation range
 * @param end the end point of the annotation range
 * @param rangeHighlighter the representation of the annotated text in a local editor
 */
AnnotationRange(int start, int end, @Nullable RangeHighlighter rangeHighlighter) {

  if (start < 0 || end < 0) {
    throw new IllegalArgumentException(
        "The start and end of the annotation must not be negative "
            + "values. start: "
            + start
            + ", end: "
            + end);
  }

  if (start > end) {
    throw new IllegalArgumentException(
        "The start of the annotation must not be after the end of the "
            + "annotation. start: "
            + start
            + ", end: "
            + end);
  }

  if (rangeHighlighter != null) {
    if (!rangeHighlighter.isValid()) {
      throw new IllegalArgumentException(
          "The given RangeHighlighter for the range (" + start + "," + end + ") is invalid");

    } else if (start != rangeHighlighter.getStartOffset()
        || end != rangeHighlighter.getEndOffset()) {

      throw new IllegalArgumentException(
          "The range of the given RangeHighlighter does not match the given start and end value");
    }
  }

  this.start = start;
  this.end = end;
  this.rangeHighlighter = rangeHighlighter;
}
 
Example #22
Source File: XBreakpointPanelProvider.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public GutterIconRenderer getBreakpointGutterIconRenderer(Object breakpoint) {
  if (breakpoint instanceof XLineBreakpointImpl) {
    RangeHighlighter highlighter = ((XLineBreakpointImpl)breakpoint).getHighlighter();
    if (highlighter != null) {
      return (GutterIconRenderer)highlighter.getGutterIconRenderer();
    }
  }
  return null;
}
 
Example #23
Source File: SimpleOnesideDiffViewer.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@RequiredUIAccess
protected void onDispose() {
  for (RangeHighlighter highlighter : myHighlighters) {
    highlighter.dispose();
  }
  myHighlighters.clear();
  super.onDispose();
}
 
Example #24
Source File: BreadcrumbsWrapper.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void itemHovered(Crumb crumb, @SuppressWarnings("unused") InputEvent event) {
  if (!Registry.is("editor.breadcrumbs.highlight.on.hover")) {
    return;
  }

  HighlightManager hm = HighlightManager.getInstance(myProject);
  if (myHighlighed != null) {
    for (RangeHighlighter highlighter : myHighlighed) {
      hm.removeSegmentHighlighter(myEditor, highlighter);
    }
    myHighlighed = null;
  }
  if (crumb instanceof NavigatableCrumb) {
    final TextRange range = ((NavigatableCrumb)crumb).getHighlightRange();
    if (range == null) return;
    final TextAttributes attributes = new TextAttributes();
    final CrumbPresentation p = PsiCrumb.getPresentation(crumb);
    Color color = p == null ? null : p.getBackgroundColor(false, false, false);
    if (color == null) color = BreadcrumbsComponent.ButtonSettings.getBackgroundColor(false, false, false, false);
    if (color == null) color = UIUtil.getLabelBackground();
    final Color background = EditorColorsManager.getInstance().getGlobalScheme().getColor(EditorColors.CARET_ROW_COLOR);
    attributes.setBackgroundColor(makeTransparent(color, background != null ? background : Gray._200, 0.3));
    myHighlighed = new ArrayList<>(1);
    int flags = HighlightManager.HIDE_BY_ESCAPE | HighlightManager.HIDE_BY_TEXT_CHANGE | HighlightManager.HIDE_BY_ANY_KEY;
    hm.addOccurrenceHighlight(myEditor, range.getStartOffset(), range.getEndOffset(), attributes, flags, myHighlighed, null);
  }
}
 
Example #25
Source File: MarkupModelImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@Nonnull
public RangeHighlighter[] getAllHighlighters() {
  ApplicationManager.getApplication().assertIsDispatchThread();
  if (myCachedHighlighters == null) {
    int size = myHighlighterTree.size() + myHighlighterTreeForLines.size();
    if (size == 0) return RangeHighlighter.EMPTY_ARRAY;
    List<RangeHighlighterEx> list = new ArrayList<>(size);
    CommonProcessors.CollectProcessor<RangeHighlighterEx> collectProcessor = new CommonProcessors.CollectProcessor<>(list);
    myHighlighterTree.processAll(collectProcessor);
    myHighlighterTreeForLines.processAll(collectProcessor);
    myCachedHighlighters = list.toArray(RangeHighlighter.EMPTY_ARRAY);
  }
  return myCachedHighlighters;
}
 
Example #26
Source File: CommentsDiffTool.java    From review-board-idea-plugin with Apache License 2.0 5 votes vote down vote up
private void updateHighLights(Editor editor) {
    MarkupModel markup = editor.getMarkupModel();

    for (RangeHighlighter customRangeHighlighter : newCommentHighlighters) {
        markup.removeHighlighter(customRangeHighlighter);
    }
    newCommentHighlighters.clear();

    int lineCount = markup.getDocument().getLineCount();

    Map<Integer, List<Comment>> lineComments = lineComments(comments);
    for (Map.Entry<Integer, List<Comment>> entry : lineComments.entrySet()) {
        if (entry.getKey() > lineCount) continue;

        boolean hasNewComments = false;
        for (Comment comment : entry.getValue()) {
            if (comment.id == null) {
                hasNewComments = true;
                break;
            }
        }

        TextAttributes attributes = new TextAttributes();
        if (hasNewComments) attributes.setBackgroundColor(JBColor.PINK);
        else attributes.setBackgroundColor(JBColor.YELLOW);

        RangeHighlighter rangeHighlighter = markup
                .addLineHighlighter(entry.getKey() - 1, HighlighterLayer.SELECTION + (hasNewComments ? 2 : 1), attributes);
        rangeHighlighter.setGutterIconRenderer(new CommentGutterIconRenderer());
        newCommentHighlighters.add(rangeHighlighter);
    }
}
 
Example #27
Source File: HighlightCommand.java    From CppTools with Apache License 2.0 5 votes vote down vote up
private static RangeHighlighter processHighlighter(int hFrom, int hTo, int colorIndex, TextAttributes attrs,
                                                   Editor editor, TIntObjectHashMap<RangeHighlighter> lastOffsetToMarkersMap,
                                                   THashSet<RangeHighlighter> highlightersSet,
                                                   THashSet<RangeHighlighter> invalidMarkersSet
                                                   ) {
  RangeHighlighter rangeHighlighter = lastOffsetToMarkersMap.get(hFrom);

  if (rangeHighlighter == null ||
      rangeHighlighter.getEndOffset() != hTo ||
      rangeHighlighter.getTextAttributes() != attrs
      ) {
    highlightersSet.add(
      rangeHighlighter = HighlightUtils.createRangeMarker(
        editor,
        hFrom,
        hTo,
        colorIndex,
        attrs
      )
    );

    lastOffsetToMarkersMap.put(hFrom, rangeHighlighter);
  } else {
    highlightersSet.add(rangeHighlighter);
    invalidMarkersSet.remove(rangeHighlighter);
  }

  return rangeHighlighter;
}
 
Example #28
Source File: ConsoleLogConsole.java    From aem-ide-tooling-4-intellij with Apache License 2.0 5 votes vote down vote up
@Nullable
public RelativePoint getRangeHighlighterLocation(RangeHighlighter range) {
    Editor editor = myLogEditor.getValue();
    Project project = editor.getProject();
    Window window = NotificationsManagerImpl.findWindowForBalloon(project);
    if (range != null && window != null) {
        Point point = editor.visualPositionToXY(editor.offsetToVisualPosition(range.getStartOffset()));
        return new RelativePoint(window, SwingUtilities.convertPoint(editor.getContentComponent(), point, window));
    }
    return null;
}
 
Example #29
Source File: InplaceRefactoring.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected void addHighlights(@Nonnull Map<TextRange, TextAttributes> ranges,
                             @Nonnull Editor editor,
                             @Nonnull Collection<RangeHighlighter> highlighters,
                             @Nonnull HighlightManager highlightManager) {
  for (Map.Entry<TextRange, TextAttributes> entry : ranges.entrySet()) {
    TextRange range = entry.getKey();
    TextAttributes attributes = entry.getValue();
    highlightManager.addOccurrenceHighlight(editor, range.getStartOffset(), range.getEndOffset(), attributes, 0, highlighters, null);
  }

  for (RangeHighlighter highlighter : highlighters) {
    highlighter.setGreedyToLeft(true);
    highlighter.setGreedyToRight(true);
  }
}
 
Example #30
Source File: TemplateState.java    From consulo with Apache License 2.0 5 votes vote down vote up
private RangeHighlighter getSegmentHighlighter(int segmentNumber, boolean isSelected, boolean isEnd) {
  final TextAttributes lvAttr = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(EditorColors.LIVE_TEMPLATE_ATTRIBUTES);
  TextAttributes attributes = isSelected ? lvAttr : new TextAttributes();
  TextAttributes endAttributes = new TextAttributes();

  int start = mySegments.getSegmentStart(segmentNumber);
  int end = mySegments.getSegmentEnd(segmentNumber);
  RangeHighlighter segmentHighlighter = myEditor.getMarkupModel()
          .addRangeHighlighter(start, end, HighlighterLayer.LAST + 1, isEnd ? endAttributes : attributes, HighlighterTargetArea.EXACT_RANGE);
  segmentHighlighter.setGreedyToLeft(true);
  segmentHighlighter.setGreedyToRight(true);
  return segmentHighlighter;
}