Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit cecd256

Browse filesBrowse 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 <targos@protonmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent b6f4e01 commit cecd256
Copy full SHA for cecd256

File tree

Expand file treeCollapse file tree

2 files changed

+6
-6
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+6
-6
lines changed
Open diff view settings
Collapse file

‎lib/readline.js‎

Copy file name to clipboardExpand all lines: lib/readline.js
+6-2Lines 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];
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-repl-history-navigation.js
-4Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.