Skip to content

Commit cecd256

Browse files
BridgeARMylesBorins
authored andcommitted
readline,repl: skip history entries identical to the current line
Skip history entries that are identical to the currently visible line to improve the user experience. PR-URL: #31112 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent b6f4e01 commit cecd256

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

lib/readline.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,8 @@ Interface.prototype._historyNext = function() {
702702
const search = this[kSubstringSearch] || '';
703703
let index = this.historyIndex - 1;
704704
while (index >= 0 &&
705-
!this.history[index].startsWith(search)) {
705+
(!this.history[index].startsWith(search) ||
706+
this.line === this.history[index])) {
706707
index--;
707708
}
708709
if (index === -1) {
@@ -721,10 +722,13 @@ Interface.prototype._historyPrev = function() {
721722
const search = this[kSubstringSearch] || '';
722723
let index = this.historyIndex + 1;
723724
while (index < this.history.length &&
724-
!this.history[index].startsWith(search)) {
725+
(!this.history[index].startsWith(search) ||
726+
this.line === this.history[index])) {
725727
index++;
726728
}
727729
if (index === this.history.length) {
730+
// TODO(BridgeAR): Change this to:
731+
// this.line = search;
728732
return;
729733
} else {
730734
this.line = this.history[index];

test/parallel/test-repl-history-navigation.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,7 @@ const tests = [
138138
// UP - skipping const foo = true
139139
'\x1B[1G', '\x1B[0J',
140140
'> 555 + 909', '\x1B[12G',
141-
// UP - matching the identical history entry again.
142-
'\x1B[1G', '\x1B[0J',
143-
'> 555 + 909',
144141
// UP, UP, ENTER. UPs at the end of the history have no effect.
145-
'\x1B[12G',
146142
'\r\n',
147143
'1464\n',
148144
'\x1B[1G', '\x1B[0J',

0 commit comments

Comments
 (0)