Java 类com.intellij.openapi.editor.markup.RangeHighlighter 实例源码

项目:Gherkin-TS-Runner    文件:GherkinIconUtils.java   
public void generateGherkinRunIcons(Document rootDocument, Editor rootEditor) {
    for (int i = 0; i < rootDocument.getLineCount(); i++) {
        int startOffset = rootDocument.getLineStartOffset(i);
        int endOffset = rootDocument.getLineEndOffset(i);

        String lineText = rootDocument.getText(new TextRange(startOffset, endOffset)).trim();

        Icon icon;
        if (lineText.matches(SCENARIO_REGEX)) {
            icon = GherkinIconRenderer.SCENARIO_ICON;
        } else if (lineText.matches(FEATURE_REGEX)) {
            icon = GherkinIconRenderer.FEATURE_ICON;
        } else {
            // System.out.println();
             continue;
        }
        GherkinIconRenderer gherkinIconRenderer = new GherkinIconRenderer(rootEditor.getProject(), fileName);
        gherkinIconRenderer.setLine(i);
        gherkinIconRenderer.setIcon(icon);

        RangeHighlighter rangeHighlighter = createRangeHighlighter(rootDocument, rootEditor, i, i, new TextAttributes());
        rangeHighlighter.setGutterIconRenderer(gherkinIconRenderer);
    }
}
项目:MultiHighlight    文件:ColorPreviewPanel.java   
private void highlightLine(int index, NamedTextAttr namedTextAttr) {
    UIUtil.invokeAndWaitIfNeeded((Runnable) () -> {
        try {
            MarkupModelEx markupModel = myEditor.getMarkupModel();
            final Document doc = markupModel.getDocument();
            final int lineStartOffset = doc.getLineStartOffset(index);
            final int lineEndOffset = doc.getLineEndOffset(index);
            // IDEA-53203: add ERASE_MARKER for manually defined attributes
            markupModel.addRangeHighlighter(lineStartOffset, lineEndOffset,
                    HighlighterLayer.SELECTION - 1, TextAttributes.ERASE_MARKER,
                    HighlighterTargetArea.EXACT_RANGE);
            RangeHighlighter rangeHighlight =
                    markupModel.addRangeHighlighter(lineStartOffset, lineEndOffset,
                            HighlighterLayer.SELECTION - 1, namedTextAttr,
                            HighlighterTargetArea.EXACT_RANGE);
            rangeHighlight.setErrorStripeMarkColor(namedTextAttr.getErrorStripeColor());
            rangeHighlight.setErrorStripeTooltip(namedTextAttr.getName());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    });
}
项目:MultiHighlight    文件:MultiHighlightHandler.java   
private static boolean isClearHighlights(@NotNull Editor editor) {
    if (editor instanceof EditorWindow) {
        editor = ((EditorWindow) editor).getDelegate();
    }

    final Project project = editor.getProject();
    if (project == null) {
        Log.error("isClearHighlights: editor.getProject() == null");
        return false;
    }

    int caretOffset = editor.getCaretModel().getOffset();
    final RangeHighlighter[] highlighters =
            ((HighlightManagerImpl) HighlightManager.getInstance(project)).getHighlighters(
                    editor);
    for (RangeHighlighter highlighter : highlighters) {
        if (TextRange.create(highlighter).grown(1).contains(caretOffset)) {
            return true;
        }
    }

    return false;
}
项目:MultiHighlight    文件:MultiHighlightClearAction.java   
@Override
public void actionPerformed(AnActionEvent e) {
    final Project project = e.getRequiredData(CommonDataKeys.PROJECT);
    final Editor editor = e.getRequiredData(CommonDataKeys.EDITOR);

    final HighlightManager highlightManager = HighlightManager.getInstance(project);
    final RangeHighlighter[] highlighters =
            ((HighlightManagerImpl) highlightManager).getHighlighters(editor);
    for (RangeHighlighter highlighter : highlighters) {
        final TextAttributes ta = highlighter.getTextAttributes();
        if (ta != null && ta instanceof NamedTextAttr
                && highlighter.getLayer() == HighlighterLayer.SELECTION - 1) {
            highlightManager.removeSegmentHighlighter(editor, highlighter);
        }
    }
}
项目:mule-intellij-plugins    文件:FlowInPlaceRenamer.java   
private static void addHighlights(List<TextRange> ranges, Editor editor, ArrayList<RangeHighlighter> highlighters) {
    EditorColorsManager colorsManager = EditorColorsManager.getInstance();
    TextAttributes attributes = colorsManager.getGlobalScheme().getAttributes(EditorColors.WRITE_SEARCH_RESULT_ATTRIBUTES);
    HighlightManager highlightManager = HighlightManager.getInstance(editor.getProject());
    Iterator iterator = ranges.iterator();

    while (iterator.hasNext()) {
        TextRange range = (TextRange) iterator.next();
        //highlightManager.addOccurrenceHighlight(editor, range.getStartOffset() + 1, range.getEndOffset() - 1, attributes, 0, highlighters, (Color) null);
        highlightManager.addRangeHighlight(editor, range.getStartOffset() + 1, range.getEndOffset() - 1, attributes, false, highlighters);
    }

    iterator = highlighters.iterator();

    while (iterator.hasNext()) {
        RangeHighlighter highlighter = (RangeHighlighter) iterator.next();
        highlighter.setGreedyToLeft(true);
        highlighter.setGreedyToRight(true);
    }

}
项目:samebug-idea-plugin    文件:ConsoleWatcher.java   
private RangeHighlighter addMarkerAtOffset(int offset, SearchMark mark) {
    ApplicationManager.getApplication().assertIsDispatchThread();
    final Document document = editor.getDocument();

    if (0 <= offset && offset < document.getTextLength()) {
        editor.getSettings().setLineMarkerAreaShown(true);
        final int line = document.getLineNumber(offset);
        final MarkupModel markupModel = editor.getMarkupModel();

        RangeHighlighter highlighter;
        highlighter = markupModel.addLineHighlighter(line, HighlighterLayer.ADDITIONAL_SYNTAX, null);
        highlighter.setGutterIconRenderer(mark);
        return highlighter;
    } else {
        return null;
    }
}
项目:intellij-ce-playground    文件:BreakpointManager.java   
public void editBreakpoint(final Breakpoint breakpoint, final Editor editor) {
  DebuggerInvocationUtil.swingInvokeLater(myProject, new Runnable() {
    @Override
    public void run() {
      XBreakpoint xBreakpoint = breakpoint.myXBreakpoint;
      if (xBreakpoint instanceof XLineBreakpointImpl) {
        RangeHighlighter highlighter = ((XLineBreakpointImpl)xBreakpoint).getHighlighter();
        if (highlighter != null) {
          GutterIconRenderer renderer = highlighter.getGutterIconRenderer();
          if (renderer != null) {
            DebuggerSupport.getDebuggerSupport(JavaDebuggerSupport.class).getEditBreakpointAction().editBreakpoint(
              myProject, editor, breakpoint.myXBreakpoint, renderer
            );
          }
        }
      }
    }
  });
}
项目:intellij-ce-playground    文件:MavenDomTestCase.java   
protected void assertHighlighted(VirtualFile file, HighlightInfo... expected) throws IOException {
  Editor editor = getEditor(file);
  HighlightUsagesHandler.invoke(myProject, editor, getTestPsiFile(file));

  RangeHighlighter[] highlighters = editor.getMarkupModel().getAllHighlighters();
  List<HighlightInfo> actual = new ArrayList<HighlightInfo>();
  for (RangeHighlighter each : highlighters) {
    if (!each.isValid()) continue;
    int offset = each.getStartOffset();
    PsiElement element = getTestPsiFile(file).findElementAt(offset);
    element = PsiTreeUtil.getParentOfType(element, XmlTag.class);
    String text = editor.getDocument().getText().substring(offset, each.getEndOffset());
    actual.add(new HighlightInfo(element, text));
  }

  assertUnorderedElementsAreEqual(actual, expected);
}
项目:intellij-ce-playground    文件:RefactoringUtil.java   
/**
 * @return List of highlighters
 */
public static List<RangeHighlighter> highlightAllOccurrences(Project project, PsiElement[] occurrences, Editor editor) {
  ArrayList<RangeHighlighter> highlighters = new ArrayList<RangeHighlighter>();
  HighlightManager highlightManager = HighlightManager.getInstance(project);
  EditorColorsManager colorsManager = EditorColorsManager.getInstance();
  TextAttributes attributes = colorsManager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
  if (occurrences.length > 1) {
    for (PsiElement occurrence : occurrences) {
      final RangeMarker rangeMarker = occurrence.getUserData(ElementToWorkOn.TEXT_RANGE);
      if (rangeMarker != null && rangeMarker.isValid()) {
        highlightManager
          .addRangeHighlight(editor, rangeMarker.getStartOffset(), rangeMarker.getEndOffset(), attributes, true, highlighters);
      }
      else {
        final TextRange textRange = occurrence.getTextRange();
        highlightManager.addRangeHighlight(editor, textRange.getStartOffset(), textRange.getEndOffset(), attributes, true, highlighters);
      }
    }
  }
  return highlighters;
}
项目:intellij-ce-playground    文件:LivePreview.java   
private void updateCursorHighlighting() {
  hideBalloon();

  if (myCursorHighlighter != null) {
    HighlightManager.getInstance(mySearchResults.getProject()).removeSegmentHighlighter(mySearchResults.getEditor(), myCursorHighlighter);
    myCursorHighlighter = null;
  }

  final FindResult cursor = mySearchResults.getCursor();
  Editor editor = mySearchResults.getEditor();
  if (cursor != null && cursor.getEndOffset() <= editor.getDocument().getTextLength()) {
    Set<RangeHighlighter> dummy = new HashSet<RangeHighlighter>();
    Color color = editor.getColorsScheme().getColor(EditorColors.CARET_COLOR);
    highlightRange(cursor, new TextAttributes(null, null, color, EffectType.ROUNDED_BOX, 0), dummy);
    if (!dummy.isEmpty()) {
      myCursorHighlighter = dummy.iterator().next();
    }

    editor.getScrollingModel().runActionOnScrollingFinished(new Runnable() {
      @Override
      public void run() {
        showReplacementPreview();
      }
    });
  }
}
项目:intellij-ce-playground    文件:UnifiedEditorRangeHighlighter.java   
public void apply(@Nullable Project project, @NotNull Document document) {
  MarkupModel model = DocumentMarkupModel.forDocument(document, project, true);

  for (Element piece : myPieces) {
    RangeHighlighterEx delegate = piece.getDelegate();
    if (!delegate.isValid()) continue;

    RangeHighlighter highlighter = model
      .addRangeHighlighter(piece.getStart(), piece.getEnd(), delegate.getLayer(), delegate.getTextAttributes(), delegate.getTargetArea());
    highlighter.setEditorFilter(delegate.getEditorFilter());
    highlighter.setCustomRenderer(delegate.getCustomRenderer());
    highlighter.setErrorStripeMarkColor(delegate.getErrorStripeMarkColor());
    highlighter.setErrorStripeTooltip(delegate.getErrorStripeTooltip());
    highlighter.setGutterIconRenderer(delegate.getGutterIconRenderer());
    highlighter.setLineMarkerRenderer(delegate.getLineMarkerRenderer());
    highlighter.setLineSeparatorColor(delegate.getLineSeparatorColor());
    highlighter.setThinErrorStripeMark(delegate.isThinErrorStripeMark());
    highlighter.setLineSeparatorPlacement(delegate.getLineSeparatorPlacement());
    highlighter.setLineSeparatorRenderer(delegate.getLineSeparatorRenderer());
  }
}
项目:intellij-ce-playground    文件:CodeInsightTestFixtureImpl.java   
@Override
@NotNull
public List<GutterMark> findAllGutters() {
  final Project project = getProject();
  final SortedMap<Integer, List<GutterMark>> result = new TreeMap<Integer, List<GutterMark>>();

  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());
}
项目:intellij-ce-playground    文件:InplaceRefactoring.java   
public void finish(boolean success) {
  if (!ourRenamersStack.isEmpty() && ourRenamersStack.peek() == this) {
    ourRenamersStack.pop();
  }
  if (myHighlighters != null) {
    if (!myProject.isDisposed()) {
      final HighlightManager highlightManager = HighlightManager.getInstance(myProject);
      for (RangeHighlighter highlighter : myHighlighters) {
        highlightManager.removeSegmentHighlighter(myEditor, highlighter);
      }
    }

    myHighlighters = null;
    myEditor.putUserData(INPLACE_RENAMER, null);
  }
  if (myBalloon != null) {
         if (!isRestart()) {
           myBalloon.hide();
         }
       }
}
项目:intellij-ce-playground    文件:TemplateState.java   
private void focusCurrentHighlighter(boolean toSelect) {
  if (isFinished()) {
    return;
  }
  if (myCurrentVariableNumber >= myTabStopHighlighters.size()) {
    return;
  }
  RangeHighlighter segmentHighlighter = myTabStopHighlighters.get(myCurrentVariableNumber);
  if (segmentHighlighter != null) {
    final int segmentNumber = getCurrentSegmentNumber();
    RangeHighlighter newSegmentHighlighter = getSegmentHighlighter(segmentNumber, toSelect, false);
    if (newSegmentHighlighter != null) {
      segmentHighlighter.dispose();
      myTabStopHighlighters.set(myCurrentVariableNumber, newSegmentHighlighter);
    }
  }
}
项目:intellij-ce-playground    文件:EditorMarkupModelImpl.java   
@Override
public TooltipRenderer calcTooltipRenderer(@NotNull final Collection<RangeHighlighter> highlighters) {
  LineTooltipRenderer bigRenderer = null;
  //do not show same tooltip twice
  Set<String> tooltips = null;

  for (RangeHighlighter highlighter : highlighters) {
    final Object tooltipObject = highlighter.getErrorStripeTooltip();
    if (tooltipObject == null) continue;

    final String text = tooltipObject.toString();
    if (tooltips == null) {
      tooltips = new THashSet<String>();
    }
    if (tooltips.add(text)) {
      if (bigRenderer == null) {
        bigRenderer = new LineTooltipRenderer(text, new Object[]{highlighters});
      }
      else {
        bigRenderer.addBelow(text);
      }
    }
  }

  return bigRenderer;
}
项目:intellij-ce-playground    文件:BreadcrumbsXmlWrapper.java   
@Override
public void itemHovered(@Nullable BreadcrumbsPsiItem item) {
  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 (item != null) {
    final TextRange range = item.getPsiElement().getTextRange();
    final TextAttributes attributes = new TextAttributes();
    final CrumbPresentation p = item.getPresentation();
    final Color color = p != null ? p.getBackgroundColor(false, false, false) : BreadcrumbsComponent.ButtonSettings.DEFAULT_BG_COLOR;
    final Color background = EditorColorsManager.getInstance().getGlobalScheme().getColor(EditorColors.CARET_ROW_COLOR);
    attributes.setBackgroundColor(XmlTagTreeHighlightingUtil.makeTransparent(color, background != null ? background : Gray._200, 0.3));
    myHighlighed = new ArrayList<RangeHighlighter>(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);
  }
}
项目:intellij-ce-playground    文件:DocumentMarkupModelTest.java   
public void testInfoTestAttributes() throws Exception {
  LanguageExtensionPoint<Annotator> extension = new LanguageExtensionPoint<Annotator>();
  extension.language="TEXT";
  extension.implementationClass = TestAnnotator.class.getName();
  PlatformTestUtil.registerExtension(ExtensionPointName.create(LanguageAnnotators.EP_NAME), extension, getTestRootDisposable());
  myFixture.configureByText(PlainTextFileType.INSTANCE, "foo");
  EditorColorsScheme scheme = new EditorColorsSchemeImpl(new DefaultColorsScheme()){{initFonts();}};
  scheme.setAttributes(HighlighterColors.TEXT, new TextAttributes(Color.black, Color.white, null, null, Font.PLAIN));
  ((EditorEx)myFixture.getEditor()).setColorsScheme(scheme);
  myFixture.doHighlighting();
  MarkupModel model = DocumentMarkupModel.forDocument(myFixture.getEditor().getDocument(), getProject(), false);
  RangeHighlighter[] highlighters = model.getAllHighlighters();
  assertEquals(1, highlighters.length);
  TextAttributes attributes = highlighters[0].getTextAttributes();
  assertNotNull(attributes);
  assertNull(attributes.getBackgroundColor());
  assertNull(attributes.getForegroundColor());
}
项目:intellij-ce-playground    文件:ProcessWithConsoleRunner.java   
/**
 * Gets highlighted information from test console. Some parts of output (like file links) may be highlighted, and you need to check them.
 *
 * @return pair of [[ranges], [texts]] where range is [from,to] in doc. for each region, and "text" is text extracted from this region.
 * For example assume that in document "spam eggs ham" words "ham" and "spam" are highlighted.
 * You should have 2 ranges (0, 4) and (10, 13) and 2 strings (spam and ham)
 */
