private int findeol() { int x = buf.cursor(); while (x < buf.length() && buf.atChar(x) != '\n') { x++; } return x; }
protected boolean viChangeEol() { return viChange(buf.cursor(), buf.length()) && setKeyMap(VIINS); }
protected boolean deleteChar() { if (count < 0) { return callNeg(this::backwardDeleteChar); } if (buf.cursor() == buf.length()) { return false; } buf.delete(count); return true; }
protected boolean deleteWord() { if (count < 0) { return callNeg(this::backwardDeleteWord); } int x = buf.cursor(); while (count-- > 0) { while (x < buf.length() && !isWord(buf.atChar(x))) { x++; } while (x < buf.length() && isWord(buf.atChar(x))) { x++; } } buf.delete(x - buf.cursor()); return true; }
protected boolean viFirstNonBlank() { beginningOfLine(); while (buf.cursor() < buf.length() && isWhitespace(buf.currChar())) { buf.move(1); } return true; }
protected boolean upCaseWord() { int count = Math.abs(this.count); int cursor = buf.cursor(); while (count-- > 0) { while (buf.cursor() < buf.length() && !isWord(buf.currChar())) { buf.move(1); } while (buf.cursor() < buf.length() && isWord(buf.currChar())) { buf.currChar(Character.toUpperCase(buf.currChar())); buf.move(1); } } if (this.count < 0) { buf.cursor(cursor); } return true; }
protected boolean downCaseWord() { int count = Math.abs(this.count); int cursor = buf.cursor(); while (count-- > 0) { while (buf.cursor() < buf.length() && !isWord(buf.currChar())) { buf.move(1); } while (buf.cursor() < buf.length() && isWord(buf.currChar())) { buf.currChar(Character.toLowerCase(buf.currChar())); buf.move(1); } } if (this.count < 0) { buf.cursor(cursor); } return true; }
protected boolean viForwardBlankWordEnd() { if (count < 0) { return false; } while (count-- > 0) { while (buf.cursor() < buf.length()) { buf.move(1); if (!isWhitespace(buf.currChar())) { break; } } while (buf.cursor() < buf.length()) { buf.move(1); if (isWhitespace(buf.currChar())) { break; } } } return true; }
protected boolean emacsForwardWord() { if (count < 0) { return callNeg(this::emacsBackwardWord); } while (count-- > 0) { while (buf.cursor() < buf.length() && !isWord(buf.currChar())) { buf.move(1); } if (isInViChangeOperation() && count == 0) { return true; } while (buf.cursor() < buf.length() && isWord(buf.currChar())) { buf.move(1); } } return true; }
/** * Pasts the yank buffer to the right of the current cursor position * and moves the cursor to the end of the pasted region. * @return <code>true</code> */ protected boolean viPutAfter() { if (yankBuffer.indexOf('\n') >= 0) { while (buf.move(1) == 1 && buf.currChar() != '\n'); buf.move(1); putString(yankBuffer); buf.move(- yankBuffer.length()); } else if (yankBuffer.length () != 0) { if (buf.cursor() < buf.length()) { buf.move(1); } for (int i = 0; i < count; i++) { putString(yankBuffer); } buf.move(-1); } return true; }
protected boolean forwardWord() { if (count < 0) { return callNeg(this::backwardWord); } while (count-- > 0) { while (buf.cursor() < buf.length() && isWord(buf.currChar())) { buf.move(1); } if (isInViChangeOperation() && count == 0) { break; } while (buf.cursor() < buf.length() && !isWord(buf.currChar())) { buf.move(1); } } return true; }
protected boolean capitalizeWord() { int count = Math.abs(this.count); int cursor = buf.cursor(); while (count-- > 0) { boolean first = true; while (buf.cursor() < buf.length() && !isWord(buf.currChar())) { buf.move(1); } while (buf.cursor() < buf.length() && isWord(buf.currChar()) && !isAlpha(buf.currChar())) { buf.move(1); } while (buf.cursor() < buf.length() && isWord(buf.currChar())) { buf.currChar(first ? Character.toUpperCase(buf.currChar()) : Character.toLowerCase(buf.currChar())); buf.move(1); first = false; } } if (this.count < 0) { buf.cursor(cursor); } return true; }
protected boolean historySearchBackward() { if (historyBuffer == null || buf.length() == 0 || !buf.toString().equals(history.current())) { historyBuffer = buf.copy(); searchBuffer = getFirstWord(); } int searchIndex = searchBackwards(searchBuffer.toString(), history.index(), true); if (searchIndex == -1) { return false; } else { // Maintain cursor position while searching. if (history.moveTo(searchIndex)) { setBuffer(history.current()); } else { return false; } } return true; }
protected boolean killWord() { if (count < 0) { return callNeg(this::backwardKillWord); } int x = buf.cursor(); while (count-- > 0) { while (x < buf.length() && !isWord(buf.atChar(x))) { x++; } while (x < buf.length() && isWord(buf.atChar(x))) { x++; } } killRing.add(buf.substring(buf.cursor(), x)); buf.delete(x - buf.cursor()); return true; }
/** * Switches the case of the current character from upper to lower * or lower to upper as necessary and advances the cursor one * position to the right. * @return <code>true</code> if it succeeded, <code>false</code> otherwise */ protected boolean viSwapCase() { for (int i = 0; i < count; i++) { if (buf.cursor() < buf.length()) { int ch = buf.atChar(buf.cursor()); ch = switchCase(ch); buf.currChar(ch); buf.move(1); } else { return false; } } return true; }
protected boolean viForwardBlankWord() { if (count < 0) { return callNeg(this::viBackwardBlankWord); } while (count-- > 0) { while (buf.cursor() < buf.length() && !isWhitespace(buf.currChar())) { buf.move(1); } if (isInViChangeOperation() && count == 0) { return true; } int nl = buf.currChar() == '\n' ? 1 : 0; while (buf.cursor() < buf.length() && nl < 2 && isWhitespace(buf.currChar())) { buf.move(1); nl += buf.currChar() == '\n' ? 1 : 0; } } return true; }
protected void doCleanup(boolean nl) { buf.cursor(buf.length()); post = null; if (size.getColumns() > 0 || size.getRows() > 0) { redisplay(false); if (nl) { println(); } terminal.puts(Capability.keypad_local); terminal.trackMouse(Terminal.MouseTracking.Off); if (isSet(Option.BRACKETED_PASTE)) terminal.writer().write(BRACKETED_PASTE_OFF); flush(); } history.moveToEnd(); }