Search in sources :

Example 11 with VisualPosition

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

the class MoveCaretLeftOrRightWithSelectionHandler method doExecute.

@Override
protected void doExecute(Editor editor, @Nullable Caret caret, DataContext dataContext) {
    assert caret != null;
    VisualPosition currentPosition = caret.getVisualPosition();
    if (caret.isAtBidiRunBoundary() && (myMoveRight ^ currentPosition.leansRight)) {
        int selectionStartToUse = caret.getLeadSelectionOffset();
        VisualPosition selectionStartPositionToUse = caret.getLeadSelectionPosition();
        caret.moveToVisualPosition(currentPosition.leanRight(!currentPosition.leansRight));
        caret.setSelection(selectionStartPositionToUse, selectionStartToUse, caret.getVisualPosition(), caret.getOffset());
    } else {
        editor.getCaretModel().moveCaretRelatively(myMoveRight ? 1 : -1, 0, true, editor.isColumnMode(), caret == editor.getCaretModel().getPrimaryCaret());
    }
}
Also used : VisualPosition(com.intellij.openapi.editor.VisualPosition)

Example 12 with VisualPosition

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

the class EditorActionTest method testMoveRightAtFoldedLineEnd.

public void testMoveRightAtFoldedLineEnd() throws Exception {
    init("line1<caret>\nline2\nline3", TestFileType.TEXT);
    addCollapsedFoldRegion(5, 7, "...");
    executeAction(IdeActions.ACTION_EDITOR_MOVE_CARET_RIGHT);
    assertEquals(new VisualPosition(0, 6), myEditor.getCaretModel().getVisualPosition());
}
Also used : VisualPosition(com.intellij.openapi.editor.VisualPosition)

Example 13 with VisualPosition

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

the class FileInEditorProcessor method isCaretAboveTop.

private static boolean isCaretAboveTop(Editor editor, Rectangle area) {
    Caret caret = editor.getCaretModel().getCurrentCaret();
    VisualPosition caretVisualPosition = caret.getVisualPosition();
    int caretY = editor.visualPositionToXY(caretVisualPosition).y;
    return caretY < area.y;
}
Also used : VisualPosition(com.intellij.openapi.editor.VisualPosition) Caret(com.intellij.openapi.editor.Caret) LightweightHint(com.intellij.ui.LightweightHint)

Example 14 with VisualPosition

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

the class IntentionHintComponent method canPlaceBulbOnTheSameLine.

private static boolean canPlaceBulbOnTheSameLine(Editor editor) {
    if (ApplicationManager.getApplication().isUnitTestMode() || editor.isOneLineMode())
        return false;
    final int offset = editor.getCaretModel().getOffset();
    final VisualPosition pos = editor.offsetToVisualPosition(offset);
    int line = pos.line;
    final int firstNonSpaceColumnOnTheLine = EditorActionUtil.findFirstNonSpaceColumnOnTheLine(editor, line);
    if (firstNonSpaceColumnOnTheLine == -1)
        return false;
    final Point point = editor.visualPositionToXY(new VisualPosition(line, firstNonSpaceColumnOnTheLine));
    return point.x > AllIcons.Actions.RealIntentionBulb.getIconWidth() + (editor.isOneLineMode() ? SMALL_BORDER_SIZE : NORMAL_BORDER_SIZE) * 2;
}
Also used : VisualPosition(com.intellij.openapi.editor.VisualPosition) RelativePoint(com.intellij.ui.awt.RelativePoint) com.intellij.codeInsight.hint(com.intellij.codeInsight.hint) LightweightHint(com.intellij.ui.LightweightHint) RelativePoint(com.intellij.ui.awt.RelativePoint) HintHint(com.intellij.ui.HintHint)

Example 15 with VisualPosition

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

the class ConsoleGutterComponent method paintAnnotations.

private void paintAnnotations(Graphics g, Rectangle clip) {
    int lineHeight = editor.getLineHeight();
    int startLine = clip.y / lineHeight;
    int endLine = Math.min(((clip.y + clip.height) / lineHeight) + 1, editor.getVisibleLineCount());
    if (startLine >= endLine) {
        return;
    }
    if (!atLineStart) {
        g.setColor(JBColor.BLUE);
    }
    g.setFont(editor.getColorsScheme().getFont(EditorFontType.PLAIN));
    int y = ((startLine + 1) * lineHeight) - editor.getDescent();
    FontMetrics fontMetrics = editor.getFontMetrics(Font.PLAIN);
    for (int line = startLine; line < endLine; line++) {
        int logicalLine = editor.visualToLogicalPosition(new VisualPosition(line, 0)).line;
        if (atLineStart) {
            gutterContentProvider.drawIcon(logicalLine, g, y, editor);
        } else {
            String text = gutterContentProvider.getText(logicalLine, editor);
            if (text != null) {
                // right-aligned
                g.drawString(text, maxContentWidth - gap - fontMetrics.stringWidth(text), y);
            }
        }
        y += lineHeight;
    }
}
Also used : VisualPosition(com.intellij.openapi.editor.VisualPosition) HintHint(com.intellij.ui.HintHint) RelativePoint(com.intellij.ui.awt.RelativePoint)

Aggregations

VisualPosition (com.intellij.openapi.editor.VisualPosition)20 RelativePoint (com.intellij.ui.awt.RelativePoint)5 HintHint (com.intellij.ui.HintHint)3 LightweightHint (com.intellij.ui.LightweightHint)3 com.intellij.codeInsight.hint (com.intellij.codeInsight.hint)2 Editor (com.intellij.openapi.editor.Editor)2 LogicalPosition (com.intellij.openapi.editor.LogicalPosition)2 Project (com.intellij.openapi.project.Project)2 Nullable (org.jetbrains.annotations.Nullable)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Caret (com.intellij.openapi.editor.Caret)1 CaretModel (com.intellij.openapi.editor.CaretModel)1 Inlay (com.intellij.openapi.editor.Inlay)1 SoftWrap (com.intellij.openapi.editor.SoftWrap)1 SoftWrapModel (com.intellij.openapi.editor.SoftWrapModel)1 EditorEx (com.intellij.openapi.editor.ex.EditorEx)1 EditorImpl (com.intellij.openapi.editor.impl.EditorImpl)1 JBPopup (com.intellij.openapi.ui.popup.JBPopup)1 TextRange (com.intellij.openapi.util.TextRange)1 PsiElement (com.intellij.psi.PsiElement)1