monaco-editor icon indicating copy to clipboard operation
monaco-editor copied to clipboard

[Bug] Getting wrong range data on paste event

Open buglessbuild opened this issue 7 months ago • 0 comments

Reproducible in vscode.dev or in VS Code Desktop?

  • [x] Not reproducible in vscode.dev or VS Code Desktop

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!

Image

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

buglessbuild avatar May 04 '25 13:05 buglessbuild