Search in sources :

Example 16 with RangeHighlighter

use of com.intellij.openapi.editor.markup.RangeHighlighter in project intellij-community by JetBrains.

the class EditorMarkupModelImpl method doClick.

private void doClick(@NotNull final MouseEvent e) {
    RangeHighlighter marker = getNearestRangeHighlighter(e);
    int offset;
    LogicalPosition logicalPositionToScroll = null;
    if (marker == null) {
        if (myEditorPreviewHint != null) {
            logicalPositionToScroll = myEditor.visualToLogicalPosition(new VisualPosition(myEditorFragmentRenderer.myStartVisualLine, 0));
            offset = myEditor.getDocument().getLineStartOffset(logicalPositionToScroll.line);
        } else {
            return;
        }
    } else {
        offset = marker.getStartOffset();
    }
    final Document doc = myEditor.getDocument();
    if (doc.getLineCount() > 0 && myEditorPreviewHint == null) {
        // Necessary to expand folded block even if navigating just before one
        // Very useful when navigating to first unused import statement.
        int lineEnd = doc.getLineEndOffset(doc.getLineNumber(offset));
        myEditor.getCaretModel().moveToOffset(lineEnd);
    }
    myEditor.getCaretModel().removeSecondaryCarets();
    myEditor.getCaretModel().moveToOffset(offset);
    myEditor.getSelectionModel().removeSelection();
    ScrollingModel scrollingModel = myEditor.getScrollingModel();
    scrollingModel.disableAnimation();
    if (logicalPositionToScroll != null) {
        int lineY = myEditor.logicalPositionToXY(logicalPositionToScroll).y;
        int relativePopupOffset = myEditorFragmentRenderer.myRelativeY;
        scrollingModel.scrollVertically(lineY - relativePopupOffset);
    } else {
        scrollingModel.scrollToCaret(ScrollType.CENTER);
    }
    scrollingModel.enableAnimation();
    if (marker != null) {
        fireErrorMarkerClicked(marker, e);
    }
}
Also used : RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) com.intellij.codeInsight.hint(com.intellij.codeInsight.hint) RelativePoint(com.intellij.ui.awt.RelativePoint)

Example 17 with RangeHighlighter

use of com.intellij.openapi.editor.markup.RangeHighlighter in project intellij-community by JetBrains.

the class EditorImpl method setHighlightingFilter.

public void setHighlightingFilter(@Nullable Condition<RangeHighlighter> filter) {
    if (myHighlightingFilter == filter)
        return;
    Condition<RangeHighlighter> oldFilter = myHighlightingFilter;
    myHighlightingFilter = filter;
    for (RangeHighlighter highlighter : myDocumentMarkupModel.getDelegate().getAllHighlighters()) {
        boolean oldAvailable = oldFilter == null || oldFilter.value(highlighter);
        boolean newAvailable = filter == null || filter.value(highlighter);
        if (oldAvailable != newAvailable) {
            myMarkupModelListener.attributesChanged((RangeHighlighterEx) highlighter, true, EditorUtil.attributesImpactFontStyleOrColor(highlighter.getTextAttributes()));
        }
    }
}
Also used : RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter)

Example 18 with RangeHighlighter

use of com.intellij.openapi.editor.markup.RangeHighlighter in project intellij-community by JetBrains.

the class ApplyPatchChange method createOperation.

@Nullable
private MyGutterOperation createOperation(@NotNull OperationType type) {
    if (isResolved())
        return null;
    EditorEx editor = myViewer.getPatchEditor();
    Document document = editor.getDocument();
    int line = getPatchRange().start;
    int offset = line == DiffUtil.getLineCount(document) ? document.getTextLength() : document.getLineStartOffset(line);
    RangeHighlighter highlighter = editor.getMarkupModel().addRangeHighlighter(offset, offset, HighlighterLayer.ADDITIONAL_SYNTAX, null, HighlighterTargetArea.LINES_IN_RANGE);
    return new MyGutterOperation(highlighter, type);
}
Also used : RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) EditorEx(com.intellij.openapi.editor.ex.EditorEx) Document(com.intellij.openapi.editor.Document) Nullable(org.jetbrains.annotations.Nullable)

Example 19 with RangeHighlighter

use of com.intellij.openapi.editor.markup.RangeHighlighter in project intellij-community by JetBrains.

the class ApplyPatchChange method destroyHighlighters.

