Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6ddee4a

Browse filesBrowse files
BridgeARaduh95
authored andcommitted
repl: fix pasting after moving the cursor to the left
Fixes: #60446 PR-URL: #60470 Reviewed-By: Jordan Harband <ljharb@gmail.com>
1 parent 22fd621 commit 6ddee4a
Copy full SHA for 6ddee4a

File tree

Expand file treeCollapse file tree

2 files changed

+16
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+16
-1
lines changed
Open diff view settings
Collapse file

‎lib/internal/readline/interface.js‎

Copy file name to clipboardExpand all lines: lib/internal/readline/interface.js
+11-1Lines 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+
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;
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-repl-paste-big-data.js
+5Lines changed: 5 additions & 0 deletions
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

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.