Search in sources :

Example 26 with ProperTextRange

use of com.intellij.openapi.util.ProperTextRange in project intellij-community by JetBrains.

the class InjectedCaret method setSelection.

@Override
public void setSelection(int startOffset, int endOffset, boolean updateSystemSelection) {
    TextRange hostRange = myEditorWindow.getDocument().injectedToHost(new ProperTextRange(startOffset, endOffset));
    myDelegate.setSelection(hostRange.getStartOffset(), hostRange.getEndOffset(), updateSystemSelection);
}
Also used : ProperTextRange(com.intellij.openapi.util.ProperTextRange) ProperTextRange(com.intellij.openapi.util.ProperTextRange) TextRange(com.intellij.openapi.util.TextRange)

Example 27 with ProperTextRange

use of com.intellij.openapi.util.ProperTextRange in project intellij-community by JetBrains.

the class InjectedCaret method setSelection.

@Override
public void setSelection(@Nullable VisualPosition startPosition, int startOffset, @Nullable VisualPosition endPosition, int endOffset, boolean updateSystemSelection) {
    TextRange hostRange = myEditorWindow.getDocument().injectedToHost(new ProperTextRange(startOffset, endOffset));
    myDelegate.setSelection(startPosition, hostRange.getStartOffset(), endPosition, hostRange.getEndOffset(), updateSystemSelection);
}
Also used : ProperTextRange(com.intellij.openapi.util.ProperTextRange) ProperTextRange(com.intellij.openapi.util.ProperTextRange) TextRange(com.intellij.openapi.util.TextRange)

Example 28 with ProperTextRange

use of com.intellij.openapi.util.ProperTextRange in project intellij-community by JetBrains.

the class EditorMarkupModelImpl method offsetsToYPositions.

@NotNull
private ProperTextRange offsetsToYPositions(int start, int end) {
    if (!dimensionsAreValid) {
        recalcEditorDimensions();
    }
    Document document = myEditor.getDocument();
    int startLineNumber = end == -1 ? 0 : offsetToLine(start, document);
    int startY;
    int lineCount;
    int editorTargetHeight = Math.max(0, myEditorTargetHeight);
    if (myEditorSourceHeight < editorTargetHeight) {
        lineCount = 0;
        startY = myEditorScrollbarTop + startLineNumber * myEditor.getLineHeight();
    } else {
        lineCount = myEditorSourceHeight / myEditor.getLineHeight();
        startY = myEditorScrollbarTop + (int) ((float) startLineNumber / lineCount * editorTargetHeight);
    }
    int endY;
    int endLineNumber = offsetToLine(end, document);
    if (end == -1 || start == -1) {
        endY = Math.min(myEditorSourceHeight, editorTargetHeight);
    } else if (start == end || offsetToLine(start, document) == endLineNumber) {
        // both offsets are on the same line, no need to recalc Y position
        endY = startY;
    } else if (myEditorSourceHeight < editorTargetHeight) {
        endY = myEditorScrollbarTop + endLineNumber * myEditor.getLineHeight();
    } else {
        endY = myEditorScrollbarTop + (int) ((float) endLineNumber / lineCount * editorTargetHeight);
    }
    if (endY < startY)
        endY = startY;
    return new ProperTextRange(startY, endY);
}
Also used : ProperTextRange(com.intellij.openapi.util.ProperTextRange) com.intellij.codeInsight.hint(com.intellij.codeInsight.hint) RelativePoint(com.intellij.ui.awt.RelativePoint) NotNull(org.jetbrains.annotations.NotNull)

Example 29 with ProperTextRange

use of com.intellij.openapi.util.ProperTextRange in project intellij-community by JetBrains.

the class EditorMarkupModelImpl method markDirtied.

private void markDirtied(@NotNull ProperTextRange yPositions) {
    if (myDirtyYPositions != WHOLE_DOCUMENT) {
        int start = Math.max(0, yPositions.getStartOffset() - myEditor.getLineHeight());
        int end = myEditorScrollbarTop + myEditorTargetHeight == 0 ? yPositions.getEndOffset() + myEditor.getLineHeight() : Math.min(myEditorScrollbarTop + myEditorTargetHeight, yPositions.getEndOffset() + myEditor.getLineHeight());
        ProperTextRange adj = new ProperTextRange(start, Math.max(end, start));
        myDirtyYPositions = myDirtyYPositions == null ? adj : myDirtyYPositions.union(adj);
    }
    myEditorScrollbarTop = 0;
    myEditorSourceHeight = 0;
    myEditorTargetHeight = 0;
    dimensionsAreValid = false;
}
Also used : ProperTextRange(com.intellij.openapi.util.ProperTextRange) com.intellij.codeInsight.hint(com.intellij.codeInsight.hint) RelativePoint(com.intellij.ui.awt.RelativePoint)

Example 30 with ProperTextRange

use of com.intellij.openapi.util.ProperTextRange in project intellij-community by JetBrains.

