Skip to content

Commit d6a1232

Browse files
meixgtargos
authored andcommitted
repl: preserve preview on ESCAPE key press
Fix: #46876 PR-URL: #46878 Fixes: #46876 Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent 8850dac commit d6a1232

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

lib/internal/repl/utils.js

+5-3
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]) {

lib/repl.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -993,9 +993,8 @@ function REPLServer(prompt,
993993
clearPreview(key);
994994
if (!reverseSearch(d, key)) {
995995
ttyWrite(d, key);
996-
if (key.name !== 'escape') {
997-
showPreview();
998-
}
996+
const showCompletionPreview = key.name !== 'escape';
997+
showPreview(showCompletionPreview);
999998
}
1000999
return;
10011000
}

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

+18
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)