@NotNull
public Pair<List<Pair<Integer, Integer>>, List<String>> getHighlightedStringsInConsole() {
  final List<String> resultStrings = new ArrayList<String>();
  final List<Pair<Integer, Integer>> resultRanges = new ArrayList<Pair<Integer, Integer>>();
  ApplicationManager.getApplication().invokeAndWait(new Runnable() {
    @Override
    public void run() {
      myConsole.flushDeferredText();
      final Editor editor = myConsole.getEditor();
      for (final RangeHighlighter highlighter : editor.getMarkupModel().getAllHighlighters()) {
        if (highlighter instanceof RangeHighlighterEx) {
          final int start = ((RangeHighlighterEx)highlighter).getAffectedAreaStartOffset();
          final int end = ((RangeHighlighterEx)highlighter).getAffectedAreaEndOffset();
          resultRanges.add(Pair.create(start, end));
          resultStrings.add(editor.getDocument().getText().substring(start, end));
        }
      }
    }
  }, ModalityState.NON_MODAL);
  return Pair.create(resultRanges, resultStrings);
}
项目:intellij-ce-playground    文件:HighlightUsagesHandler.java   
public static void highlightRanges(HighlightManager highlightManager, Editor editor, TextAttributes attributes,
                                   boolean clearHighlights,
                                   List<TextRange> textRanges) {
  if (clearHighlights) {
    clearHighlights(editor, highlightManager, textRanges, attributes);
    return;
  }
  ArrayList<RangeHighlighter> highlighters = new ArrayList<RangeHighlighter>();
  for (TextRange range : textRanges) {
    highlightManager.addRangeHighlight(editor, range.getStartOffset(), range.getEndOffset(), attributes, false, highlighters);
  }
  for (RangeHighlighter highlighter : highlighters) {
    String tooltip = getLineTextErrorStripeTooltip(editor.getDocument(), highlighter.getStartOffset(), true);
    highlighter.setErrorStripeTooltip(tooltip);
  }
}
项目:intellij-ce-playground    文件:EscapeHandler.java   
@Override
public boolean isEnabled(Editor editor, DataContext dataContext) {
  if (editor.hasHeaderComponent()) return true;
  Project project = CommonDataKeys.PROJECT.getData(dataContext);

  if (project != null) {
    HighlightManagerImpl highlightManager = (HighlightManagerImpl)HighlightManager.getInstance(project);
    if (highlightManager != null) {
      Map<RangeHighlighter, HighlightManagerImpl.HighlightInfo> map = highlightManager.getHighlightInfoMap(editor, false);
      if (map != null) {
        for (HighlightManagerImpl.HighlightInfo info : map.values()) {
          if (!info.editor.equals(editor)) continue;
          if ((info.flags & HighlightManager.HIDE_BY_ESCAPE) != 0) {
            return true;
          }
        }
      }
    }
  }

  return myOriginalHandler.isEnabled(editor, dataContext);
}
项目:intellij-ce-playground    文件:CtrlMouseHandler.java   
@NotNull
private HighlightersSet installHighlighterSet(@NotNull Info info, @NotNull Editor editor) {
  final JComponent internalComponent = editor.getContentComponent();
  internalComponent.addKeyListener(myEditorKeyListener);
  editor.getScrollingModel().addVisibleAreaListener(myVisibleAreaListener);
  final Cursor cursor = internalComponent.getCursor();
  internalComponent.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
  myFileEditorManager.addFileEditorManagerListener(myFileEditorManagerListener);

  List<RangeHighlighter> highlighters = new ArrayList<RangeHighlighter>();
  TextAttributes attributes = myEditorColorsManager.getGlobalScheme().getAttributes(EditorColors.REFERENCE_HYPERLINK_COLOR);
  for (TextRange range : info.getRanges()) {
    TextAttributes attr = NavigationUtil.patchAttributesColor(attributes, range, editor);
    final RangeHighlighter highlighter = editor.getMarkupModel().addRangeHighlighter(range.getStartOffset(), range.getEndOffset(),
                                                                                     HighlighterLayer.SELECTION + 1,
                                                                                     attr,
                                                                                     HighlighterTargetArea.EXACT_RANGE);
    highlighters.add(highlighter);
  }

  return new HighlightersSet(highlighters, editor, cursor, info);
}
项目:Gherkin-TS-Runner    文件:GherkinIconUtils.java   
public void removeGherkinRunIcons(Editor rootEditor) {
    RangeHighlighter[] highlighters = rootEditor.getMarkupModel().getAllHighlighters();
    for (RangeHighlighter highlighter : highlighters) {

        if (highlighter.getGutterIconRenderer() instanceof GherkinIconRenderer) {
            rootEditor.getMarkupModel().removeHighlighter(highlighter);
        }
    }
}
项目:Gherkin-TS-Runner    文件:GherkinIconUtils.java   
private RangeHighlighter createRangeHighlighter(Document document, Editor editor, int fromLine, int toLine, TextAttributes attributes) {
    int lineStartOffset = document.getLineStartOffset(Math.max(0, fromLine));
    int lineEndOffset = document.getLineEndOffset(Math.max(0, toLine));

    return editor.getMarkupModel().addRangeHighlighter(
            lineStartOffset, lineEndOffset, 3333, attributes, HighlighterTargetArea.LINES_IN_RANGE
    );
}
项目:educational-plugin    文件:CCTestCase.java   
@Nullable
public static RangeHighlighter getHighlighter(MarkupModel model, AnswerPlaceholder placeholder) {
  for (RangeHighlighter highlighter : model.getAllHighlighters()) {
    int endOffset = placeholder.getOffset() + placeholder.getRealLength();
    if (highlighter.getStartOffset() == placeholder.getOffset() && highlighter.getEndOffset() == endOffset) {
      return highlighter;
    }
  }
  return null;
}
项目:MultiHighlight    文件:MultiHighlightHandler.java   
private static void clearHighlights(Editor editor, HighlightManager highlightManager,
        List<TextRange> toRemoves) {
    if (editor instanceof EditorWindow) {
        editor = ((EditorWindow) editor).getDelegate();
    }

    RangeHighlighter[] highlighters =
            ((HighlightManagerImpl) highlightManager).getHighlighters(editor);

    Arrays.sort(highlighters, (o1, o2) -> o1.getStartOffset() - o2.getStartOffset());
    Collections.sort(toRemoves, (o1, o2) -> o1.getStartOffset() - o2.getStartOffset());

    int i = 0;
    int j = 0;
    while (i < highlighters.length && j < toRemoves.size()) {
        RangeHighlighter highlighter = highlighters[i];
        final TextAttributes ta = highlighter.getTextAttributes();
        final TextRange textRange = TextRange.create(highlighter);
        final TextRange toRemove = toRemoves.get(j);
        if (ta != null && ta instanceof NamedTextAttr // wrap
                && highlighter.getLayer() == HighlighterLayer.SELECTION - 1 // wrap
                && toRemove.equals(textRange)) {
            highlightManager.removeSegmentHighlighter(editor, highlighter);
            i++;
        } else if (toRemove.getStartOffset() > textRange.getEndOffset()) {
            i++;
        } else if (toRemove.getEndOffset() < textRange.getStartOffset()) {
            j++;
        } else {
            i++;
            j++;
        }
    }
}
项目:MultiHighlight    文件:MultiHighlightHandler.java   
private static void highlight(@NotNull HighlightManager highlightManager,
        @NotNull Collection<TextRange> textRanges, @NotNull Editor editor,
        @NotNull TextAttributes ta, @Nullable Collection<RangeHighlighter> holder,
        @Nullable Color scrollMarkColor) {
    for (TextRange range : textRanges) {
        highlightManager.addOccurrenceHighlight(editor, range.getStartOffset(),
                range.getEndOffset(), ta, 0, holder, scrollMarkColor);
    }
}
项目:mule-intellij-plugins    文件:FlowInPlaceRenamer.java   
private void finish() {
    ourRenamersStack.pop();
    if (this.myHighlighters != null) {
        Project project = this.myEditor.getProject();
        if (project != null && !project.isDisposed()) {
            HighlightManager highlightManager = HighlightManager.getInstance(project);
            Iterator var3 = this.myHighlighters.iterator();

            while (var3.hasNext()) {
                RangeHighlighter highlighter = (RangeHighlighter) var3.next();
                highlightManager.removeSegmentHighlighter(this.myEditor, highlighter);
            }
        }
    }
}
项目:samebug-idea-plugin    文件:ConsoleWatcher.java   
public ConsoleWatcher(Project project, ConsoleViewImpl console, DebugSessionInfo sessionInfo) {
    this.sessionInfo = sessionInfo;
    this.editor = console.getEditor();
    this.searchRequestStore = IdeaSamebugPlugin.getInstance().searchRequestStore;
    this.highlights = new ConcurrentHashMap<UUID, RangeHighlighter>();
    this.timer = new Timer("Samebug-ConsoleWatcher-" + sessionInfo.id);
    currentTask = null;
    LOGGER.info("Watcher constructed for " + editor.toString());

    editor.getDocument().addDocumentListener(this, console);
    MessageBusConnection messageBusConnection = project.getMessageBus().connect(console);
    messageBusConnection.subscribe(SearchRequestListener.TOPIC, this);
}
项目:intellij-ce-playground    文件:DuplicatesImpl.java   
public static ArrayList<RangeHighlighter> previewMatch(Project project, Match match, Editor editor) {
  final ArrayList<RangeHighlighter> highlighters = new ArrayList<RangeHighlighter>();
  highlightMatch(project, editor, match, highlighters);
  final TextRange textRange = match.getTextRange();
  final LogicalPosition logicalPosition = editor.offsetToLogicalPosition(textRange.getStartOffset());
  expandAllRegionsCoveringRange(project, editor, textRange);
  editor.getScrollingModel().scrollTo(logicalPosition, ScrollType.MAKE_VISIBLE);
  return highlighters;
}
项目:intellij-ce-playground    文件:TrafficLightRenderer.java   
private void incErrorCount(RangeHighlighter highlighter, int delta) {
  Object o = highlighter.getErrorStripeTooltip();
  if (!(o instanceof HighlightInfo)) return;
  HighlightInfo info = (HighlightInfo)o;
  HighlightSeverity infoSeverity = info.getSeverity();
  final int severityIdx = mySeverityRegistrar.getSeverityIdx(infoSeverity);
  if (severityIdx != -1) {
    errorCount[severityIdx] += delta;
  }
}
项目:intellij-ce-playground    文件:HighlighterUtil.java   
/**
 * Clear all highlighters in an editor that are set up by this class
 *
 * @param editor the editor
 */
