com.intellij.openapi.editor.ex.MarkupModelEx Java Examples

The following examples show how to use com.intellij.openapi.editor.ex.MarkupModelEx. 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: 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 #3
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 #4
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 #5
Source File: SyntaxInfoBuilder.java    From consulo with Apache License 2.0 6 votes vote down vote up
private MarkupModelRangeIterator(@Nullable MarkupModel markupModel, @Nonnull EditorColorsScheme colorsScheme, int startOffset, int endOffset) {
  myStartOffset = startOffset;
  myEndOffset = endOffset;
  myColorsScheme = colorsScheme;
  myDefaultForeground = colorsScheme.getDefaultForeground();
  myDefaultBackground = colorsScheme.getDefaultBackground();
  myUnsupportedModel = !(markupModel instanceof MarkupModelEx);
  if (myUnsupportedModel) {
    myIterator = null;
    return;
  }
  myIterator = ((MarkupModelEx)markupModel).overlappingIterator(startOffset, endOffset);
  try {
    findNextSuitableRange();
  }
  catch (RuntimeException | Error e) {
    myIterator.dispose();
    throw e;
  }
}
 
Example #6
Source File: RangeMarkerTest.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void testRangeHighlighterLinesInRangeForLongLinePerformance() throws Exception {
  final int N = 50000;
  Document document = EditorFactory.getInstance().createDocument(StringUtil.repeatSymbol('x', 2 * N));

  final MarkupModelEx markupModel = (MarkupModelEx)DocumentMarkupModel.forDocument(document, ourProject, true);
  for (int i=0; i<N-1;i++) {
    markupModel.addRangeHighlighter(2*i, 2*i+1, 0, null, HighlighterTargetArea.EXACT_RANGE);
  }
  markupModel.addRangeHighlighter(N / 2, N / 2 + 1, 0, null, HighlighterTargetArea.LINES_IN_RANGE);

  PlatformTestUtil.startPerformanceTest("slow highlighters lookup", (int)(N*Math.log(N)/1000), new ThrowableRunnable() {
    @Override
    public void run() {
      List<RangeHighlighterEx> list = new ArrayList<RangeHighlighterEx>();
      CommonProcessors.CollectProcessor<RangeHighlighterEx> coll = new CommonProcessors.CollectProcessor<RangeHighlighterEx>(list);
      for (int i=0; i<N-1;i++) {
        list.clear();
        markupModel.processRangeHighlightersOverlappingWith(2*i, 2*i+1, coll);
        assertEquals(2, list.size());  // 1 line plus one exact range marker
      }
    }
  }).assertTiming();
}
 
Example #7
Source File: NavigationUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
/**
 * Patches attributes to be visible under debugger active line
 */
@SuppressWarnings("UseJBColor")
public static TextAttributes patchAttributesColor(TextAttributes attributes, @Nonnull TextRange range, @Nonnull Editor editor) {
  if (attributes.getForegroundColor() == null && attributes.getEffectColor() == null) return attributes;
  MarkupModel model = DocumentMarkupModel.forDocument(editor.getDocument(), editor.getProject(), false);
  if (model != null) {
    if (!((MarkupModelEx)model).processRangeHighlightersOverlappingWith(range.getStartOffset(), range.getEndOffset(), highlighter -> {
      if (highlighter.isValid() && highlighter.getTargetArea() == HighlighterTargetArea.LINES_IN_RANGE) {
        TextAttributes textAttributes = highlighter.getTextAttributes();
        if (textAttributes != null) {
          Color color = textAttributes.getBackgroundColor();
          return !(color != null && color.getBlue() > 128 && color.getRed() < 128 && color.getGreen() < 128);
        }
      }
      return true;
    })) {
      TextAttributes clone = attributes.clone();
      clone.setForegroundColor(Color.orange);
      clone.setEffectColor(Color.orange);
      return clone;
    }
  }
  return attributes;
}
 
