◐ Shell
clean mode source ↗

repl: fix pasting after moving the cursor to the left · nodejs/node@6ddee4a

Original file line numberDiff line numberDiff line change

@@ -659,7 +659,17 @@ class Interface extends InterfaceConstructor {

659659

[kInsertString](c) {

660660

this[kBeforeEdit](this.line, this.cursor);

661661

if (!this.isCompletionEnabled) {

662-

this.line += c;

662+

if (this.cursor < this.line.length) {

663+

const beg = StringPrototypeSlice(this.line, 0, this.cursor);

664+

const end = StringPrototypeSlice(

665+

this.line,

666+

this.cursor,

667+

this.line.length,

668+

);

669+

this.line = beg + c + end;

670+

} else {

671+

this.line += c;

672+

}

663673

this.cursor += c.length;

664674

this[kWriteToOutput](c);

665675

return;

Original file line numberDiff line numberDiff line change

@@ -9,6 +9,11 @@ const { startNewREPLServer } = require('../common/repl');

99

const cpuUsage = process.cpuUsage();

1010
1111

const { replServer } = startNewREPLServer({}, { disableDomainErrorAssert: true });

12+

replServer.input.emit('data', '{}');

13+

replServer.input.emit('keypress', '', { name: 'left' });

14+

replServer.input.emit('data', 'node');

15+

assert.strictEqual(replServer.line, '{node}');

16+
1217

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

1318

replServer.input.emit('data', '.exit\n');

1419