Java Code Examples for com.intellij.openapi.editor.Editor#getMarkupModel()

The following examples show how to use com.intellij.openapi.editor.Editor#getMarkupModel() . 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: 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 2
Source File: LSPDiagnosticsToMarkers.java    From intellij-quarkus with Eclipse Public License 2.0 5 votes vote down vote up
private void cleanMarkers(Editor editor) {
    Map<String, RangeHighlighter[]> allMarkers = getAllMarkers(editor);
    RangeHighlighter[] highlighters = allMarkers.get(languageServerId);
    MarkupModel markupModel = editor.getMarkupModel();
    if (highlighters != null) {
        for (RangeHighlighter highlighter : highlighters) {
            markupModel.removeHighlighter(highlighter);
        }
    }
    allMarkers.remove(languageServerId);
}
 
Example 3
Source File: EditorPerfDecorations.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void removeMarker(TextRange range) {
  final PerfGutterIconRenderer marker = perfMarkers.remove(range);
  if (marker != null) {
    final Editor editor = textEditor.getEditor();
    final MarkupModel markupModel = editor.getMarkupModel();
    markupModel.removeHighlighter(marker.getHighlighter());
  }
}
 
Example 4
Source File: EditorPerfDecorations.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void removeMarker(TextRange range) {
  final PerfGutterIconRenderer marker = perfMarkers.remove(range);
  if (marker != null) {
    final Editor editor = textEditor.getEditor();
    final MarkupModel markupModel = editor.getMarkupModel();
    markupModel.removeHighlighter(marker.getHighlighter());
  }
}
 
Example 5
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 6
Source File: EditorDocOps.java    From KodeBeagle with Apache License 2.0 5 votes vote down vote up
public final void addHighlighting(final List<Integer> linesForHighlighting,
                                  final Document document) {
    TextAttributes attributes = new TextAttributes();
    JBColor color = JBColor.GREEN;
    attributes.setEffectColor(color);
    attributes.setEffectType(EffectType.SEARCH_MATCH);
    attributes.setBackgroundColor(HIGHLIGHTING_COLOR);
    Editor projectEditor =
            FileEditorManager.getInstance(windowObjects.getProject()).getSelectedTextEditor();
    if (projectEditor != null) {
        PsiFile psiFile =
                PsiDocumentManager.getInstance(windowObjects.getProject()).
                        getPsiFile(projectEditor.getDocument());
        MarkupModel markupModel = projectEditor.getMarkupModel();
        if (markupModel != null) {
            markupModel.removeAllHighlighters();

            for (int line : linesForHighlighting) {
                line = line - 1;
                if (line < document.getLineCount()) {
                    int startOffset = document.getLineStartOffset(line);
                    int endOffset = document.getLineEndOffset(line);
                    String lineText =
                            document.getCharsSequence().
                                    subSequence(startOffset, endOffset).toString();
                    int lineStartOffset =
                            startOffset + lineText.length() - lineText.trim().length();
                    markupModel.addRangeHighlighter(lineStartOffset, endOffset,
                            HighlighterLayer.ERROR, attributes,
                            HighlighterTargetArea.EXACT_RANGE);
                    if (psiFile != null && psiFile.findElementAt(lineStartOffset) != null) {
                        HighlightUsagesHandler.doHighlightElements(projectEditor,
                                new PsiElement[]{psiFile.findElementAt(lineStartOffset)},
                                attributes, false);
                    }
                }
            }
        }
    }
}
 
Example 7
Source File: MyActionUtils.java    From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@NotNull
	public static List<RangeHighlighter> getRangeHighlightersAtOffset(Editor editor, int offset) {
		MarkupModel markupModel = editor.getMarkupModel();
		// collect all highlighters and combine to make a single tool tip
		List<RangeHighlighter> highlightersAtOffset = new ArrayList<RangeHighlighter>();
		for (RangeHighlighter r : markupModel.getAllHighlighters()) {
			int a = r.getStartOffset();
			int b = r.getEndOffset();
//			System.out.printf("#%d: %d..%d %s\n", i, a, b, r.toString());
			if (offset >= a && offset < b) { // cursor is over some kind of highlighting
				highlightersAtOffset.add(r);
			}
		}
		return highlightersAtOffset;
	}
 
Example 8
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 9
Source File: BreakpointItem.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected static void showInEditor(DetailView panel, VirtualFile virtualFile, int line) {
  TextAttributes attributes =
          EditorColorsManager.getInstance().getGlobalScheme().getAttributes(DebuggerColors.BREAKPOINT_ATTRIBUTES);

  DetailView.PreviewEditorState state = DetailView.PreviewEditorState.create(virtualFile, line, attributes);

  if (state.equals(panel.getEditorState())) {
    return;
  }

  panel.navigateInPreviewEditor(state);

  TextAttributes softerAttributes = attributes.clone();
  Color backgroundColor = softerAttributes.getBackgroundColor();
  if (backgroundColor != null) {
    softerAttributes.setBackgroundColor(ColorUtil.softer(backgroundColor));
  }

  final Editor editor = panel.getEditor();
  final MarkupModel editorModel = editor.getMarkupModel();
  final MarkupModel documentModel =
          DocumentMarkupModel.forDocument(editor.getDocument(), editor.getProject(), false);

  for (RangeHighlighter highlighter : documentModel.getAllHighlighters()) {
    if (highlighter.getUserData(DebuggerColors.BREAKPOINT_HIGHLIGHTER_KEY) == Boolean.TRUE) {
      final int line1 = editor.offsetToLogicalPosition(highlighter.getStartOffset()).line;
      if (line1 != line) {
        editorModel.addLineHighlighter(line1,
                                       DebuggerColors.BREAKPOINT_HIGHLIGHTER_LAYER + 1, softerAttributes);
      }
    }
  }
}
 
Example 10
Source File: ErrorStripeUpdateManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("WeakerAccess") // Used in Rider
public void repaintErrorStripePanel(@Nonnull Editor editor) {
  ApplicationManager.getApplication().assertIsDispatchThread();
  if (!myProject.isInitialized()) return;

  PsiFile file = myPsiDocumentManager.getPsiFile(editor.getDocument());
  final EditorMarkupModel markup = (EditorMarkupModel)editor.getMarkupModel();
  markup.setErrorPanelPopupHandler(new DaemonEditorPopup(myProject, editor));
  markup.setErrorStripTooltipRendererProvider(createTooltipRenderer(editor));
  markup.setMinMarkHeight(DaemonCodeAnalyzerSettings.getInstance().getErrorStripeMarkMinHeight());
  setOrRefreshErrorStripeRenderer(markup, file);
}
 
Example 11
Source File: DiffMarkup.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nullable
private MarkupModel getMarkupModel() {
  Editor editor = getEditor();
  return editor == null ? null : editor.getMarkupModel();
}
 
Example 12
Source File: DefaultHighlightInfoProcessor.java    From consulo with Apache License 2.0 4 votes vote down vote up
static void repaintErrorStripeAndIcon(@Nonnull Editor editor, @Nonnull Project project) {
  EditorMarkupModel markup = (EditorMarkupModel)editor.getMarkupModel();
  markup.repaintTrafficLightIcon();
  ErrorStripeUpdateManager.getInstance(project).repaintErrorStripePanel(editor);
}