webContextMenus: support pasting images

This commit is contained in:
V 2023-09-27 04:13:40 +02:00
parent 837d1fc083
commit 4facc3cad7
No known key found for this signature in database
GPG Key ID: A1DC0CFB5615D905

@ -218,10 +218,19 @@ export default definePlugin({
}, },
async paste() { async paste() {
const text = await navigator.clipboard.readText(); const clip = (await navigator.clipboard.read())[0];
if (!clip) return;
const data = new DataTransfer(); const data = new DataTransfer();
data.setData("text/plain", text); for (const type of clip.types) {
if (type === "image/png") {
const file = new File([await clip.getType(type)], "unknown.png", { type });
data.items.add(file);
} else if (type === "text/plain") {
const blob = await clip.getType(type);
data.setData(type, await blob.text());
}
}
document.dispatchEvent( document.dispatchEvent(
new ClipboardEvent("paste", { new ClipboardEvent("paste", {