/** * 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 killWholeLine() { if (buf.length() == 0) { return false; int end; if (count < 0) { end = buf.cursor(); while (buf.atChar(end) != 0 && buf.atChar(end) != '\n') { end++; while (start > 0 && buf.atChar(start - 1) != '\n') { start--; start = buf.cursor(); while (start > 0 && buf.atChar(start - 1) != '\n') { start--; while (end < buf.length() && buf.atChar(end) != '\n') { end++; String killed = buf.substring(start, end); buf.cursor(start); buf.delete(end - start); killRing.add(killed); return true;
private CharSequence getFirstWord() { String s = buf.toString(); int i = 0; while (i < s.length() && !Character.isWhitespace(s.charAt(i))) { i++; } return s.substring(0, i); }
private boolean doCopyKillRegion(boolean kill) { if (regionMark > buf.length()) { regionMark = buf.length(); int end = buf.cursor(); if (start < end) { while (start > 0 && buf.atChar(start - 1) != '\n') { start--; while (end < buf.length() - 1 && buf.atChar(end + 1) != '\n') { end++; killRing.add(buf.substring(start, end)); if (kill) { buf.backspace(end - start); while (end > 0 && buf.atChar(end - 1) != '\n') { end--; while (start < buf.length() && buf.atChar(start) != '\n') { start++; killRing.addBackwards(buf.substring(end, start)); if (kill) { buf.cursor(end); buf.delete(start - end); } else if (regionMark > buf.cursor()) { if (isInViCmdMode()) { regionMark++;
protected boolean copyPrevWord() { if (count <= 0) { return false; } int t1, t0 = buf.cursor(); while (true) { t1 = t0; while (t0 > 0 && !isWord(buf.atChar(t0 - 1))) { t0--; } while (t0 > 0 && isWord(buf.atChar(t0 - 1))) { t0--; } if (--count == 0) { break; } if (t0 == 0) { return false; } } buf.write(buf.substring(t0, t1)); return true; }
protected boolean backwardKillWord() { if (count < 0) { return callNeg(this::killWord); } int x = buf.cursor(); while (count-- > 0) { while (x > 0 && !isWord(buf.atChar(x - 1))) { x--; } while (x > 0 && isWord(buf.atChar(x - 1))) { x--; } } killRing.addBackwards(buf.substring(x, buf.cursor())); buf.backspace(buf.cursor() - x); return true; }
int lstart = buf.cursor() - 1; int lend = buf.cursor(); while (buf.atChar(lstart) != 0 && buf.atChar(lstart) != '\n') { lstart--; while (buf.atChar(lend) != 0 && buf.atChar(lend) != '\n') { lend++; while (buf.cursor() <= lstart) { buf.move(1); while (buf.cursor() >= lend) { buf.move(-1); int c = buf.currChar(); buf.currChar(buf.prevChar()); buf.move(-1); buf.currChar(c); buf.move(neg ? 0 : 2);
if (buf.cursor() < buf.length() && buf.nextChar() == findChar) { buf.move(1); if (buf.cursor() > 0 && buf.prevChar() == findChar) { buf.move(-1); int cursor = buf.cursor(); while (count-- > 0) { do { buf.move(findDir); } while (buf.cursor() > 0 && buf.cursor() < buf.length() && buf.currChar() != findChar && buf.currChar() != '\n'); if (buf.cursor() <= 0 || buf.cursor() >= buf.length() || buf.currChar() == '\n') { buf.cursor(cursor); return false; buf.move(findTailAdd); buf.move(1);
AttributedString text = insertSecondaryPrompts(AttributedStringBuilder.append(prompt, buf.toString()), new ArrayList<>()); int promptLines = text.columnSplitLength(size.getColumns(), false, display.delayLineWrap()).size(); PostResult postResult = computePost(possible, null, null, completed); AttributedString t = insertSecondaryPrompts(AttributedStringBuilder.append(prompt, buf.toString()), new ArrayList<>()); int pl = t.columnSplitLength(size.getColumns(), false, display.delayLineWrap()).size(); PostResult pr = computePost(cands, null, null, current); if (pr.lines >= size.getRows() - pl) { post = null; int oldCursor = buf.cursor(); buf.cursor(buf.length()); redisplay(false); buf.cursor(oldCursor); println(); List<AttributedString> ls = postResult.post.columnSplitLength(size.getColumns(), false, display.delayLineWrap()); } else { sb.setLength(sb.length() - 1); buf.backspace(); buf.write(getLastBinding()); if (cands.isEmpty()) { post = null; pushBackBinding(); } else if (isSet(Option.AUTO_MENU)) { buf.backspace(escaper.apply(current, false).length()); doMenu(cands, current, escaper);
protected boolean viForwardWordEnd() { if (count < 0) { return callNeg(this::backwardWord); } while (count-- > 0) { while (buf.cursor() < buf.length()) { if (!isWhitespace(buf.nextChar())) { break; } buf.move(1); } if (buf.cursor() < buf.length()) { if (isViAlphaNum(buf.nextChar())) { buf.move(1); while (buf.cursor() < buf.length() && isViAlphaNum(buf.nextChar())) { buf.move(1); } } else { buf.move(1); while (buf.cursor() < buf.length() && !isViAlphaNum(buf.nextChar()) && !isWhitespace(buf.nextChar())) { buf.move(1); } } } } if (buf.cursor() < buf.length() && isInViMoveOperation()) { buf.move(1); } return true; }
Buffer originalBuffer = buf.copy(); searchIndex = -1; searchTerm = new StringBuffer(); case SEND_BREAK: beep(); buf.copyFrom(originalBuffer); return true; case HISTORY_INCREMENTAL_SEARCH_BACKWARD: buf.copyFrom(originalBuffer); searchFailing = false; } else { if (searchBackward) { boolean nextOnly = next; pair = matches(pat, buf.toString(), searchIndex).stream() .filter(p -> nextOnly ? p.v < buf.cursor() : p.v <= buf.cursor()) .max(Comparator.comparing(Pair::getV)) .orElse(null); pair = matches(pat, buf.toString(), searchIndex).stream() .filter(p -> nextOnly ? p.v > buf.cursor() : p.v >= buf.cursor()) .min(Comparator.comparing(Pair::getV)) .orElse(null); .orElse(null); if (pair == null && searchIndex >= 0) { pair = matches(pat, originalBuffer.toString(), -1).stream()
line = wrap(parser.parse(buf.toString(), buf.cursor(), ParseContext.COMPLETE)); } catch (Exception e) { Log.info("Error while parsing line", e); if (!line.word().equals(w)) { if (prefix) { buf.backspace(line.wordCursor()); } else { buf.move(line.word().length() - line.wordCursor()); buf.backspace(line.word().length()); buf.write(w); return true; buf.backspace(line.rawWordCursor()); } else { buf.move(line.rawWordLength() - line.rawWordCursor()); buf.backspace(line.rawWordLength()); buf.write(line.escape(completion.value(), completion.complete())); if (completion.complete()) { if (buf.currChar() != ' ') { buf.write(" "); } else { buf.move(1); if (SELF_INSERT.equals(ref) && chars.indexOf(getLastBinding().charAt(0)) >= 0 || ACCEPT_LINE.equals(ref)) { buf.backspace(completion.suffix().length());
protected boolean viYankWholeLine() { int s, e; int p = buf.cursor(); while (buf.move(-1) == -1 && buf.prevChar() != '\n') ; s = buf.cursor(); for (int i = 0; i < repeatCount; i++) { while (buf.move(1) == 1 && buf.prevChar() != '\n') ; } e = buf.cursor(); yankBuffer = buf.substring(s, e); if (!yankBuffer.endsWith("\n")) { yankBuffer += "\n"; } buf.cursor(p); return true; }