Java Code Examples for com.intellij.openapi.editor.markup.RangeHighlighter#isValid()

The following examples show how to use com.intellij.openapi.editor.markup.RangeHighlighter#isValid() . 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: 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 2
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 3
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 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: 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 6
Source File: CodeInsightTestFixtureImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
@Nonnull
public Collection<GutterMark> findAllGutters(final String filePath) {
  final Project project = getProject();
  final SortedMap<Integer, List<GutterMark>> result = new TreeMap<Integer, List<GutterMark>>();
  configureByFilesInner(filePath);

  List<HighlightInfo> infos = doHighlighting();
  for (HighlightInfo info : infos) {
    addGutterIconRenderer(info.getGutterIconRenderer(), info.startOffset, result);
  }

  RangeHighlighter[] highlighters = DocumentMarkupModel.forDocument(myEditor.getDocument(), project, true).getAllHighlighters();
  for (final RangeHighlighter highlighter : highlighters) {
    if (!highlighter.isValid()) continue;
    addGutterIconRenderer(highlighter.getGutterIconRenderer(), highlighter.getStartOffset(), result);
  }
  return ContainerUtil.concat(result.values());
}
 
Example 7
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 8
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 9
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 10
Source File: ErrorStripeHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void errorMarkerClicked(@Nonnull ErrorStripeEvent e) {
  RangeHighlighter highlighter = e.getHighlighter();
  if (!highlighter.isValid()) return;
  HighlightInfo info = findInfo(highlighter);
  if (info != null) {
    GotoNextErrorHandler.navigateToError(myProject, e.getEditor(), info);
  }
}
 
Example 11
Source File: LivePreview.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void updateInSelectionHighlighters() {
  final SelectionModel selectionModel = mySearchResults.getEditor().getSelectionModel();
  int[] starts = selectionModel.getBlockSelectionStarts();
  int[] ends = selectionModel.getBlockSelectionEnds();

  for (RangeHighlighter highlighter : myHighlighters) {
    if (!highlighter.isValid()) continue;
    boolean needsAdditionalHighlighting = false;
    TextRange cursor = mySearchResults.getCursor();
    if (cursor == null || highlighter.getStartOffset() != cursor.getStartOffset() || highlighter.getEndOffset() != cursor.getEndOffset()) {
      for (int i = 0; i < starts.length; ++i) {
        TextRange selectionRange = new TextRange(starts[i], ends[i]);
        needsAdditionalHighlighting = selectionRange.intersects(highlighter.getStartOffset(), highlighter.getEndOffset()) &&
                                      selectionRange.getEndOffset() != highlighter.getStartOffset() &&
                                      highlighter.getEndOffset() != selectionRange.getStartOffset();
        if (needsAdditionalHighlighting) break;
      }
    }

    RangeHighlighter inSelectionHighlighter = highlighter.getUserData(IN_SELECTION_KEY);
    if (inSelectionHighlighter != null) {
      if (!needsAdditionalHighlighting) {
        removeHighlighter(inSelectionHighlighter);
      }
    }
    else if (needsAdditionalHighlighting) {
      RangeHighlighter additionalHighlighter = addHighlighter(highlighter.getStartOffset(), highlighter.getEndOffset(), new TextAttributes(null, null, Color.WHITE, EffectType.ROUNDED_BOX, Font.PLAIN));
      highlighter.putUserData(IN_SELECTION_KEY, additionalHighlighter);
    }
  }
}
 
Example 12
Source File: HighlightersRecycler.java    From consulo with Apache License 2.0 4 votes vote down vote up
void recycleHighlighter(@Nonnull RangeHighlighter highlighter) {
  if (highlighter.isValid()) {
    incinerator.putValue(ProperTextRange.create(highlighter), highlighter);
  }
}
 
Example 13
Source File: HighlightCommand.java    From CppTools with Apache License 2.0 4 votes vote down vote up
private void doAddHighlighters(Editor editor, List<String> highlighterStringList, boolean overriden) {
  if (stamp != communicator.getModificationCount() || failed) return;

  final long started = System.currentTimeMillis();
  Key<THashSet<RangeHighlighter>> highlightersKey = overriden ? myOverridenHighlightersKey : myHighlightersKey;
  THashSet<RangeHighlighter> currentHighlighters = editor.getUserData(highlightersKey);
  final THashSet<RangeHighlighter> invalidMarkers;    

  if (currentHighlighters == null) {
    invalidMarkers = new THashSet<RangeHighlighter>(10000);
  } else {
    invalidMarkers = currentHighlighters;
  }

  currentHighlighters = new THashSet<RangeHighlighter>();
  editor.putUserData(highlightersKey, currentHighlighters);

  final TIntObjectHashMap<RangeHighlighter> lastOffsetToHighlightersMap = new TIntObjectHashMap<RangeHighlighter>();
  final TIntObjectHashMap<RangeHighlighter> overridenMap = new TIntObjectHashMap<RangeHighlighter>();
  final TIntObjectHashMap<RangeHighlighter> overriddingMap = new TIntObjectHashMap<RangeHighlighter>();

  for(RangeHighlighter h:invalidMarkers) {
    if (!h.isValid()) continue;

    final GutterIconRenderer gutterIconRenderer = h.getGutterIconRenderer();
    final int offset = h.getStartOffset();

    if ((!overriden && gutterIconRenderer == null)) {
      lastOffsetToHighlightersMap.put(offset, h);
    } else if (overriden && gutterIconRenderer != null) {
      final HighlightUtils.MyGutterIconRenderer myGutterIconRenderer = (HighlightUtils.MyGutterIconRenderer) gutterIconRenderer;
      final boolean overrides = myGutterIconRenderer.isOverrides();
      
      ((HighlightUtils.MyGutterIconRenderer) gutterIconRenderer).clearData();
      ((overrides)?overriddingMap:overridenMap).put(offset, h);
    }
  }

  final EditorColorsScheme colorsScheme = editor.getColorsScheme();

  for(String s: highlighterStringList) {
    processHighlighterString(editor, colorsScheme, s, overriddingMap, overridenMap, lastOffsetToHighlightersMap,
      currentHighlighters, invalidMarkers);
  }

  //System.out.println("Updated highlighters 2/5 for "+ (System.currentTimeMillis() - started));
  for(RangeHighlighter rangeHighlighter:invalidMarkers) {
    editor.getMarkupModel().removeHighlighter(rangeHighlighter);
    currentHighlighters.remove(rangeHighlighter);
  }

  long doneFor = System.currentTimeMillis() - started;
  //System.out.println("Updated highlighters 2 for "+ doneFor);
  Communicator.debug("Updated highlighters 2 for "+ doneFor);
}