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

[Bug] Since 0.46.0, dropped text append "$0"

Open clemvnt opened this issue 1 year ago • 14 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

https://microsoft.github.io/monaco-editor/playground.html?source=v0.46.0#example-creating-the-editor-hello-world

Monaco Editor Playground Code

Empty.

Reproduction Steps

  1. Open a notepad
  2. Type "text" in the notepad
  3. Drag and drop the text from the notepad to the editor on the playground

Actual (Problematic) Behavior

The editor contains "text$0".

Expected Behavior

The editor should contain "text".

Additional Context

I'm not sure, but I guess the problem must have appeared with this PR: https://github.com/microsoft/vscode/pull/202049 and come from this code: https://github.com/microsoft/vscode/blob/7f07489455fda8bc1841b98b9b7e58b20b7ee3ef/src/vs/editor/contrib/dropOrPasteInto/browser/edit.ts#L34

cc. @mjbvz

clemvnt avatar Feb 16 '24 17:02 clemvnt

I can verify.

hediet avatar Feb 20 '24 14:02 hediet

Also facing this problem.

It is fixed by removing the + '$0' from the line: https://github.com/microsoft/vscode/blob/7f07489455fda8bc1841b98b9b7e58b20b7ee3ef/src/vs/editor/contrib/dropOrPasteInto/browser/edit.ts#L34

snippetParser_1.SnippetParser.escape(edit.insertText) + '$0'

to

snippetParser_1.SnippetParser.escape(edit.insertText)

ScottMcNaught avatar May 24 '24 13:05 ScottMcNaught

I’ve noticed an additional issue related to the drag & drop functionality. When dragging and dropping a function, such as:

function test() {
  // does nothing
}

It incorrectly appends $0 at the end and inserts a backslash before the closing curly brace. I believe these characters should not be escaped. Therefore, instead of using:

snippetParser_1.SnippetParser.escape(edit.insertText) + '$0'

It would be more appropriate to have:

edit.insertText

This change should prevent the unnecessary escaping and the addition of $0 at the end of the dragged text.

scott6 avatar Jun 04 '24 04:06 scott6

It does escape $ character for us as well, the full example is dragging

$some.text

turns int

\$some.text$0

There should be a way to treat dragged content not as a Snippet but raw text, I think. How about extending IDropIntoEditorOptions with such option?

shabalin avatar Jun 25 '24 14:06 shabalin

same problem.

purocean avatar Aug 06 '24 09:08 purocean