microsoft / monaco-editor

A browser based code editor
https://microsoft.github.io/monaco-editor/
MIT License
40.36k stars 3.59k forks source link

[Feature Request] Monaco's onDidPaste can only obtain text and cannot obtain clipboard objects #4708

Open Zlaojie opened 3 weeks ago

Zlaojie commented 3 weeks ago

Context

Description

paste event result carries native clipboard event attribute. But if i paste a picture, monaco's onDidPaste can only obtain text and cannot obtain clipboard objects.

this.editor.onDidPaste((e) => { console.log(e.clipboardEvent.clipboardData?.items); // e.clipboardEvent.clipboardData?.items always return an empty array //do some things ,such as upload files from clipboardEvent });

Monaco Editor Playground Link

No response

Monaco Editor Playground Code

No response

AndersMad commented 1 week ago

I did via event on the editor container where I had to override the addEventListener so I could abort calling the native one on paste with files.

in the chat editor they do it by navigator.clipboard.read() but that requires elevated rights.

I spose what we need is access to the registerDocumentPasteEditProvider so we can add our own pasters with pasteMimeTypes etc - could also be nice for making e.g. html -> markdown conversions on paste.