Skip to content

Commit 69ad98d

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

File tree

2 files changed

+36
-6
lines changed

2 files changed

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

0 commit comments

Comments
 (0)