Skip to content

Commit e668efa

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

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

lib/internal/repl/utils.js

Lines 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]) {

lib/repl.js

Lines 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
}