mirror of
https://gitlab.com/ArkHost/HelixNotes.git
synced 2026-09-19 17:37:29 +02:00
Merge branch 'fix/webkitgtk-clipboard-image-paste' into 'main'
fix: paste images copied from a browser on WebKitGTK Closes #245 See merge request ArkHost/HelixNotes!5
This commit is contained in:
@@ -5629,18 +5629,21 @@
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// WebKitGTK fallback (bug #218519): older WebKitGTK versions return
|
// WebKitGTK fallback (bug #218519): WebKitGTK never exposes a clipboard image
|
||||||
// empty DataTransferItemList for image pastes. Detect this and read
|
// through DataTransfer, so the loop above cannot fire on Linux and this is the
|
||||||
// the image directly from the system clipboard via Rust/arboard.
|
// only path that can work there. The guard used to also require an empty
|
||||||
if (items.length === 0) {
|
// DataTransferItemList and no text/html, which no real image copy satisfies:
|
||||||
|
// Chromium's "Copy image" writes an <img> HTML fragment alongside the bitmap
|
||||||
|
// (but no text/plain), so the image was dropped and its remote URL pasted
|
||||||
|
// instead. Key off text/plain, and accept HTML that is just an <img>.
|
||||||
const hasText = event.clipboardData!.getData('text/plain');
|
const hasText = event.clipboardData!.getData('text/plain');
|
||||||
const hasHtml = event.clipboardData!.getData('text/html');
|
const html = event.clipboardData!.getData('text/html');
|
||||||
if (!hasText && !hasHtml) {
|
const htmlIsBareImage = /^\s*(?:<meta[^>]*>\s*)?<img\b[^>]*>\s*$/i.test(html);
|
||||||
|
if (!hasText && (!html || htmlIsBareImage)) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
insertClipboardImage();
|
insertClipboardImage();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user