fix: do not cancel HTML or text paste when no image is in the event

Empty text/plain used to preventDefault before native clipboard read, which discarded HTML-only paste if no image was recovered.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-16 12:46:10 +08:00
parent 00209d55e6
commit d6a7a3ab08
3 changed files with 13 additions and 5 deletions

View File

@@ -186,10 +186,15 @@
const local = fromEvent ? fromEvent(e) : [];
const text = clipboardText(e, "text/plain");
const uris = clipboardText(e, "text/uri-list");
const steal = local.length > 0
|| (pathLike && (pathLike(text) || pathLike(uris)))
|| !String(text).trim();
if (!steal) return;
const html = clipboardText(e, "text/html");
const imagePath = Boolean(pathLike && (pathLike(text) || pathLike(uris)));
const hasText = Boolean(String(text).trim() || String(html).trim());
// Image files in the event, or a pasted image path, are ours. Empty
// payload is the Linux case where the image is only on the native
// clipboard. Non-empty text/html must reach the page — do not cancel
// first and then fail to recover an image.
if (!local.length && !imagePath && hasText) return;
e.preventDefault();
e.stopImmediatePropagation();
window.__dshDesktopIngesting = true;