/** * Converts a visual line number to a logical line number. * * @param editor The editor * @param line The visual line number to convert * @return The logical line number */ public static int visualLineToLogicalLine(@NotNull final Editor editor, final int line) { int logicalLine = editor.visualToLogicalPosition(new VisualPosition(line, 0)).line; return normalizeLine(editor, logicalLine); }
public int moveCaretToLineEnd(@NotNull Editor editor, @NotNull Caret caret) { final VisualPosition visualPosition = caret.getVisualPosition(); final int lastVisualLineColumn = EditorUtil.getLastVisualLineColumnNumber(editor, visualPosition.line); final VisualPosition visualEndOfLine = new VisualPosition(visualPosition.line, lastVisualLineColumn, true); return moveCaretToLineEnd(editor, editor.visualToLogicalPosition(visualEndOfLine).line, true); }
public int moveCaretVertical(@NotNull Editor editor, @NotNull Caret caret, int count) { VisualPosition pos = caret.getVisualPosition(); if ((pos.line == 0 && count < 0) || (pos.line >= EditorHelper.getVisualLineCount(editor) - 1 && count > 0)) { return -1; } else { int col = CaretData.getLastColumn(caret); int line = EditorHelper.normalizeVisualLine(editor, pos.line + count); VisualPosition newPos = new VisualPosition(line, EditorHelper .normalizeVisualColumn(editor, line, col, CommandState.inInsertMode(editor))); return EditorHelper.visualPositionToOffset(editor, newPos); } }
/** * Inserts the character above/below the cursor at the cursor location * * @param editor The editor to insert into * @param caret The caret to insert after * @param dir 1 for getting from line below cursor, -1 for getting from line above cursor * @return true if able to get the character and insert it, false if not */ public boolean insertCharacterAroundCursor(@NotNull Editor editor, @NotNull Caret caret, int dir) { boolean res = false; VisualPosition vp = caret.getVisualPosition(); vp = new VisualPosition(vp.line + dir, vp.column); int len = EditorHelper.getLineLength(editor, EditorHelper.visualLineToLogicalLine(editor, vp.line)); if (vp.column < len) { int offset = EditorHelper.visualPositionToOffset(editor, vp); char ch = editor.getDocument().getCharsSequence().charAt(offset); editor.getDocument().insertString(caret.getOffset(), Character.toString(ch)); MotionGroup.moveCaret(editor, caret, VimPlugin.getMotion().moveCaretHorizontal(editor, caret, 1, true)); res = true; } return res; }
public void testUpDownMove() { final Editor editor = typeTextInFile(parseKeys("2j", "k"), "one\n" + "tw<caret>o\n" + "three\n" + "four\n"); final VisualPosition position = editor.getCaretModel().getVisualPosition(); assertEquals(new VisualPosition(2, 2), position); }
caret.moveToVisualPosition(new VisualPosition(visualLine + i, repeatColumn)); repeatInsertText(editor, context, started ? (i == 0 ? count : count + 1) : count);
CommandState.Mode.REPLACE); if (col != vp.column) { caretModel.moveToVisualPosition(new VisualPosition(vp.line, col));
int offset = EditorHelper.visualPositionToOffset(editor, new VisualPosition(newline, newColumn)); moveCaret(editor, editor.getCaretModel().getPrimaryCaret(), offset);