public int moveCaretHorizontalWrap(@NotNull Editor editor, @NotNull Caret caret, int count) { // FIX - allows cursor over newlines int oldOffset = caret.getOffset(); int offset = Math.min(Math.max(0, caret.getOffset() + count), EditorHelper.getFileSize(editor)); if (offset == oldOffset) { return -1; } else { return offset; } }
/** * Gets the visual block end for the caret. */ public static int getVisualEnd(@NotNull Caret caret) { Integer visualEnd = caret.getUserData(VISUAL_END); if (visualEnd == null) { return caret.getOffset(); } else { return visualEnd; } }
/** * Gets the visual block start for the caret. */ public static int getVisualStart(@NotNull Caret caret) { Integer visualStart = caret.getUserData(VISUAL_START); if (visualStart == null) { return caret.getOffset(); } else { return visualStart; } }
/** * Gets the visual offset for the caret. */ public static int getVisualOffset(@NotNull Caret caret) { Integer visualOffset = caret.getUserData(VISUAL_OFFSET); if (visualOffset == null) { return caret.getOffset(); } else { return visualOffset; } }
/** * Gets the insertion start for the caret */ public static int getInsertStart(@NotNull Caret caret) { Integer ret = caret.getUserData(INSERT_START); if (ret == null) { return caret.getOffset(); } else { return ret; } }
public int moveCaretToSection(@NotNull Editor editor, @NotNull Caret caret, char type, int dir, int count) { if ((caret.getOffset() == 0 && count < 0) || (caret.getOffset() >= EditorHelper.getFileSize(editor) - 1 && count > 0)) { return -1; } else { int res = SearchHelper.findSection(editor, caret, type, dir, count); if (res != -1) { res = EditorHelper.normalizeOffset(editor, res, false); } return res; } }
public int moveCaretHorizontal(@NotNull Editor editor, @NotNull Caret caret, int count, boolean allowPastEnd) { int oldOffset = caret.getOffset(); int offset = EditorHelper.normalizeOffset(editor, caret.getLogicalPosition().line, oldOffset + count, allowPastEnd); if (offset == oldOffset) { return -1; } else { return offset; } }
public static int findUnmatchedBlock(@NotNull Editor editor, @NotNull Caret caret, char type, int count) { CharSequence chars = editor.getDocument().getCharsSequence(); int pos = caret.getOffset(); int loc = blockChars.indexOf(type); // What direction should we go now (-1 is backward, 1 is forward) int dir = loc % 2 == 0 ? -1 : 1; // Which character did we find and which should we now search for char match = blockChars.charAt(loc); char found = blockChars.charAt(loc - dir); return findBlockLocation(chars, found, match, dir, pos, count); }
private int searchNextWithDirection(@NotNull Editor editor, @NotNull Caret caret, int count, int dir) { searchHighlight(false); return findItOffset(editor, caret.getOffset(), count, dir, false); }
/** * Clears all the keystrokes from the current insert command * * @param editor The editor to clear strokes from. */ private void clearStrokes(@NotNull Editor editor) { strokes.clear(); repeatCharsCount = 0; for (Caret caret : editor.getCaretModel().getAllCarets()) { CaretData.setInsertStart(caret, caret.getOffset()); } }
public void indentLines(@NotNull Editor editor, @NotNull Caret caret, @NotNull DataContext context, int lines, int dir) { int start = caret.getOffset(); int end = VimPlugin.getMotion().moveCaretToLineEndOffset(editor, caret, lines - 1, false); indentRange(editor, caret, context, new TextRange(start, end), 1, dir); }
public int search(@NotNull Editor editor, @NotNull Caret caret, @NotNull String command, int count, int flags, boolean moveCursor) { final int res = search(editor, command, caret.getOffset(), count, flags); if (res != -1 && moveCursor) { VimPlugin.getMark().saveJumpLocation(editor); MotionGroup.moveCaret(editor, caret, res); } return res; }
/** * Inserts text into the document * * @param editor The editor to insert into * @param caret The caret to start insertion in * @param str The text to insert */ public void insertText(@NotNull Editor editor, @NotNull Caret caret, @NotNull String str) { int start = caret.getOffset(); editor.getDocument().insertString(start, str); caret.moveToOffset(start + str.length()); VimPlugin.getMark().setMark(editor, MarkGroup.MARK_CHANGE_POS, start); }
public static int findNextWord(@NotNull Editor editor, @NotNull Caret caret, int count, boolean bigWord) { CharSequence chars = editor.getDocument().getCharsSequence(); final int pos = caret.getOffset(); final int size = EditorHelper.getFileSize(editor); return findNextWord(chars, pos, size, count, bigWord, false); }
@Override public int getOffset(@NotNull Editor editor, @NotNull Caret caret, @NotNull DataContext context, int count, int rawCount, @Nullable Argument argument) { if (argument == null) { VimPlugin.indicateError(); return caret.getOffset(); } int res = VimPlugin.getMotion().moveCaretToNextCharacterOnLine(editor, caret, -count, argument.getCharacter()); VimPlugin.getMotion().setLastFTCmd(MotionGroup.LAST_F, argument.getCharacter()); return res; } }
@Override public int getOffset(@NotNull Editor editor, @NotNull Caret caret, @NotNull DataContext context, int count, int rawCount, @Nullable Argument argument) { if (argument == null) { VimPlugin.indicateError(); return caret.getOffset(); } int res = VimPlugin.getMotion().moveCaretToNextCharacterOnLine(editor, caret, count, argument.getCharacter()); VimPlugin.getMotion().setLastFTCmd(MotionGroup.LAST_f, argument.getCharacter()); return res; } }
public void autoIndentLines(@NotNull Editor editor, @NotNull Caret caret, @NotNull DataContext context, int count) { final int startLine = caret.getLogicalPosition().line; final int endLine = startLine + count - 1; if (endLine <= EditorHelper.getLineCount(editor)) { final TextRange range = new TextRange(caret.getOffset(), editor.getDocument().getLineEndOffset(endLine)); autoIndentRange(editor, caret, context, range); } }
@Override public int getOffset(@NotNull Editor editor, @NotNull Caret caret, @NotNull DataContext context, int count, int rawCount, @Nullable Argument argument) { if (argument == null) { VimPlugin.indicateError(); return caret.getOffset(); } int res = VimPlugin.getMotion().moveCaretToBeforeNextCharacterOnLine(editor, caret, -count, argument.getCharacter()); VimPlugin.getMotion().setLastFTCmd(MotionGroup.LAST_T, argument.getCharacter()); return res; } }
@Override public int getOffset(@NotNull Editor editor, @NotNull Caret caret, @NotNull DataContext context, int count, int rawCount, @Nullable Argument argument) { if (argument == null) { VimPlugin.indicateError(); return caret.getOffset(); } int res = VimPlugin.getMotion().moveCaretToBeforeNextCharacterOnLine(editor, caret, count, argument.getCharacter()); VimPlugin.getMotion().setLastFTCmd(MotionGroup.LAST_t, argument.getCharacter()); return res; } }
public void assertOffset(int... expectedOffsets) { final List<Caret> carets = myFixture.getEditor().getCaretModel().getAllCarets(); assertEquals("Wrong amount of carets", expectedOffsets.length, carets.size()); for (int i = 0; i < expectedOffsets.length; i++) { assertEquals(expectedOffsets[i], carets.get(i).getOffset()); } }