10BC0 repl: fix pasting after moving the cursor to the left by BridgeAR · Pull Request #60470 · nodejs/node · GitHub
[go: up one dir, main page]

Skip to content
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
12 changes: 11 additions & 1 deletion lib/internal/readline/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,17 @@ class Interface extends InterfaceConstructor {
[kInsertString](c) {
this[kBeforeEdit](this.line, this.cursor);
if (!this.isCompletionEnabled) {
this.line += c;
if (this.cursor < this.line.length) {
const beg = StringPrototypeSlice(this.line, 0, this.cursor);
const end = StringPrototypeSlice(
this.line,
this.cursor,
this.line.length,
);
this.line = beg + c + end;
} else {
this.line += c;
}
this.cursor += c.length;
this[kWriteToOutput](c);
return;
Expand Down
5 changes: 5 additions & 0 deletions test/parallel/test-repl-paste-big-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ const { startNewREPLServer } = require('../common/repl');
const cpuUsage = process.cpuUsage();

const { replServer } = startNewREPLServer({}, { disableDomainErrorAssert: true });
replServer.input.emit('data', '{}');
replServer.input.emit('keypress', '', { name: 'left' });
replServer.input.emit('data', 'node');
assert.strictEqual(replServer.line, '{node}');

replServer.input.emit('data', 'a'.repeat(2e4) + '\n');
replServer.input.emit('data', '.exit\n');

Expand Down
Loading
0