the class EditorMarkupModelImpl method showToolTipByMouseMove.

private boolean showToolTipByMouseMove(@NotNull final MouseEvent e) {
    if (myEditor.getVisibleLineCount() == 0)
        return false;
    MouseEvent me = new MouseEvent(e.getComponent(), e.getID(), e.getWhen(), e.getModifiers(), 0, e.getY() + 1, e.getClickCount(), e.isPopupTrigger());
    final int visualLine = getVisualLineByEvent(e);
    myLastVisualLine = visualLine;
    Rectangle area = myEditor.getScrollingModel().getVisibleArea();
    int visualY = myEditor.getLineHeight() * visualLine;
    boolean isVisible = area.contains(area.x, visualY) && myWheelAccumulator == 0;
    if (UIUtil.uiParents(myEditor.getComponent(), false).filter(EditorWindowHolder.class).isEmpty() || isVisible || !UISettings.getInstance().getShowEditorToolTip()) {
        final Set<RangeHighlighter> highlighters = new THashSet<>();
        getNearestHighlighters(this, me.getY(), highlighters);
        getNearestHighlighters(((EditorEx) getEditor()).getFilteredDocumentMarkupModel(), me.getY(), highlighters);
        if (highlighters.isEmpty())
            return false;
        int y = e.getY();
        RangeHighlighter nearest = getNearestRangeHighlighter(e);
        if (nearest != null) {
            ProperTextRange range = offsetsToYPositions(nearest.getStartOffset(), nearest.getEndOffset());
            int eachStartY = range.getStartOffset();
            int eachEndY = range.getEndOffset();
            y = eachStartY + (eachEndY - eachStartY) / 2;
        }
        me = new MouseEvent(e.getComponent(), e.getID(), e.getWhen(), e.getModifiers(), me.getX(), y + 1, e.getClickCount(), e.isPopupTrigger());
        TooltipRenderer bigRenderer = myTooltipRendererProvider.calcTooltipRenderer(highlighters);
        if (bigRenderer != null) {
            showTooltip(me, bigRenderer, createHint(me));
            return true;
        }
        return false;
    } else {
        float rowRatio = (float) visualLine / (myEditor.getVisibleLineCount() - 1);
        int y = myRowAdjuster != 0 ? (int) (rowRatio * myEditor.getVerticalScrollBar().getHeight()) : me.getY();
        me = new MouseEvent(me.getComponent(), me.getID(), me.getWhen(), me.getModifiers(), me.getX(), y, me.getClickCount(), me.isPopupTrigger());
        final List<RangeHighlighterEx> highlighters = new ArrayList<>();
        collectRangeHighlighters(this, visualLine, highlighters);
        collectRangeHighlighters(myEditor.getFilteredDocumentMarkupModel(), visualLine, highlighters);
        myEditorFragmentRenderer.update(visualLine, highlighters, me.isAltDown());
        myEditorFragmentRenderer.show(myEditor, me.getPoint(), true, ERROR_STRIPE_TOOLTIP_GROUP, createHint(me));
        return true;
    }
}
Also used : ProperTextRange(com.intellij.openapi.util.ProperTextRange) com.intellij.codeInsight.hint(com.intellij.codeInsight.hint) RelativePoint(com.intellij.ui.awt.RelativePoint) THashSet(gnu.trove.THashSet) RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) EditorWindowHolder(com.intellij.openapi.fileEditor.impl.EditorWindowHolder)

Aggregations

ProperTextRange (com.intellij.openapi.util.ProperTextRange)31 TextRange (com.intellij.openapi.util.TextRange)14 com.intellij.codeInsight.hint (com.intellij.codeInsight.hint)4 PsiElement (com.intellij.psi.PsiElement)4 RelativePoint (com.intellij.ui.awt.RelativePoint)4 NotNull (org.jetbrains.annotations.NotNull)4 Nullable (org.jetbrains.annotations.Nullable)4 Document (com.intellij.openapi.editor.Document)2 Segment (com.intellij.openapi.util.Segment)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 List (java.util.List)2 BackgroundEditorHighlighter (com.intellij.codeHighlighting.BackgroundEditorHighlighter)1 HighlightingPass (com.intellij.codeHighlighting.HighlightingPass)1 EditorInfo (com.intellij.codeInsight.EditorInfo)1 DefaultHighlightInfoProcessor (com.intellij.codeInsight.daemon.impl.DefaultHighlightInfoProcessor)1 GeneralHighlightingPass (com.intellij.codeInsight.daemon.impl.GeneralHighlightingPass)1 LocalInspectionsPass (com.intellij.codeInsight.daemon.impl.LocalInspectionsPass)1 EmptyPass (com.intellij.codeInsight.daemon.impl.ProgressableTextEditorHighlightingPass.EmptyPass)1 GenericElementSignatureProvider (com.intellij.codeInsight.folding.impl.GenericElementSignatureProvider)1 InspectionManager (com.intellij.codeInspection.InspectionManager)1