Search in sources :

Example 66 with LogicalPosition

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

the class HintManagerImpl method showQuestionHint.

public void showQuestionHint(@NotNull final Editor editor, final int offset1, final int offset2, @NotNull final LightweightHint hint, @NotNull final QuestionAction action, @PositionFlags short constraint) {
    final LogicalPosition pos1 = editor.offsetToLogicalPosition(offset1);
    final LogicalPosition pos2 = editor.offsetToLogicalPosition(offset2);
    final Point p = getHintPosition(hint, editor, pos1, pos2, constraint);
    showQuestionHint(editor, p, offset1, offset2, hint, action, constraint);
}
Also used : LogicalPosition(com.intellij.openapi.editor.LogicalPosition) RelativePoint(com.intellij.ui.awt.RelativePoint)

Example 67 with LogicalPosition

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

the class SyncScrollSupport method syncVerticalScroll.

private static void syncVerticalScroll(@NotNull ScrollingContext context, @NotNull Rectangle newRectangle, @NotNull Rectangle oldRectangle) {
    if (newRectangle.y == oldRectangle.y)
        return;
    EditingSides sidesContainer = context.getSidesContainer();
    FragmentSide masterSide = context.getMasterSide();
    FragmentSide masterDiffSide = context.getMasterDiffSide();
    Editor master = sidesContainer.getEditor(masterSide);
    Editor slave = sidesContainer.getEditor(masterSide.otherSide());
    if (master == null || slave == null)
        return;
    if (master.isDisposed() || slave.isDisposed())
        return;
    int masterVerticalScrollOffset = master.getScrollingModel().getVerticalScrollOffset();
    int slaveVerticalScrollOffset = slave.getScrollingModel().getVerticalScrollOffset();
    Rectangle viewRect = master.getScrollingModel().getVisibleArea();
    int middleY = viewRect.height / 3;
    if (master.getDocument().getTextLength() == 0)
        return;
    LogicalPosition masterPos = master.xyToLogicalPosition(new Point(viewRect.x, masterVerticalScrollOffset + middleY));
    int masterCenterLine = masterPos.line;
    int scrollToLine = sidesContainer.getLineBlocks().transform(masterDiffSide, masterCenterLine);
    int offset;
    if (scrollToLine < 0) {
        offset = slaveVerticalScrollOffset + newRectangle.y - oldRectangle.y;
    } else {
        int correction = (masterVerticalScrollOffset + middleY) % master.getLineHeight();
        Point point = slave.logicalPositionToXY(new LogicalPosition(scrollToLine, masterPos.column));
        offset = point.y - middleY + correction;
    }
    int deltaHeaderOffset = getHeaderOffset(slave) - getHeaderOffset(master);
    doScrollVertically(slave.getScrollingModel(), offset + deltaHeaderOffset);
}
Also used : LogicalPosition(com.intellij.openapi.editor.LogicalPosition) EditingSides(com.intellij.openapi.diff.impl.EditingSides) FragmentSide(com.intellij.openapi.diff.impl.highlighting.FragmentSide) Editor(com.intellij.openapi.editor.Editor)

Example 68 with LogicalPosition

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

the class SyncScrollSupport method scrollEditor.

public static void scrollEditor(@NotNull Editor editor, int logicalLine) {
    editor.getCaretModel().moveToLogicalPosition(new LogicalPosition(logicalLine, 0));
    ScrollingModel scrollingModel = editor.getScrollingModel();
    scrollingModel.disableAnimation();
    scrollingModel.scrollToCaret(ScrollType.CENTER);
    scrollingModel.enableAnimation();
}
Also used : LogicalPosition(com.intellij.openapi.editor.LogicalPosition) ScrollingModel(com.intellij.openapi.editor.ScrollingModel)

Example 69 with LogicalPosition

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

the class FoldingTransformation method transform.

public int transform(int line) {
    FoldRegion foldRegion = findFoldRegion(line);
    int yOffset = 0;
    if (foldRegion != null) {
        int startLine = getStartLine(foldRegion);
        yOffset = (int) ((double) (line - startLine) / getLineLength(foldRegion) * myEditor.getLineHeight());
        line = startLine;
    }
    yOffset += myEditor.logicalPositionToXY(new LogicalPosition(line, 0)).y;
    final JComponent header = myEditor.getHeaderComponent();
    int headerOffset = header == null ? 0 : header.getHeight();
    return yOffset - myEditor.getScrollingModel().getVerticalScrollOffset() + headerOffset;
}
Also used : LogicalPosition(com.intellij.openapi.editor.LogicalPosition) FoldRegion(com.intellij.openapi.editor.FoldRegion)

Example 70 with LogicalPosition

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

the class DiffWalkerAction method actionPerformed.

public void actionPerformed(AnActionEvent event) {
    FocusDiffSide side = DiffUtil.getFocusDiffSide(event.getDataContext());
    if (side == null)
        return;
    int line = getLineNumberToGo(side);
    Editor editor = side.getEditor();
    if (line >= 0 && editor != null) {
        LogicalPosition pos = new LogicalPosition(line, 0);
        editor.getCaretModel().removeSecondaryCarets();
        editor.getCaretModel().moveToLogicalPosition(pos);
        editor.getScrollingModel().scrollToCaret(ScrollType.CENTER);
    }
}
Also used : LogicalPosition(com.intellij.openapi.editor.LogicalPosition) Editor(com.intellij.openapi.editor.Editor) FocusDiffSide(com.intellij.openapi.diff.impl.util.FocusDiffSide)

Aggregations

LogicalPosition (com.intellij.openapi.editor.LogicalPosition)97 Document (com.intellij.openapi.editor.Document)12 PsiElement (com.intellij.psi.PsiElement)12 Editor (com.intellij.openapi.editor.Editor)11 TextRange (com.intellij.openapi.util.TextRange)10 VirtualFile (com.intellij.openapi.vfs.VirtualFile)9 EditorEx (com.intellij.openapi.editor.ex.EditorEx)7 NotNull (org.jetbrains.annotations.NotNull)6 CaretModel (com.intellij.openapi.editor.CaretModel)5 RelativePoint (com.intellij.ui.awt.RelativePoint)5 JSFile (com.intellij.lang.javascript.psi.JSFile)4 EditorColorsManager (com.intellij.openapi.editor.colors.EditorColorsManager)4 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)4 Project (com.intellij.openapi.project.Project)4 PsiFile (com.intellij.psi.PsiFile)4 PsiReference (com.intellij.psi.PsiReference)4 PsiMultiReference (com.intellij.psi.impl.source.resolve.reference.impl.PsiMultiReference)4 Mark (com.maddyhome.idea.vim.common.Mark)4 HighlightManager (com.intellij.codeInsight.highlighting.HighlightManager)3 EditorHighlighter (com.intellij.openapi.editor.highlighter.EditorHighlighter)3