Skip to content

Commit e668efa

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

3 files changed

Lines changed: 25 additions & 6 deletions

File tree

‎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(newERR_INSPECTOR_NOT_AVAILABLE()));
364364
}
365365

366-
constshowPreview=()=>{
366+
constshowPreview=(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-
constinsertPreview=false;
383-
showCompletionPreview(repl.line,insertPreview);
382+
if(showCompletion){
383+
constinsertPreview=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+
constshowCompletionPreview=key.name!=='escape';
999+
showPreview(showCompletionPreview);
10011000
}
10021001
return;
10031002
}

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

Lines 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
constnumtests=tests.length;
619637

0 commit comments

Comments
 (0)