Skip to content

Commit fb544a4

Browse files
committed
repl: prevent unwanted autocompletion on pressing Enter
1 parent 0f58a3d commit fb544a4

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

lib/internal/repl/utils.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,6 @@ function setupPreview(repl, contextSymbol, bufferSymbol, active) {
207207
if (escaped === null && key.meta) {
208208
escaped = repl.line;
209209
}
210-
} else if ((key.name === 'return' || key.name === 'enter') &&
211-
!key.meta &&
212-
escaped !== repl.line &&
213-
isCursorAtInputEnd()) {
214-
repl._insertString(completionPreview);
215210
}
216211
}
217212
completionPreview = null;
@@ -467,7 +462,7 @@ function setupPreview(repl, contextSymbol, bufferSymbol, active) {
467462
previewLine += completionPreview;
468463
}
469464

470-
getInputPreview(previewLine, inputPreviewCallback);
465+
getInputPreview(repl.line, inputPreviewCallback);
471466
if (wrapped) {
472467
getInputPreview(previewLine, inputPreviewCallback);
473468
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'use strict';
2+
const repl = require('repl');
3+
const { describe, it } = require("node:test");
4+
const ArrayStream = require('../common/arraystream');
5+
const assert = require('assert');
6+
const outputStream = new ArrayStream();
7+
let accum = '';
8+
outputStream.write = (data) => accum += data.replace('\r', '');
9+
10+
function prepareREPL() {
11+
const replServer = repl.start({
12+
prompt: '',
13+
input: new ArrayStream(),
14+
output: outputStream,
15+
allowBlockingCompletions: true,
16+
});
17+
18+
19+
return replServer;
20+
}
21+
22+
23+
describe('REPL Prevent unwanted autocompletion on pressing Enter', () => {
24+
const code = [
25+
'typeof Reflect.construct',
26+
'typeof Reflect.const',
27+
];
28+
29+
it(`should not autocomplete constructor`, async () => {
30+
const { replServer, input } = prepareREPL();
31+
input.run(code);
32+
assert.strictEqual(accum, '\'function\'\n\'undefined\'\n');
33+
});
34+
});

0 commit comments

Comments
 (0)