microsoft / microsoft/monaco-editor
[Bug] Getting wrong range data on paste event
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 46.8k
- Forks
- 4.1k
- Avg merge
- 17h 58m
- Merged PRs (30d)
- 1
Description
Reproducible in vscode.dev or in VS Code Desktop?
- Not reproducible in vscode.dev or VS Code Desktop
Reproducible in the monaco editor playground?
- Not reproducible in the monaco editor playground
Monaco Editor Playground Link
Hello maintainers,
I'm facing an issue with the paste event behavior. Specifically, when I copy a line without selecting any text—by simply placing the cursor at a position (e.g., after a character) and pressing Cmd + C—the subsequent paste results in an incorrect range.
For example, in the attached screenshot, I copied line number 1 by placing the cursor after the letter n in name
const name = 'john';
if
and it copied this text:
const name = 'john';
And when I then pasted it after if, I expected this result (I understand this isn't valid code. I just couldn't think of a better example):
const name = 'john';
if const name = 'john';
However, this is what I actually got:
const name = 'john';
const name = 'john';
if
And the paste event returned the following range (onDidPaste):
{
"startLineNumber": 3,
"startColumn": 4,
"endLineNumber": 4,
"endColumn": 4
}
According to this range, the pasted text should appear at line number 3, column 4—but instead, it was inserted at the beginning of line number 3, which seems incorrect. Ideally, either the range should reflect where the paste actually occurs, or the paste should respect the given range.
Could you please look into this issue?
Sorry for the bad code example!
Thanks!
Monaco Editor Playground Code
https://microsoft.github.io/monaco-editor/playground.html?source=v0.52.2#XQAAAAKYAQAAAAAAAABBqQkHQ5NjdMjwa-jY7SIQ9S7DNlzs5W-mwj0fe1ZCDRFc9ws9XQE0SJE1jc2VKxhaLFIw9vEWSxW3yscwzs04RgmSaumWUF-TBOsVJ4S4FwfCDQb5-2uUHXTVAefbVSd9IzaZ_vv9VR9KugsKiy1S9LdD89hKJA8E5LcLOnXOdvrKhg9NWmt8Y3piRGlyiKNYDCpHhXt7No8d1ctzxF0ybP_jPf8psHkvQ7OAPad3OYSkJE_BhkymnFb9qjPpBPRv-jIeevLz6UphCmU8-CkSowJ6LMMaXfVOOZvYrwnfJHO6unPWHAt1bo3S9qxOlT_K00jqXQV5hf50W4xrD1pecv1pjZLiRJQlmWAJaxyK21bkYWevDdtLI1QI03w6Rt6BLh0gIm99WLYszQjyHkl00F__IyswAA
Reproduction Steps
No response
Actual (Problematic) Behavior
No response
Expected Behavior
No response
Additional Context
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the linked Monaco Editor Playground reproduction for v0.52.2 and inspect the onDidPaste range against where the paste is inserted. Done means the reported range matches the actual insertion location, or the paste respects the reported range, with coverage for copying a line at a cursor position and pasting it after another line.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 38/100