Java Code Examples for com.intellij.openapi.editor.ex.MarkupModelEx#processRangeHighlightersOverlappingWith()

The following examples show how to use com.intellij.openapi.editor.ex.MarkupModelEx#processRangeHighlightersOverlappingWith() . 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: UnifiedEditorRangeHighlighter.java    From consulo with Apache License 2.0 6 votes vote down vote up
public UnifiedEditorRangeHighlighter(@javax.annotation.Nullable Project project, @Nonnull Document document) {
  ApplicationManager.getApplication().assertReadAccessAllowed();

  MarkupModelEx model = (MarkupModelEx)DocumentMarkupModel.forDocument(document, project, false);
  if (model == null) return;

  model.processRangeHighlightersOverlappingWith(0, document.getTextLength(), new Processor<RangeHighlighterEx>() {
    @Override
    public boolean process(RangeHighlighterEx marker) {
      int newStart = marker.getStartOffset();
      int newEnd = marker.getEndOffset();

      myPieces.add(new Element(marker, newStart, newEnd));

      return true;
    }
  });
}
 
Example 2
Source File: UnifiedEditorRangeHighlighter.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void processRange(@Nonnull MarkupModelEx model, @Nonnull HighlightRange range) {
  final TextRange base = range.getBase();
  final TextRange changed = range.getChanged();
  final int changedLength = changed.getEndOffset() - changed.getStartOffset();

  model.processRangeHighlightersOverlappingWith(changed.getStartOffset(), changed.getEndOffset(), new Processor<RangeHighlighterEx>() {
    @Override
    public boolean process(RangeHighlighterEx marker) {
      int relativeStart = Math.max(marker.getStartOffset() - changed.getStartOffset(), 0);
      int relativeEnd = Math.min(marker.getEndOffset() - changed.getStartOffset(), changedLength);

      int newStart = base.getStartOffset() + relativeStart;
      int newEnd = base.getStartOffset() + relativeEnd;

      if (newEnd - newStart <= 0) return true;

      myPieces.add(new Element(marker, newStart, newEnd));

      return true;
    }
  });
}
 
Example 3
Source File: DaemonCodeAnalyzerEx.java    From consulo with Apache License 2.0 6 votes vote down vote up
/**
 *
 * @param document
 * @param project
 * @param minSeverity null means all
 * @param startOffset
 * @param endOffset
 * @param processor
 * @return
 */
public static boolean processHighlights(@Nonnull Document document,
                                        @Nonnull Project project,
                                        @javax.annotation.Nullable final HighlightSeverity minSeverity,
                                        final int startOffset,
                                        final int endOffset,
                                        @Nonnull final Processor<HighlightInfo> processor) {
  LOG.assertTrue(ApplicationManager.getApplication().isReadAccessAllowed());

  final SeverityRegistrar severityRegistrar = SeverityRegistrar.getSeverityRegistrar(project);
  MarkupModelEx model = (MarkupModelEx)DocumentMarkupModel.forDocument(document, project, true);
  return model.processRangeHighlightersOverlappingWith(startOffset, endOffset, marker -> {
    Object tt = marker.getErrorStripeTooltip();
    if (!(tt instanceof HighlightInfo)) return true;
    HighlightInfo info = (HighlightInfo)tt;
    return minSeverity != null && severityRegistrar.compare(info.getSeverity(), minSeverity) < 0
           || info.highlighter == null
           || processor.process(info);
  });
}
 
Example 4
Source File: RangeMarkerTest.java    From consulo with Apache License 2.0 5 votes vote down vote up
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<RangeHighlighter>();
  markupModel.processRangeHighlightersOverlappingWith(2, 9, new CommonProcessors.CollectProcessor<RangeHighlighter>(list));
  assertEquals(Arrays.asList(line, exact), list);
}
 
Example 5
Source File: EditorPainter.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void paintLineMarkersSeparators(MarkupModelEx markupModel) {
  // we decrement startOffset to capture also line-range highlighters on the previous line,
  // cause they can render a separator visible on current line
  markupModel.processRangeHighlightersOverlappingWith(myStartOffset - 1, myEndOffset, highlighter -> {
    paintLineMarkerSeparator(highlighter);
    return true;
  });
}
 
Example 6
Source File: EditorPainter.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void collectVisibleInnerHighlighters(@Nonnull FoldRegion region, @Nonnull MarkupModelEx markupModel, @Nonnull List<? super RangeHighlighterEx> highlighters) {
  int startOffset = region.getStartOffset();
  int endOffset = region.getEndOffset();
  markupModel.processRangeHighlightersOverlappingWith(startOffset, endOffset, h -> {
    if (h.isVisibleIfFolded() && h.getAffectedAreaStartOffset() >= startOffset && h.getAffectedAreaEndOffset() <= endOffset) {
      highlighters.add(h);
    }
    return true;
  });
}
 
Example 7
Source File: EditorPainter.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void paintHighlightersAfterEndOfLine(MarkupModelEx markupModel) {
  markupModel.processRangeHighlightersOverlappingWith(myStartOffset, myEndOffset, highlighter -> {
    if (highlighter.getStartOffset() >= myStartOffset) {
      paintHighlighterAfterEndOfLine(highlighter);
    }
    return true;
  });
}
 
Example 8
Source File: EditorPainter.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void paintBorderEffect(MarkupModelEx markupModel) {
  markupModel.processRangeHighlightersOverlappingWith(myStartOffset, myEndOffset, rangeHighlighter -> {
    TextAttributes attributes = rangeHighlighter.getTextAttributes();
    EffectDescriptor borderDescriptor = getBorderDescriptor(attributes);
    if (borderDescriptor != null) {
      paintBorderEffect(rangeHighlighter.getAffectedAreaStartOffset(), rangeHighlighter.getAffectedAreaEndOffset(), borderDescriptor);
    }
    return true;
  });
}
 