public static void clearHighlighters(final Editor editor) {
    final List<RangeHighlighter> hl = editor.getUserData(HIGHLIGHTERS_KEY);
    if (hl != null) {
        if (purgeInvalidHighlighters(editor, hl)) {
            final HighlightManager mgr = HighlightManager.getInstance(editor.getProject());
            for (Iterator<RangeHighlighter> iterator = hl.iterator(); iterator.hasNext();) {
                RangeHighlighter highlighter = iterator.next();
                mgr.removeSegmentHighlighter(editor, highlighter);
                iterator.remove();
            }
        }
    }
}
项目:intellij-ce-playground    文件:SimpleOnesideDiffViewer.java   
@Override
@CalledInAwt
protected void onDispose() {
  for (RangeHighlighter highlighter : myHighlighters) {
    highlighter.dispose();
  }
  myHighlighters.clear();
  super.onDispose();
}
项目:intellij-ce-playground    文件:HighlighterUtil.java   
public static boolean hasHighlighters(Editor editor) {
    final List<RangeHighlighter> hl = editor.getUserData(HIGHLIGHTERS_KEY);
    if (hl != null) {
        if (hl.isEmpty()) {
            return false;
        }
        return purgeInvalidHighlighters(editor, hl);
    }
    return false;
}
项目:intellij-ce-playground    文件:DiffEmptyHighlighterRenderer.java   
@Override
public void paint(@NotNull Editor editor, @NotNull RangeHighlighter highlighter, @NotNull Graphics g) {
  g.setColor(myDiffType.getColor(editor));
  Point point = editor.logicalPositionToXY(editor.offsetToLogicalPosition(highlighter.getStartOffset()));
  int endy = point.y + editor.getLineHeight() - 1;
  g.drawLine(point.x, point.y, point.x, endy);
  g.drawLine(point.x - 1, point.y, point.x - 1, endy);
}
项目:intellij-ce-playground    文件:EmptyMarkupModel.java   
@Override
@NotNull
public RangeHighlighter addRangeHighlighter(int startOffset,
                                            int endOffset,
                                            int layer,
                                            @Nullable TextAttributes textAttributes,
                                            @NotNull HighlighterTargetArea targetArea) {
  throw new ProcessCanceledException();
}
项目:intellij-ce-playground    文件:MarkupModelImpl.java   
@Override
@NotNull
public RangeHighlighter addLineHighlighter(int lineNumber, int layer, TextAttributes textAttributes) {
  if (isNotValidLine(lineNumber)) {
    throw new IndexOutOfBoundsException("lineNumber:" + lineNumber + ". Must be in [0, " + (getDocument().getLineCount() - 1) + "]");
  }

  int offset = DocumentUtil.getFirstNonSpaceCharOffset(getDocument(), lineNumber);
  return addRangeHighlighter(offset, offset, layer, textAttributes, HighlighterTargetArea.LINES_IN_RANGE);
}
项目:intellij-ce-playground    文件:MarkupModelImpl.java   
@Override
@NotNull
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<RangeHighlighterEx>(size);
    CommonProcessors.CollectProcessor<RangeHighlighterEx> collectProcessor = new CommonProcessors.CollectProcessor<RangeHighlighterEx>(list);
    myHighlighterTree.process(collectProcessor);
    myHighlighterTreeForLines.process(collectProcessor);
    myCachedHighlighters = list.toArray(new RangeHighlighter[list.size()]);
  }
  return myCachedHighlighters;
}
项目:intellij-ce-playground    文件:MarkupModelImpl.java   
@Override
@NotNull
public RangeHighlighter addRangeHighlighter(int startOffset,
                                            int endOffset,
                                            int layer,
                                            TextAttributes textAttributes,
                                            @NotNull HighlighterTargetArea targetArea) {
  return addRangeHighlighterAndChangeAttributes(startOffset, endOffset, layer, textAttributes, targetArea, false, null);
}
项目:intellij-ce-playground    文件:MarkupModelImpl.java   
@Override
public void removeHighlighter(@NotNull RangeHighlighter segmentHighlighter) {
  ApplicationManager.getApplication().assertIsDispatchThread();
  myCachedHighlighters = null;
  if (!segmentHighlighter.isValid()) return;

  boolean removed = treeFor(segmentHighlighter).removeInterval((RangeHighlighterEx)segmentHighlighter);
  LOG.assertTrue(removed);
}
项目:intellij-ce-playground    文件:MarkupModelImpl.java   
@Override
public void removeAllHighlighters() {
  ApplicationManager.getApplication().assertIsDispatchThread();
  for (RangeHighlighter highlighter : getAllHighlighters()) {
    highlighter.dispose();
  }
  myCachedHighlighters = null;
  myHighlighterTree.clear();
  myHighlighterTreeForLines.clear();
}