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 e668efa

Browse filesBrowse files
meixgdanielleadams
authored andcommitted
repl: preserve preview on ESCAPE key press
Fix: #46876 PR-URL: #46878 Fixes: #46876 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent fca3391 commit e668efa
Copy full SHA for e668efa

File tree

Expand file treeCollapse file tree

3 files changed

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

3 files changed

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

‎lib/internal/repl/utils.js‎

Copy file name to clipboardExpand all lines: lib/internal/repl/utils.js
+5-3Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ function setupPreview(repl, contextSymbol, bufferSymbol, active) {
363363
}, () => callback(new ERR_INSPECTOR_NOT_AVAILABLE()));
364364
}
365365

366-
const showPreview = () => {
366+
const showPreview = (showCompletion = true) => {
367367
// Prevent duplicated previews after a refresh.
368368
if (inputPreview !== null || !repl.isCompletionEnabled) {
369369
return;
@@ -379,8 +379,10 @@ function setupPreview(repl, contextSymbol, bufferSymbol, active) {
379379
hasCompletions = false;
380380

381381
// Add the autocompletion preview.
382-
const insertPreview = false;
383-
showCompletionPreview(repl.line, insertPreview);
382+
if (showCompletion) {
383+
const insertPreview = false;
384+
showCompletionPreview(repl.line, insertPreview);
385+
}
384386

385387
// Do not preview if the command is buffered.
386388
if (repl[bufferSymbol]) {
Collapse file

‎lib/repl.js‎

Copy file name to clipboardExpand all lines: lib/repl.js
+2-3Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -995,9 +995,8 @@ function REPLServer(prompt,
995995
clearPreview(key);
996996
if (!reverseSearch(d, key)) {
997997
ttyWrite(d, key);
998-
if (key.name !== 'escape') {
999-
showPreview();
1000-
}
998+
const showCompletionPreview = key.name !== 'escape';
999+
showPreview(showCompletionPreview);
10011000
}
10021001
return;
10031002
}
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-repl-history-navigation.js
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,24 @@ const tests = [
614614
],
615615
clean: false
616616
},
617+
{
618+
// Test that preview should not be removed when pressing ESCAPE key
619+
env: { NODE_REPL_HISTORY: defaultHistoryPath },
620+
skip: !process.features.inspector,
621+
test: [
622+
'1+1',
623+
ESCAPE,
624+
ENTER,
625+
],
626+
expected: [
627+
prompt, ...'1+1',
628+
'\n// 2',
629+
'\n// 2',
630+
'2\n',
631+
prompt,
632+
],
633+
clean: false
634+
},
617635
];
618636
const numtests = tests.length;
619637

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.