/** * Search backwards in history from the current position. * * @param searchTerm substring to search for. * @return index where the substring has been found, or -1 else. */ public int searchBackwards(String searchTerm) { return searchBackwards(searchTerm, history.index(), false); }
/** * Search forwards in history from the current position. * * @param searchTerm substring to search for. * @return index where the substring has been found, or -1 else. */ public int searchForwards(String searchTerm) { return searchForwards(searchTerm, history.index()); }
/** * Move up or down the history tree. * @param next <code>true</code> to go to the next, <code>false</code> for the previous. * @return <code>true</code> if successful, <code>false</code> otherwise */ protected boolean moveHistory(final boolean next) { if (!buf.toString().equals(history.current())) { modifiedHistory.put(history.index(), buf.toString()); } if (next && !history.next()) { return false; } else if (!next && !history.previous()) { return false; } setBuffer(modifiedHistory.containsKey(history.index()) ? modifiedHistory.get(history.index()) : history.current()); return true; }
rep = history.get(history.index() - 1); break; case '#': idx = searchBackwards(history, sc, history.index(), false); if (idx < 0) { throw new IllegalArgumentException("!?" + sc + ": event not found"); String previous = history.get(history.index() - 1).trim(); int lastSpace = previous.lastIndexOf(' '); if (lastSpace != -1) { rep = history.get(history.index() - idx); } else if (!neg && idx > history.index() - history.size() && idx <= history.index()) { rep = history.get(idx - 1); } else { String ss = line.substring(i); i = line.length(); idx = searchBackwards(history, ss, history.index(), true); if (idx < 0) { throw new IllegalArgumentException("!" + ss + ": event not found"); String s1 = line.substring(i + 1, i1); String s2 = line.substring(i1 + 1, i2); String s = history.get(history.index() - 1).replace(s1, s2); sb.append(s); i = i2 + 1;
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 viRepeatSearch() { if (searchDir == 0) { return false; } int si = searchDir < 0 ? searchBackwards(searchString, searchIndex, false) : searchForwards(searchString, searchIndex, false); if (si == -1 || si == history.index()) { return false; } searchIndex = si; /* * Show the match. */ buf.clear(); history.moveTo(searchIndex); buf.write(history.get(searchIndex)); if (VICMD.equals(keyMap)) { buf.move(-1); } return true; }
searchBuffer = getFirstWord(); int index = history.index() + 1;