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: https://github.com/nodejs/node/pull/31112 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
625a0ec5e1
commit
d449c505f3
@ -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];
|
||||
|
@ -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',
|
||||
|
Loading…
x
Reference in New Issue
Block a user