Skip to content

Commit 07ec123

Browse files
BridgeARaduh95
authored andcommitted
repl: fix pasting after moving the cursor to the left
Fixes: #60446 PR-URL: #60470 Reviewed-By: Jordan Harband <[email protected]>
1 parent 2c651c9 commit 07ec123

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

‎lib/internal/readline/interface.js‎

Lines changed: 11 additions & 1 deletion
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+
constbeg=StringPrototypeSlice(this.line,0,this.cursor);
664+
constend=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;

‎test/parallel/test-repl-paste-big-data.js‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ const{startNewREPLServer } = require('../common/repl');
99
constcpuUsage=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

0 commit comments

Comments
(0)