Package com.intellij.openapi.editor.markup

Examples of com.intellij.openapi.editor.markup.MarkupModel


  }

  @NotNull
  public static Optional<RangeHighlighter> findRangeHighlighterAtLine(final Editor editor, final Integer line) {
    if (line == null) return Optional.absent();
    final MarkupModel markupModel = editor.getMarkupModel();
    final RangeHighlighter[] highlighters = markupModel.getAllHighlighters();
    for (RangeHighlighter highlighter : highlighters) {
      final LogicalPosition logicalPosition = editor.offsetToLogicalPosition(highlighter.getStartOffset());
      final int lineOfHighlighter = logicalPosition.line;
      if (lineOfHighlighter == line - 1) {
        return Optional.of(highlighter);
View Full Code Here


  private void createInvisibleHighlighter(PsiFile psiFile, final SonarIssue issue, final TextRange textRange) {
    final Optional<Document> document = Finders.findDocumentFromPsiFile(psiFile);
    final List<Editor> editors = Finders.findEditorsFrom(document.get());
    for (final Editor editor : editors) {

      final MarkupModel markupModel = editor.getMarkupModel();

      ApplicationManager.getApplication().invokeLater(new Runnable() {
        @Override
        public void run() {
          final Optional<RangeHighlighter> rangeHighlighterAtLine = Finders.findRangeHighlighterAtLine(editor, issue.getLine());
          if (rangeHighlighterAtLine.isPresent()) {
            final Set<SonarIssue> issuesOfHighlighter = rangeHighlighterAtLine.get().getUserData(KEY);
            if (null != issuesOfHighlighter) {
              issuesOfHighlighter.add(issue);
            }
          } else {
            TextAttributes attrs = new TextAttributes();
//            uncomment to make visible
//            attrs.setForegroundColor(JBColor.BLUE);
            final RangeHighlighter rangeHighlighter = markupModel.addRangeHighlighter(
                textRange.getStartOffset(),
                textRange.getEndOffset(),
                0,
                attrs,
                HighlighterTargetArea.EXACT_RANGE);
View Full Code Here

            offsets[++i] = lastOffset + str.length();
            sb.append(str);
        }
        LOG.debug("printToHistory(): text processed");
        final Document history = myHistoryViewer.getDocument();
        final MarkupModel markupModel = DocumentMarkupModel.forDocument(history, myProject, true);
        final int oldHistoryLength = history.getTextLength();
        appendToHistoryDocument(history, sb.toString());
        assert (oldHistoryLength + offsets[i]) == history.getTextLength()
                : "Last offset - " + offsets[i] + " history length: old " + oldHistoryLength + ", new - " + history.getTextLength();
        LOG.debug("printToHistory(): text added");
        i = 0;
        for (final Pair<String, TextAttributes> pair : attributedText) {
            markupModel.addRangeHighlighter(oldHistoryLength + offsets[i],
                    oldHistoryLength + offsets[i + 1],
                    HighlighterLayer.SYNTAX,
                    pair.getSecond(),
                    HighlighterTargetArea.EXACT_RANGE);
            ++i;
View Full Code Here

    public void printToHistory(String text, final TextAttributes attributes) {
        ApplicationManager.getApplication().assertIsDispatchThread();
        text = StringUtil.convertLineSeparators(text);
        final boolean scrollToEnd = shouldScrollHistoryToEnd();
        final Document history = myHistoryViewer.getDocument();
        final MarkupModel markupModel = DocumentMarkupModel.forDocument(history, myProject, true);
        final int offset = history.getTextLength();
        appendToHistoryDocument(history, text);
        markupModel.addRangeHighlighter(offset,
                history.getTextLength(),
                HighlighterLayer.SYNTAX,
                attributes,
                HighlighterTargetArea.EXACT_RANGE);
        if (scrollToEnd) {
View Full Code Here

        myHistoryViewer.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
    }

    protected String addTextRangeToHistory(TextRange textRange, final EditorEx consoleEditor, boolean preserveMarkup) {
        final Document history = myHistoryViewer.getDocument();
        final MarkupModel markupModel = DocumentMarkupModel.forDocument(history, myProject, true);
        if (myPrompt != null) {
            appendToHistoryDocument(history, myPrompt);
        }

        final int localStartOffset = textRange.getStartOffset();
        String text;
        EditorHighlighter highlighter;
        if (consoleEditor instanceof EditorWindow) {
            EditorWindow editorWindow = (EditorWindow) consoleEditor;
            EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
            PsiFile file = editorWindow.getInjectedFile();
            final VirtualFile virtualFile = file.getVirtualFile();
            assert virtualFile != null;
            highlighter = HighlighterFactory.createHighlighter(virtualFile, scheme, getProject());
            String fullText = InjectedLanguageUtil.getUnescapedText(file, null, null);
            highlighter.setText(fullText);
            text = textRange.substring(fullText);
        } else {
            text = consoleEditor.getDocument().getText(textRange);
            highlighter = consoleEditor.getHighlighter();
        }
        //offset can be changed after text trimming after insert due to buffer constraints
        appendToHistoryDocument(history, text);
        int offset = history.getTextLength() - text.length();

        final HighlighterIterator iterator = highlighter.createIterator(localStartOffset);
        final int localEndOffset = textRange.getEndOffset();
        while (!iterator.atEnd()) {
            final int itStart = iterator.getStart();
            if (itStart > localEndOffset) break;
            final int itEnd = iterator.getEnd();
            if (itEnd >= localStartOffset) {
                final int start = Math.max(itStart, localStartOffset) - localStartOffset + offset;
                final int end = Math.min(itEnd, localEndOffset) - localStartOffset + offset;
                markupModel.addRangeHighlighter(start, end, HighlighterLayer.SYNTAX, iterator.getTextAttributes(),
                        HighlighterTargetArea.EXACT_RANGE);
            }
            iterator.advance();
        }
        if (!text.endsWith("\n")) {
View Full Code Here

        }
    }

    public void addComment(Editor editor, ChangeInfo changeInfo, String revisionId, Project project, Comment comment) {
        if (editor == null) return;
        MarkupModel markup = editor.getMarkupModel();

        RangeHighlighter rangeHighlighter = null;
        if (comment.range != null) {
            rangeHighlighter = highlightRangeComment(comment.range, editor, project);
        }

        int lineCount = markup.getDocument().getLineCount();

        int line = comment.line - 1;
        if (line < 0) {
            line = 0;
        }
        if (line > lineCount - 1) {
            line = lineCount - 1;
        }
        if (line >= 0) {
            final RangeHighlighter highlighter = markup.addLineHighlighter(line, HighlighterLayer.ERROR + 1, null);
            CommentGutterIconRenderer iconRenderer = new CommentGutterIconRenderer(
                    this, editor, gerritUtil, selectedRevisions, addCommentActionBuilder,
                    comment, changeInfo, revisionId, highlighter, rangeHighlighter);
            highlighter.setGutterIconRenderer(iconRenderer);
        }
View Full Code Here

            String shortClassName = getShortClassName(marker);

            if (map.containsKey(shortClassName)) {

                if (addRenderer) {
                    MarkupModel model = getMarkupModel(map, shortClassName, project);
                    addRenderers(marker, model);
                }

                // TODO clean up
                tableModel.setVirtualFileAt(tableModel.getRowCount(),
View Full Code Here

        }
    }

    public static void addMarkersToFile(Project project, VirtualFile file,
                                        Iterable<VulnerabilityMarker> markers) {
        MarkupModel model = getMarkupModel(file, project, true);

        for (VulnerabilityMarker marker : markers) {
            String shortClassName = getShortClassName(marker);
            if (shortClassName != null && shortClassName.equals(file.getName())) {
                addRenderers(marker, model);
View Full Code Here

        removeAll(fileSet, project);
    }

    private static void removeAll(Collection<VirtualFile> files, Project project) {
        for (VirtualFile virtualFile : files) {
            MarkupModel model = getMarkupModel(virtualFile, project, false);

            if (model != null) {
                removeThreadFixRenderers(model);
            }
        }
View Full Code Here

                                              Project project) {
        return getMarkupModel(map.get(shortClassName).iterator().next(), project, true);
    }

    private static MarkupModel getMarkupModel(VirtualFile virtualFile, Project project, boolean create) {
        MarkupModel returnModel = null;

        Document document = FileDocumentManager.getInstance().getDocument(virtualFile);

        if (document != null) {
            returnModel = DocumentMarkupModel.forDocument(document, project, create);
View Full Code Here

TOP

Related Classes of com.intellij.openapi.editor.markup.MarkupModel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.