mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
repl: preserve preview on ESCAPE key press
Fix: #46876 PR-URL: https://github.com/nodejs/node/pull/46878 Fixes: https://github.com/nodejs/node/issues/46876 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
@@ -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;
|
||||
@@ -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]) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user