From b37c3b28f47139877e4bafba2ec799551af1189d Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sun, 22 Nov 2026 05:19:59 +0000 Subject: [PATCH 1/3] test(web): a plain paste of a Word clipboard keeps the text Fails on main: shouldHandleComposerAttachmentPaste claims any clipboard holding an image, so a plain paste from Word attaches a picture of the text instead of inserting it (#40681). Co-Authored-By: Claude Opus 5.5 --- .../web/src/components/chat/composerAttachmentFiles.test.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/apps/web/src/components/chat/composerAttachmentFiles.test.ts b/apps/web/src/components/chat/composerAttachmentFiles.test.ts index 2a487b1f237de..04a1e66b5dc2e 100644 --- a/apps/web/src/components/chat/composerAttachmentFiles.test.ts +++ b/apps/web/src/components/chat/composerAttachmentFiles.test.ts @@ -121,10 +121,14 @@ describe("composer attachment files", () => { ).toBe(true); }); - it("leaves an image-and-text clipboard to the text path under Paste as Text", () => { + it("leaves a Word image-and-text clipboard to the text path, with or without Paste as Text", () => { const image = new File(["png"], "image.png", { type: "image/png" }); const input = { files: [image], plainText: "Hello from Word", bypassAutoAttachment: true }; expect(shouldHandleComposerAttachmentPaste(input)).toBe(false); + // A plain paste of the same Word clipboard keeps the text too. + expect(shouldHandleComposerAttachmentPaste({ ...input, bypassAutoAttachment: false })).toBe( + false, + ); }); it("preserves text when the clipboard also includes generic image files", () => { From 06ff28b1d5c9c152f39542e3b87470127daded41 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sun, 22 Nov 2026 05:25:47 +0000 Subject: [PATCH 2/3] fix(web): pasting text copied from Word inserts the text instead of an image Word and other rich text sources put a picture of the selection on the clipboard next to the text. The composer claimed any clipboard holding a supported image before looking at the text, so a plain paste attached the picture and dropped the text. Text now wins over a raster image, unless the text is only the pasted files' names, as when an image file is copied in Finder. Fixes pingdotgg/t3code#40681 Co-Authored-By: Claude Opus 5.5 --- .../chat/composerAttachmentFiles.test.ts | 4 +++ .../chat/composerAttachmentFiles.ts | 33 +++++++++++-------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/apps/web/src/components/chat/composerAttachmentFiles.test.ts b/apps/web/src/components/chat/composerAttachmentFiles.test.ts index 04a1e66b5dc2e..f05ccd53a39a3 100644 --- a/apps/web/src/components/chat/composerAttachmentFiles.test.ts +++ b/apps/web/src/components/chat/composerAttachmentFiles.test.ts @@ -129,6 +129,10 @@ describe("composer attachment files", () => { expect(shouldHandleComposerAttachmentPaste({ ...input, bypassAutoAttachment: false })).toBe( false, ); + // Finder puts a copied file's name on the clipboard as text; the image still attaches. + expect(shouldHandleComposerAttachmentPaste({ files: [image], plainText: "image.png" })).toBe( + true, + ); }); it("preserves text when the clipboard also includes generic image files", () => { diff --git a/apps/web/src/components/chat/composerAttachmentFiles.ts b/apps/web/src/components/chat/composerAttachmentFiles.ts index 041db7193d2e2..9e0b64bff33ec 100644 --- a/apps/web/src/components/chat/composerAttachmentFiles.ts +++ b/apps/web/src/components/chat/composerAttachmentFiles.ts @@ -239,6 +239,14 @@ export function attachmentsToReleaseOnUploadCapabilityLoss( ); } +function isOnlyFileNames(text: string, files: ReadonlyArray): boolean { + const names = new Set(files.map((file) => file.name)); + return text + .split(/\r?\n/) + .filter((line) => line.length > 0) + .every((line) => names.has(line)); +} + export function shouldHandleComposerAttachmentPaste(input: { readonly files: ReadonlyArray; readonly plainText: string; @@ -247,22 +255,19 @@ export function shouldHandleComposerAttachmentPaste(input: { // Paste as Text keeps the text even when the source also put an image of it on the clipboard. if (input.bypassAutoAttachment && input.plainText.length > 0) return false; if ( - input.files.some((file) => { - if (isDngFile(file)) return true; - const classification = classifyComposerAttachmentFile(file); - return ( - classification === "image" || - classification === "unsupported-image" || - isSvgAttachment({ name: file.name, mimeType: file.type }) - ); - }) + input.files.some( + (file) => isDngFile(file) || isSvgAttachment({ name: file.name, mimeType: file.type }), + ) ) { return true; } - - if (input.plainText.length > 0) { - return false; + const hasImage = input.files.some((file) => { + const classification = classifyComposerAttachmentFile(file); + return classification === "image" || classification === "unsupported-image"; + }); + if (input.plainText.length === 0) { + return hasImage || input.files.some((file) => classifyComposerAttachmentFile(file) === "file"); } - - return input.files.some((file) => classifyComposerAttachmentFile(file) === "file"); + // Rich text sources (Word, Pages) add a picture of the text; a Finder copy's text is only file names. + return hasImage && isOnlyFileNames(input.plainText, input.files); } From 8e16eb75cdbc9484f98460b283e132ff1c189472 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sun, 22 Nov 2026 05:33:32 +0000 Subject: [PATCH 3/3] fix(web): an image copied with Copy Image still attaches when its URL is on the clipboard Firefox's Copy Image puts the image URL in text/plain and only an in text/html. The Word fix let any text win over a raster image unless it was the files' names, so that paste inserted the URL. The image now also wins when the clipboard HTML is only an image with no text, which is what separates it from rich text sources like Word. Co-Authored-By: Claude Opus 5.5 --- apps/web/src/components/chat/ChatComposer.tsx | 10 +++++++++- .../chat/composerAttachmentFiles.test.ts | 10 +++++++++- .../components/chat/composerAttachmentFiles.ts | 15 +++++++++++++-- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/apps/web/src/components/chat/ChatComposer.tsx b/apps/web/src/components/chat/ChatComposer.tsx index 2c3bc34529ffd..6d4487adef153 100644 --- a/apps/web/src/components/chat/ChatComposer.tsx +++ b/apps/web/src/components/chat/ChatComposer.tsx @@ -133,6 +133,7 @@ import { fileAttachmentCapabilityBlockReason, fileAttachmentStagingLimit, isPreviewableComposerVideo, + isImageOnlyClipboardHtml, shouldHandleComposerAttachmentPaste, } from "./composerAttachmentFiles"; import { @@ -2918,7 +2919,14 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps) (!pastedContext && activeThreadId && files.length > 0 && - shouldHandleComposerAttachmentPaste({ files, plainText, bypassAutoAttachment })) + shouldHandleComposerAttachmentPaste({ + files, + plainText, + bypassAutoAttachment, + htmlIsOnlyImage: + plainText.length > 0 && + isImageOnlyClipboardHtml(event.clipboardData.getData("text/html")), + })) ) { event.preventDefault(); event.stopPropagation(); diff --git a/apps/web/src/components/chat/composerAttachmentFiles.test.ts b/apps/web/src/components/chat/composerAttachmentFiles.test.ts index f05ccd53a39a3..f842566d7cd60 100644 --- a/apps/web/src/components/chat/composerAttachmentFiles.test.ts +++ b/apps/web/src/components/chat/composerAttachmentFiles.test.ts @@ -129,7 +129,15 @@ describe("composer attachment files", () => { expect(shouldHandleComposerAttachmentPaste({ ...input, bypassAutoAttachment: false })).toBe( false, ); - // Finder puts a copied file's name on the clipboard as text; the image still attaches. + // Firefox's Copy Image adds the image URL as text and only an as HTML; the image attaches. + expect( + shouldHandleComposerAttachmentPaste({ + files: [image], + plainText: "https://example.com/image.png", + htmlIsOnlyImage: true, + }), + ).toBe(true); + // Finder adds a copied file's name as text. expect(shouldHandleComposerAttachmentPaste({ files: [image], plainText: "image.png" })).toBe( true, ); diff --git a/apps/web/src/components/chat/composerAttachmentFiles.ts b/apps/web/src/components/chat/composerAttachmentFiles.ts index 9e0b64bff33ec..191c5841185ff 100644 --- a/apps/web/src/components/chat/composerAttachmentFiles.ts +++ b/apps/web/src/components/chat/composerAttachmentFiles.ts @@ -247,10 +247,18 @@ function isOnlyFileNames(text: string, files: ReadonlyArray): boolean { .every((line) => names.has(line)); } +/** A browser's Copy Image puts only an in text/html; rich text sources put the text there. */ +export function isImageOnlyClipboardHtml(html: string): boolean { + if (html.length === 0) return false; + const body = new DOMParser().parseFromString(html, "text/html").body; + return body.querySelector("img") !== null && (body.textContent ?? "").trim().length === 0; +} + export function shouldHandleComposerAttachmentPaste(input: { readonly files: ReadonlyArray; readonly plainText: string; readonly bypassAutoAttachment?: boolean; + readonly htmlIsOnlyImage?: boolean; }): boolean { // Paste as Text keeps the text even when the source also put an image of it on the clipboard. if (input.bypassAutoAttachment && input.plainText.length > 0) return false; @@ -268,6 +276,9 @@ export function shouldHandleComposerAttachmentPaste(input: { if (input.plainText.length === 0) { return hasImage || input.files.some((file) => classifyComposerAttachmentFile(file) === "file"); } - // Rich text sources (Word, Pages) add a picture of the text; a Finder copy's text is only file names. - return hasImage && isOnlyFileNames(input.plainText, input.files); + // Rich text sources (Word, Pages) add a picture of the text. Copy Image adds the image URL as + // text beside an , and a Finder copy adds the file names. + return ( + hasImage && (input.htmlIsOnlyImage === true || isOnlyFileNames(input.plainText, input.files)) + ); }