Example 9
Source File: EditorHyperlinkSupport.java    From consulo with Apache License 2.0 5 votes vote down vote up
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());
}
 
Example 10
Source File: LineMarkersUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
static boolean processLineMarkers(@Nonnull Project project, @Nonnull Document document, @Nonnull Segment bounds, int group, // -1 for all
                                  @Nonnull Processor<? super LineMarkerInfo<?>> processor) {
  MarkupModelEx markupModel = (MarkupModelEx)DocumentMarkupModel.forDocument(document, project, true);
  return markupModel.processRangeHighlightersOverlappingWith(bounds.getStartOffset(), bounds.getEndOffset(), highlighter -> {
    LineMarkerInfo<?> info = getLineMarkerInfo(highlighter);
    return info == null || group != -1 && info.updatePass != group || processor.process(info);
  });
}
 
Example 11
Source File: LineMarkersUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
static void addLineMarkerToEditorIncrementally(@Nonnull Project project, @Nonnull Document document, @Nonnull LineMarkerInfo<?> marker) {
  ApplicationManager.getApplication().assertIsDispatchThread();

  MarkupModelEx markupModel = (MarkupModelEx)DocumentMarkupModel.forDocument(document, project, true);
  LineMarkerInfo<?>[] markerInTheWay = {null};
  boolean allIsClear = markupModel.processRangeHighlightersOverlappingWith(marker.startOffset, marker.endOffset, highlighter -> (markerInTheWay[0] = getLineMarkerInfo(highlighter)) == null);
  if (allIsClear) {
    createOrReuseLineMarker(marker, markupModel, null);
  }
  if (LOG.isDebugEnabled()) {
    LOG.debug("LineMarkersUtil.addLineMarkerToEditorIncrementally: " + marker + " " + (allIsClear ? "created" : " (was not added because " + markerInTheWay[0] + " was in the way)"));
  }
}
 
Example 12
Source File: GutterIntentionMenuContributor.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void collectActions(@Nonnull Editor hostEditor, @Nonnull PsiFile hostFile, @Nonnull ShowIntentionsPass.IntentionsInfo intentions, int passIdToShowIntentionsFor, int offset) {
  final Project project = hostFile.getProject();
  final Document hostDocument = hostEditor.getDocument();
  final int line = hostDocument.getLineNumber(offset);
  MarkupModelEx model = (MarkupModelEx)DocumentMarkupModel.forDocument(hostDocument, project, true);
  List<RangeHighlighterEx> result = new ArrayList<>();
  Processor<RangeHighlighterEx> processor = Processors.cancelableCollectProcessor(result);
  model.processRangeHighlightersOverlappingWith(hostDocument.getLineStartOffset(line), hostDocument.getLineEndOffset(line), processor);

  for (RangeHighlighterEx highlighter : result) {
    addActions(project, highlighter, intentions.guttersToShow, ((EditorEx)hostEditor).getDataContext());
  }
}
 
Example 13
Source File: ConsoleViewImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private RangeMarker findTokenMarker(int offset) {
  RangeMarker[] marker = new RangeMarker[1];
  MarkupModelEx model = (MarkupModelEx)DocumentMarkupModel.forDocument(myEditor.getDocument(), getProject(), true);
  model.processRangeHighlightersOverlappingWith(offset, offset, m -> {
    if (getTokenType(m) == null || m.getStartOffset() > offset || offset + 1 > m.getEndOffset()) return true;
    marker[0] = m;
    return false;
  });

  return marker[0];
}
 
Example 14
Source File: LivePreview.java    From consulo with Apache License 2.0 5 votes vote down vote up
private RangeHighlighter findExistingHighlighter(int startOffset, int endOffset, TextAttributes attributes) {
  MarkupModelEx markupModel = (MarkupModelEx)mySearchResults.getEditor().getMarkupModel();
  RangeHighlighter[] existing = new RangeHighlighter[1];
  markupModel.processRangeHighlightersOverlappingWith(startOffset, startOffset, highlighter -> {
    if (highlighter.getUserData(SEARCH_MARKER) != null &&
        highlighter.getStartOffset() == startOffset && highlighter.getEndOffset() == endOffset &&
        Objects.equals(highlighter.getTextAttributes(), attributes)) {
      existing[0] = highlighter;
      return false;
    }
    return true;
  });
  return existing[0];
}
 
Example 15
Source File: Bookmark.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void release() {
  int line = getLine();
  if (line < 0) {
    return;
  }
  final Document document = getDocument();
  if (document == null) return;
  MarkupModelEx markup = (MarkupModelEx)DocumentMarkupModel.forDocument(document, myProject, true);
  final Document markupDocument = markup.getDocument();
  if (markupDocument.getLineCount() <= line) return;
  final int startOffset = markupDocument.getLineStartOffset(line);
  final int endOffset = markupDocument.getLineEndOffset(line);

  final Ref<RangeHighlighterEx> found = new Ref<RangeHighlighterEx>();
  markup.processRangeHighlightersOverlappingWith(startOffset, endOffset, new Processor<RangeHighlighterEx>() {
    @Override
    public boolean process(RangeHighlighterEx highlighter) {
      GutterMark renderer = highlighter.getGutterIconRenderer();
      if (renderer instanceof MyGutterIconRenderer && ((MyGutterIconRenderer)renderer).myBookmark == Bookmark.this) {
        found.set(highlighter);
        return false;
      }
      return true;
    }
  });
  if (!found.isNull()) found.get().dispose();
}