Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixup: address comments
  • Loading branch information
BridgeAR committed Dec 20, 2019
commit 29fcab97828bd9b97701006c41ea8b5014fadcb7
21 changes: 9 additions & 12 deletions lib/internal/repl/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,11 +420,7 @@ function setupReverseSearch(repl) {
let lastCursor = -1;
let promptPos;

function next() {
return historyIndex >= 0 && historyIndex < repl.history.length;
}

function isDirectionKey(keyName) {
function checkAndSetDirectionKey(keyName) {
if (!labels[keyName]) {
return false;
}
Expand Down Expand Up @@ -460,7 +456,7 @@ function setupReverseSearch(repl) {
historyIndex = repl.history.length - 1;
}
// Check the history entries until a match is found.
while (next()) {
while (historyIndex >= 0 && historyIndex < repl.history.length) {
let entry = repl.history[historyIndex];
// Visualize all potential matches only once.
if (alreadyMatched.has(entry)) {
Expand Down Expand Up @@ -504,9 +500,9 @@ function setupReverseSearch(repl) {
}

function print(outputLine, inputLine, cursor = repl.cursor) {
// TODO(BridgeAR): Resizing the terminal window breaks this. To fix that,
// readline must be aware of this information. It's probably best to add a
// couple of properties to readline that allow to do the following:
// TODO(BridgeAR): Resizing the terminal window hides the overlay. To fix
// that, readline must be aware of this information. It's probably best to
// add a couple of properties to readline that allow to do the following:
// 1. Add arbitrary data to the end of the current line while not counting
// towards the line. This would be useful for the completion previews.
// 2. Add arbitrary extra lines that do not count towards the regular line.
Expand All @@ -515,7 +511,8 @@ function setupReverseSearch(repl) {
// 3. Add arbitrary input that is "on top" of the current line. That is
// useful for the reverse search.
// 4. To trigger the line refresh, functions should be used to pass through
// the information.
// the information. Alternatively, getters and setters could be used.
// That might even be more elegant.
// The data would then be accounted for when calling `_refreshLine()`.
// This function would then look similar to:
// repl.overlay(outputLine);
Expand Down Expand Up @@ -599,13 +596,13 @@ function setupReverseSearch(repl) {

function reverseSearch(string, key) {
if (!isInReverseSearch) {
if (key.ctrl && isDirectionKey(key.name)) {
if (key.ctrl && checkAndSetDirectionKey(key.name)) {
historyIndex = repl.historyIndex;
promptPos = repl._getDisplayPos(`${repl._prompt}`);
print(repl.line, `${labels[dir]}_`);
isInReverseSearch = true;
}
} else if (key.ctrl && isDirectionKey(key.name)) {
} else if (key.ctrl && checkAndSetDirectionKey(key.name)) {
search();
} else if (key.name === 'backspace' ||
(key.ctrl && (key.name === 'h' || key.name === 'w'))) {
Expand Down