Example #8
Source File: UpdateHighlightersUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static void setHighlightersToEditor(@Nonnull Project project,
                                           @Nonnull Document document,
                                           int startOffset,
                                           int endOffset,
                                           @Nonnull Collection<HighlightInfo> highlights,
                                           @Nullable final EditorColorsScheme colorsScheme, // if null global scheme will be used
                                           int group) {
  TextRange range = new TextRange(startOffset, endOffset);
  ApplicationManager.getApplication().assertIsDispatchThread();

  PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(document);
  final DaemonCodeAnalyzerEx codeAnalyzer = DaemonCodeAnalyzerEx.getInstanceEx(project);
  codeAnalyzer.cleanFileLevelHighlights(project, group, psiFile);

  MarkupModel markup = DocumentMarkupModel.forDocument(document, project, true);
  assertMarkupConsistent(markup, project);

  setHighlightersInRange(project, document, range, colorsScheme, new ArrayList<>(highlights), (MarkupModelEx)markup, group);
}
 
Example #9
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
 */
static boolean processHighlightsOverlappingOutside(@Nonnull Document document,
                                                   @Nonnull Project project,
                                                   @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.processRangeHighlightersOutside(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 #10
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 #11
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 #12
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();
}
 
Example #13
Source File: BraceHighlightingHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void removeLineMarkers() {
  ApplicationManager.getApplication().assertIsDispatchThread();
  RangeHighlighter marker = myEditor.getUserData(LINE_MARKER_IN_EDITOR_KEY);
  if (marker != null && ((MarkupModelEx)myEditor.getMarkupModel()).containsHighlighter(marker)) {
    marker.dispose();
  }
  myEditor.putUserData(LINE_MARKER_IN_EDITOR_KEY, null);
}
 
Example #14
Source File: HighlightManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public boolean removeSegmentHighlighter(@Nonnull Editor editor, @Nonnull RangeHighlighter highlighter) {
  Map<RangeHighlighter, HighlightInfo> map = getHighlightInfoMap(editor, false);
  if (map == null) return false;
  HighlightInfo info = map.get(highlighter);
  if (info == null) return false;
  MarkupModel markupModel = info.editor.getMarkupModel();
  if (((MarkupModelEx)markupModel).containsHighlighter(highlighter)) {
    highlighter.dispose();
  }
  map.remove(highlighter);
  return true;
}
 
Example #15
Source File: DefaultHighlightInfoProcessor.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void highlightsInsideVisiblePartAreProduced(@Nonnull final HighlightingSession session,
                                                   @Nullable Editor editor,
                                                   @Nonnull final List<? extends HighlightInfo> infos,
                                                   @Nonnull TextRange priorityRange,
                                                   @Nonnull TextRange restrictRange,
                                                   final int groupId) {
  final PsiFile psiFile = session.getPsiFile();
  final Project project = psiFile.getProject();
  final Document document = PsiDocumentManager.getInstance(project).getDocument(psiFile);
  if (document == null) return;
  final long modificationStamp = document.getModificationStamp();
  final TextRange priorityIntersection = priorityRange.intersection(restrictRange);
  List<? extends HighlightInfo> infoCopy = new ArrayList<>(infos);
  ((HighlightingSessionImpl)session).applyInEDT(() -> {
    if (modificationStamp != document.getModificationStamp()) return;
    if (priorityIntersection != null) {
      MarkupModel markupModel = DocumentMarkupModel.forDocument(document, project, true);

      EditorColorsScheme scheme = session.getColorsScheme();
      UpdateHighlightersUtil.setHighlightersInRange(project, document, priorityIntersection, scheme, infoCopy, (MarkupModelEx)markupModel, groupId);
    }
    if (editor != null && !editor.isDisposed()) {
      // usability: show auto import popup as soon as possible
      if (!DumbService.isDumb(project)) {
        ShowAutoImportPassFactory siFactory = TextEditorHighlightingPassFactory.EP_NAME.findExtensionOrFail(project, ShowAutoImportPassFactory.class);
        TextEditorHighlightingPass highlightingPass = siFactory.createHighlightingPass(psiFile, editor);
        if (highlightingPass != null) {
          highlightingPass.doApplyInformationToEditor();
        }
      }

      repaintErrorStripeAndIcon(editor, project);
    }
  });
}
 
Example #16
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 #17
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 #18
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 #19
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 #20
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 #21
Source File: BraceHighlighter.java    From HighlightBracketPair with Apache License 2.0 5 votes vote down vote up
public BraceHighlighter(Editor editor) {
    this.editor = editor;
    this.project = this.editor.getProject();
    this.document = this.editor.getDocument();
    this.psiFile = PsiDocumentManager.getInstance(project).getPsiFile(document);
    this.fileType = psiFile.getFileType();
    this.fileText = this.editor.getDocument().getImmutableCharSequence();
    this.markupModelEx = (MarkupModelEx) this.editor.getMarkupModel();
}
 
Example #22
Source File: UpdateHighlightersUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
static void addHighlighterToEditorIncrementally(@Nonnull Project project,
                                                @Nonnull Document document,
                                                @Nonnull PsiFile file,
                                                int startOffset,
                                                int endOffset,
                                                @Nonnull final HighlightInfo info,
                                                @Nullable final EditorColorsScheme colorsScheme, // if null global scheme will be used
                                                final int group,
                                                @Nonnull Map<TextRange, RangeMarker> ranges2markersCache) {
  ApplicationManager.getApplication().assertIsDispatchThread();
  if (isFileLevelOrGutterAnnotation(info)) return;
  if (info.getStartOffset() < startOffset || info.getEndOffset() > endOffset) return;

  MarkupModel markup = DocumentMarkupModel.forDocument(document, project, true);
  final SeverityRegistrar severityRegistrar = SeverityRegistrar.getSeverityRegistrar(project);
  final boolean myInfoIsError = isSevere(info, severityRegistrar);
  Processor<HighlightInfo> otherHighlightInTheWayProcessor = oldInfo -> {
    if (!myInfoIsError && isCovered(info, severityRegistrar, oldInfo)) {
      return false;
    }

    return oldInfo.getGroup() != group || !oldInfo.equalsByActualOffset(info);
  };
  boolean allIsClear = DaemonCodeAnalyzerEx.processHighlights(document, project,
                                                              null, info.getActualStartOffset(), info.getActualEndOffset(),
                                                              otherHighlightInTheWayProcessor);
  if (allIsClear) {
    createOrReuseHighlighterFor(info, colorsScheme, document, group, file, (MarkupModelEx)markup, null, ranges2markersCache, severityRegistrar);

    clearWhiteSpaceOptimizationFlag(document);
    assertMarkupConsistent(markup, project);
  }
}
 
Example #23
Source File: UnifiedEditorRangeHighlighter.java    From consulo with Apache License 2.0 5 votes vote down vote up
public UnifiedEditorRangeHighlighter(@javax.annotation.Nullable Project project,
                                     @Nonnull Document document1,
                                     @Nonnull Document document2,
                                     @Nonnull List<HighlightRange> ranges) {
  ApplicationManager.getApplication().assertReadAccessAllowed();

  MarkupModelEx model1 = (MarkupModelEx)DocumentMarkupModel.forDocument(document1, project, false);
  MarkupModelEx model2 = (MarkupModelEx)DocumentMarkupModel.forDocument(document2, project, false);
  init(model1, model2, ranges);
}
 
Example #24
Source File: UnifiedEditorRangeHighlighter.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void init(@javax.annotation.Nullable MarkupModelEx model1,
                  @javax.annotation.Nullable MarkupModelEx model2,
                  @Nonnull List<HighlightRange> ranges) {
  for (HighlightRange range : ranges) {
    if (range.getSide().isLeft()) {
      if (model1 != null) processRange(model1, range);
    }
    else {
      if (model2 != null) processRange(model2, range);
    }
  }
}
 
Example #25
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 #26
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 #27
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 #28
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 #29
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 #30
Source File: DesktopEditorErrorPanelUI.java    From consulo with Apache License 2.0 4 votes vote down vote up
private void drawMarkup(@Nonnull final Graphics g, int startOffset, int endOffset, @Nonnull MarkupModelEx markup1, @Nonnull MarkupModelEx markup2) {
  final Queue<PositionedStripe> thinEnds = new PriorityQueue<>(5, (o1, o2) -> o1.yEnd - o2.yEnd);
  final Queue<PositionedStripe> wideEnds = new PriorityQueue<>(5, (o1, o2) -> o1.yEnd - o2.yEnd);
  // sorted by layer
  final List<PositionedStripe> thinStripes = new ArrayList<>(); // layer desc
  final List<PositionedStripe> wideStripes = new ArrayList<>(); // layer desc
  final int[] thinYStart = new int[1];  // in range 0..yStart all spots are drawn
  final int[] wideYStart = new int[1];  // in range 0..yStart all spots are drawn

  MarkupIterator<RangeHighlighterEx> iterator1 = markup1.overlappingIterator(startOffset, endOffset);
  MarkupIterator<RangeHighlighterEx> iterator2 = markup2.overlappingIterator(startOffset, endOffset);
  MarkupIterator<RangeHighlighterEx> iterator = MarkupIterator.mergeIterators(iterator1, iterator2, RangeHighlighterEx.BY_AFFECTED_START_OFFSET);
  try {
    ContainerUtil.process(iterator, highlighter -> {
      Color color = highlighter.getErrorStripeMarkColor();
      if (color == null) return true;
      boolean isThin = highlighter.isThinErrorStripeMark();
      int[] yStart = isThin ? thinYStart : wideYStart;
      List<PositionedStripe> stripes = isThin ? thinStripes : wideStripes;
      Queue<PositionedStripe> ends = isThin ? thinEnds : wideEnds;

      ProperTextRange range = myPanel.offsetsToYPositions(highlighter.getStartOffset(), highlighter.getEndOffset());
      final int ys = range.getStartOffset();
      int ye = range.getEndOffset();
      if (ye - ys < myPanel.getMarkupModel().getMinMarkHeight()) ye = ys + myPanel.getMarkupModel().getMinMarkHeight();

      yStart[0] = drawStripesEndingBefore(ys, ends, stripes, g, yStart[0]);

      final int layer = highlighter.getLayer();

      PositionedStripe stripe = null;
      int i;
      for (i = 0; i < stripes.size(); i++) {
        PositionedStripe s = stripes.get(i);
        if (s.layer == layer) {
          stripe = s;
          break;
        }
        if (s.layer < layer) {
          break;
        }
      }
      if (stripe == null) {
        // started new stripe, draw previous above
        if (i == 0 && yStart[0] != ys) {
          if (!stripes.isEmpty()) {
            PositionedStripe top = stripes.get(0);
            drawSpot(g, top.thin, yStart[0], ys, top.color);
          }
          yStart[0] = ys;
        }
        stripe = new PositionedStripe(color, ye, isThin, layer);
        stripes.add(i, stripe);
        ends.offer(stripe);
      }
      else {
        if (stripe.yEnd < ye) {
          if (!color.equals(stripe.color)) {
            // paint previous stripe on this layer
            if (i == 0 && yStart[0] != ys) {
              drawSpot(g, stripe.thin, yStart[0], ys, stripe.color);
              yStart[0] = ys;
            }
            stripe.color = color;
          }

          // key changed, reinsert into queue
          ends.remove(stripe);
          stripe.yEnd = ye;
          ends.offer(stripe);
        }
      }
      return true;
    });
  }
  finally {
    iterator.dispose();
  }

  drawStripesEndingBefore(Integer.MAX_VALUE, thinEnds, thinStripes, g, thinYStart[0]);
  drawStripesEndingBefore(Integer.MAX_VALUE, wideEnds, wideStripes, g, wideYStart[0]);
}