From cecd25693f9cd9a124ca7dd03e3e8631591efd36 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Fri, 27 Dec 2019 19:33:49 +0100 Subject: [PATCH] readline,repl: skip history entries identical to the current line MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Skip history entries that are identical to the currently visible line to improve the user experience. PR-URL: https://github.com/nodejs/node/pull/31112 Reviewed-By: Michaƫl Zasso Reviewed-By: James M Snell --- lib/readline.js | 8 ++++++-- test/parallel/test-repl-history-navigation.js | 4 ---- 2 files changed, 6 insertions(+), 6 deletions(-) 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',