/** * Implement the "vi" yank-to operation. This operation allows you * to yank the contents of the current line based upon a move operation, * for example "yw" yanks the current word, "3yw" yanks 3 words, etc. * * @param startPos The starting position from which to yank * @param endPos The ending position to which to yank * @return <code>true</code> if the yank succeeded */ protected boolean viYankTo(int startPos, int endPos) { int cursorPos = startPos; if (endPos < startPos) { int tmp = endPos; endPos = startPos; startPos = tmp; } if (startPos == endPos) { yankBuffer = ""; return true; } yankBuffer = buf.substring(startPos, endPos); /* * It was a movement command that moved the cursor to find the * end position, so put the cursor back where it started. */ buf.cursor(cursorPos); return true; }
@Override public void complete(LineReader reader, ParsedLine line, List<Candidate> candidates) { final String bufferStr = reader.getBuffer().substring(0).trim(); if (bufferStr.startsWith(SqlLine.COMMAND_PREFIX) && !bufferStr.startsWith(SqlLine.COMMAND_PREFIX + "all") && !bufferStr.startsWith(SqlLine.COMMAND_PREFIX + "sql")) { sqlLine.getCommandCompleter().complete(reader, line, candidates); } else if (sqlLine.getDatabaseConnection() != null && sqlLine.getDatabaseConnection().getSqlCompleter() != null) { sqlLine.getDatabaseConnection().getSqlCompleter() .complete(reader, line, candidates); } } }
@Override public void complete(LineReader reader, ParsedLine line, List<Candidate> candidates) { String bufferStr = reader.getBuffer().substring(0); if (bufferStr.startsWith(SqlLine.COMMAND_PREFIX) && !bufferStr.startsWith(SqlLine.COMMAND_PREFIX + "all") && !bufferStr.startsWith(SqlLine.COMMAND_PREFIX + "sql")) { sqlLine.getCommandCompleter().complete(reader, line, candidates); } else if (sqlLine.getDatabaseConnection() != null && sqlLine.getDatabaseConnection().getSqlCompleter() != null) { sqlLine.getDatabaseConnection().getSqlCompleter() .complete(reader, line, candidates); } } }
protected boolean viKillEol() { int eol = findeol(); if (buf.cursor() == eol) { return false; } killRing.add(buf.substring(buf.cursor(), eol)); buf.delete(eol - buf.cursor()); return true; }
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; }
String res = buf.substring(0, sta1) + buf.substring(sta2, end2) + buf.substring(end1, sta2) + buf.substring(sta1, end1) + buf.substring(end2); buf.clear(); buf.write(res); buf.cursor(neg ? end1 : end2); } else { String res = buf.substring(0, sta2) + buf.substring(sta1, end1) + buf.substring(end2, sta1) + buf.substring(sta2, end2) + buf.substring(end1); buf.clear(); buf.write(res);
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; }
end++; killRing.add(buf.substring(start, end)); if (kill) { buf.backspace(end - start); start++; killRing.addBackwards(buf.substring(end, start)); if (kill) { buf.cursor(end); regionMark++; killRing.add(buf.substring(buf.cursor(), regionMark)); if (kill) { buf.delete(regionMark - buf.cursor()); buf.move(1); killRing.add(buf.substring(regionMark, buf.cursor())); if (kill) { buf.backspace(buf.cursor() - regionMark);
/** * Kill the buffer ahead of the current cursor position. * * @return true if successful */ public boolean killLine() { if (count < 0) { return callNeg(this::backwardKillLine); } if (buf.cursor() == buf.length()) { return false; } int cp = buf.cursor(); int len = cp; while (count-- > 0) { if (buf.atChar(len) == '\n') { len++; } else { while (buf.atChar(len) != 0 && buf.atChar(len) != '\n') { len++; } } } int num = len - cp; String killed = buf.substring(cp, cp + num); buf.delete(num); killRing.add(killed); return true; }
public boolean backwardKillLine() { if (count < 0) { return callNeg(this::killLine); } if (buf.cursor() == 0) { return false; } int cp = buf.cursor(); int beg = cp; while (count-- > 0) { if (beg == 0) { break; } if (buf.atChar(beg - 1) == '\n') { beg--; } else { while (beg > 0 && buf.atChar(beg - 1) != 0 && buf.atChar(beg - 1) != '\n') { beg--; } } } int num = cp - beg; String killed = buf.substring(cp - beg, cp); buf.cursor(beg); buf.delete(num); killRing.add(killed); 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; }
String killed = buf.substring(start, end); buf.cursor(start); buf.delete(end - start);
protected boolean viBackwardKillWord() { if (count < 0) { return false; } int lim = findbol(); int x = buf.cursor(); while (count-- > 0) { while (x > lim && isWhitespace(buf.atChar(x - 1))) { x--; } if (x > lim) { if (isViAlphaNum(buf.atChar(x - 1))) { while (x > lim && isViAlphaNum(buf.atChar(x - 1))) { x--; } } else { while (x > lim && !isViAlphaNum(buf.atChar(x - 1)) && !isWhitespace(buf.atChar(x - 1))) { x--; } } } } killRing.addBackwards(buf.substring(x, buf.cursor())); buf.backspace(buf.cursor() - x); return true; }