Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

repl: preserve preview on ESCAPE key press #46878

Merged
merged 3 commits into from
Mar 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/internal/repl/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ function setupPreview(repl, contextSymbol, bufferSymbol, active) {
}, () => callback(new ERR_INSPECTOR_NOT_AVAILABLE()));
}

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

// Add the autocompletion preview.
const insertPreview = false;
showCompletionPreview(repl.line, insertPreview);
if (showCompletion) {
const insertPreview = false;
showCompletionPreview(repl.line, insertPreview);
}

// Do not preview if the command is buffered.
if (repl[bufferSymbol]) {
Expand Down
5 changes: 2 additions & 3 deletions lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -993,9 +993,8 @@ function REPLServer(prompt,
clearPreview(key);
if (!reverseSearch(d, key)) {
ttyWrite(d, key);
if (key.name !== 'escape') {
showPreview();
}
const showCompletionPreview = key.name !== 'escape';
showPreview(showCompletionPreview);
}
return;
}
Expand Down
18 changes: 18 additions & 0 deletions test/parallel/test-repl-history-navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,24 @@ const tests = [
],
clean: false
},
{
// Test that preview should not be removed when pressing ESCAPE key
env: { NODE_REPL_HISTORY: defaultHistoryPath },
skip: !process.features.inspector,
test: [
'1+1',
ESCAPE,
ENTER,
],
expected: [
prompt, ...'1+1',
'\n// 2',
'\n// 2',
'2\n',
prompt,
],
clean: false
},
];
const numtests = tests.length;

Expand Down