private void destroyHighlighters() {
    for (RangeHighlighter highlighter : myHighlighters) {
        highlighter.dispose();
    }
    myHighlighters.clear();
    for (MyGutterOperation operation : myOperations) {
        operation.dispose();
    }
    myOperations.clear();
}
Also used : RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter)

Example 20 with RangeHighlighter

use of com.intellij.openapi.editor.markup.RangeHighlighter in project intellij-community by JetBrains.

the class LineStatusTracker method createHighlighter.

@Override
@CalledInAwt
protected void createHighlighter(@NotNull Range range) {
    myApplication.assertIsDispatchThread();
    if (range.getHighlighter() != null) {
        LOG.error("Multiple highlighters registered for the same Range");
        return;
    }
    if (myMode == Mode.SILENT)
        return;
    int first = range.getLine1() >= getLineCount(myDocument) ? myDocument.getTextLength() : myDocument.getLineStartOffset(range.getLine1());
    int second = range.getLine2() >= getLineCount(myDocument) ? myDocument.getTextLength() : myDocument.getLineStartOffset(range.getLine2());
    MarkupModel markupModel = DocumentMarkupModel.forDocument(myDocument, myProject, true);
    RangeHighlighter highlighter = LineStatusMarkerRenderer.createRangeHighlighter(range, new TextRange(first, second), markupModel);
    highlighter.setLineMarkerRenderer(LineStatusMarkerRenderer.createRenderer(range, (editor) -> {
        return new LineStatusTrackerDrawing.MyLineStatusMarkerPopup(this, editor, range);
    }));
    highlighter.setEditorFilter(MarkupEditorFilterFactory.createIsNotDiffFilter());
    range.setHighlighter(highlighter);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Document(com.intellij.openapi.editor.Document) Key(com.intellij.openapi.util.Key) FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) DiffUtil.getLineCount(com.intellij.diff.util.DiffUtil.getLineCount) TextRange(com.intellij.openapi.util.TextRange) DocumentMarkupModel(com.intellij.openapi.editor.impl.DocumentMarkupModel) FileEditor(com.intellij.openapi.fileEditor.FileEditor) MarkupModel(com.intellij.openapi.editor.markup.MarkupModel) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) EditorNotificationPanel(com.intellij.ui.EditorNotificationPanel) List(java.util.List) VcsDirtyScopeManager(com.intellij.openapi.vcs.changes.VcsDirtyScopeManager) RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) Project(com.intellij.openapi.project.Project) MarkupEditorFilterFactory(com.intellij.openapi.editor.markup.MarkupEditorFilterFactory) NotNull(org.jetbrains.annotations.NotNull) DocumentImpl(com.intellij.openapi.editor.impl.DocumentImpl) CalledInAwt(org.jetbrains.annotations.CalledInAwt) TransactionGuard(com.intellij.openapi.application.TransactionGuard) javax.swing(javax.swing) RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) TextRange(com.intellij.openapi.util.TextRange) DocumentMarkupModel(com.intellij.openapi.editor.impl.DocumentMarkupModel) MarkupModel(com.intellij.openapi.editor.markup.MarkupModel) CalledInAwt(org.jetbrains.annotations.CalledInAwt)

Aggregations

RangeHighlighter (com.intellij.openapi.editor.markup.RangeHighlighter)102 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)29 TextRange (com.intellij.openapi.util.TextRange)23 HighlightManager (com.intellij.codeInsight.highlighting.HighlightManager)18 Editor (com.intellij.openapi.editor.Editor)17 ArrayList (java.util.ArrayList)16 NotNull (org.jetbrains.annotations.NotNull)15 Project (com.intellij.openapi.project.Project)13 EditorColorsManager (com.intellij.openapi.editor.colors.EditorColorsManager)10 MarkupModel (com.intellij.openapi.editor.markup.MarkupModel)10 Document (com.intellij.openapi.editor.Document)9 RelativePoint (com.intellij.ui.awt.RelativePoint)8 Nullable (org.jetbrains.annotations.Nullable)8 EditorEx (com.intellij.openapi.editor.ex.EditorEx)7 MarkupModelEx (com.intellij.openapi.editor.ex.MarkupModelEx)7 PsiElement (com.intellij.psi.PsiElement)6 EditorWindow (com.intellij.injected.editor.EditorWindow)4 Result (com.intellij.openapi.application.Result)4 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)4 LogicalPosition (com.intellij.openapi.editor.LogicalPosition)4