diff --git a/lib/readline.js b/lib/readline.js index e0bdb38eb81d96..b7b2651aec35d9 100644 --- a/lib/readline.js +++ b/lib/readline.js @@ -702,7 +702,8 @@ Interface.prototype._historyNext = function() { const search = this[kSubstringSearch] || ''; let index = this.historyIndex - 1; while (index >= 0 && - !this.history[index].startsWith(search)) { + (!this.history[index].startsWith(search) || + this.line === this.history[index])) { index--; } if (index === -1) { @@ -721,10 +722,13 @@ Interface.prototype._historyPrev = function() { const search = this[kSubstringSearch] || ''; let index = this.historyIndex + 1; while (index < this.history.length && - !this.history[index].startsWith(search)) { + (!this.history[index].startsWith(search) || + this.line === this.history[index])) { index++; } if (index === this.history.length) { + // TODO(BridgeAR): Change this to: + // this.line = search; return; } else { this.line = this.history[index]; diff --git a/test/parallel/test-repl-history-navigation.js b/test/parallel/test-repl-history-navigation.js index 19a77afee0dd6c..6b0813e1fae36e 100644 --- a/test/parallel/test-repl-history-navigation.js +++ b/test/parallel/test-repl-history-navigation.js @@ -138,11 +138,7 @@ const tests = [ // UP - skipping const foo = true '\x1B[1G', '\x1B[0J', '> 555 + 909', '\x1B[12G', - // UP - matching the identical history entry again. - '\x1B[1G', '\x1B[0J', - '> 555 + 909', // UP, UP, ENTER. UPs at the end of the history have no effect. - '\x1B[12G', '\r\n', '1464\n', '\x1B[1G', '\x1B[0J',