Skip to content

fix(web): pasting text copied from Word inserts the text instead of an image - #40686

Merged
juliusmarminge merged 3 commits into
mainfrom
factory/issue-40681
Nov 22, 2026
Merged

juliusmarminge merged 3 commits into
mainfrom
factory/issue-40681

Conversation

@juliusmarminge

@juliusmarminge juliusmarminge commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Pasting a paragraph copied from Microsoft Word (or another rich text app) into the composer attached a picture of the paragraph and inserted no text, because Word puts a PNG of the selection on the clipboard next to the text. The composer now pastes the text in that case, while copied images still attach.

  • shouldHandleComposerAttachmentPaste no longer lets an image on the clipboard win over text by default. With text present, a raster image attaches only when the clipboard's HTML is just an image, or the text is only the copied files' names (a Finder copy).
  • isImageOnlyClipboardHtml tells a browser's Copy Image (an <img> in text/html, the image URL as text) apart from rich text sources, whose HTML carries the text. ChatComposer passes its result as htmlIsOnlyImage.

Fixes #40681

Reproduction on main

Commit f9b19a7 (origin/main). In a fresh worktree: vp i, then T3CODE_DEV_SEED=0 vp run dev (fresh database). Paired headless Chromium (Playwright, 1280x800) via the startup pairing URL, which opened the new-thread composer. Clicked the composer's contenteditable and dispatched a ClipboardEvent('paste') whose DataTransfer held what Word puts on the macOS clipboard: text/plain 'Hello from Word', text/html '

Hello from Word

' and a File image.png (image/png). Result: defaultPrevented=true, composer text empty ('\n'), and an image.png attachment tile appeared in the composer. No text was inserted. Real Word on macOS was not available. The desktop app runs the same onComposerPaste handler, so this exercises the same code path. The failing unit test is on factory/repro-40681 (b37c3b2): vp test run src/components/chat/composerAttachmentFiles.test.ts in apps/web gives 1 failed / 10 passed, with 'expected true to be false' for the plain-paste assertion.

Evidence

Real web app, Chromium 1280×800, light theme, fresh database on each commit. Open the new-thread composer and paste the same clipboard payload: plain text 'Hello from Word', Word-style HTML, and image.png. Base attaches the image and inserts no text; head inserts the paragraph without an image attachment. scenarios:prove exited 0.

Before After
f9b19a7f85 8e16eb75cd
Before: image attached, paragraph missing After: paragraph inserted without image
Before recording After recording

Scenario source

The reproduction uses a synthetic Word-shaped clipboard payload; real Microsoft Word on macOS was not exercised.

Not shown:

  • Real Microsoft Word on macOS and the native desktop menu were not exercised; evidence covers the supplied synthetic clipboard reproduction in the real web client.

Tests

  • vp test run src/components/chat/composerAttachmentFiles.test.ts (apps/web): 11 passed
  • vp run check:changed: format, lint, knip, typecheck (2 packages), tests and react compiler pass
  • isImageOnlyClipboardHtml logic in headless Chromium (Playwright): Firefox-style Copy Image HTML true, Word-style HTML false, empty false
  • PR CI on 8e16eb7: all 40 checks passed

Not in this change

  • A generic file copied in Finder (e.g. a PDF) still pastes its file name as text instead of attaching, as it did before.
  • Unsupported raster images (e.g. CR2) pasted with real text and no image-only HTML now follow the text path like other non-image files; the old image-first order covered them too.

Who did the work

  • Written by Claude Opus 5.5, in Claude Code
  • Reviewed by GPT-6.1 Sol, in Codex, and by Claude Opus 5.5, each on its own
  • Proof captured by GPT-6.1 Sol and checked by Claude Opus 5.5

Run by the t3code factory in T3 Code.

juliusmarminge and others added 3 commits November 22, 2026 05:19
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 <noreply@anthropic.com>
…n 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 #40681

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… is on the clipboard

Firefox's Copy Image puts the image URL in text/plain and only an <img>
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 <noreply@anthropic.com>
@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:M 30-99 changed lines (additions + deletions). labels Nov 22, 2026
@coderabbitai

coderabbitai Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The composer’s paste handling now considers clipboard HTML and pasted filenames when deciding whether to attach image files or keep pasted content on the text path. Tests cover Word content, image-only HTML with URL text, and image filenames.

Changes: Composer clipboard paste handling

Layer / File(s) Summary
Clipboard classification and paste decision
apps/web/src/components/chat/composerAttachmentFiles.ts, apps/web/src/components/chat/ChatComposer.tsx, apps/web/src/components/chat/composerAttachmentFiles.test.ts
The attachment decision now considers image-only HTML and text that consists entirely of pasted filenames. DNG and SVG files still trigger attachment handling. The composer passes the HTML-only-image flag, and tests cover text and attachment outcomes.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related PRs

  • pingdotgg/t3code#38475: This PR changes the composer’s choice between the text and image attachment paths for clipboard content that contains both.

Suggested labels: bugfix

Suggested reviewers: stienswout, macroscopeapp

Merge Risk: Minimal · up to 8e16e

Pasting text copied from Word should now insert editable text instead of attaching an image. Image-only copies, such as Firefox's Copy Image or Finder image copies, still attach. The change is small and covered by tests, so no concrete merge-blocking risk was found. Confirming it with real Word on macOS would be a sensible follow-up.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: pasting text copied from Word now inserts the text instead of attaching an image. It follows the conventional commit form and matches the linked issue #40681 and the o…
Linked Issues check Passed [#40681] Requirement: plain paste of Word text (text/plain + text/html + image/png) must insert editable text, not an image attachment. At head, shouldHandleComposerAttachmentPaste in `apps/web/src/…
Out of Scope Changes check Passed All changes are in the paste-classification path: composerAttachmentFiles.ts (new isOnlyFileNames, isImageOnlyClipboardHtml, htmlIsOnlyImage input), ChatComposer.tsx (passes `htmlIsOnlyImage…
Description check Passed The description covers the problem (Word paste attaches a picture of the paragraph and inserts no text), the change (text takes precedence over raster images unless the clipboard HTML is image-only or…
Full details: Title check

Explanation

The title names the main change: pasting text copied from Word now inserts the text instead of attaching an image. It follows the conventional commit form and matches the linked issue #40681 and the objectives. Its wording is specific enough for a teammate scanning history.

Full details: Linked Issues check

Explanation

[#40681] Requirement: plain paste of Word text (text/plain + text/html + image/png) must insert editable text, not an image attachment. At head, shouldHandleComposerAttachmentPaste in apps/web/src/components/chat/composerAttachmentFiles.ts returns true for an image only when plainText is empty, when htmlIsOnlyImage is true, or when every non-empty text line equals a pasted file name. Word content has non-empty text that is not a file name, and its HTML contains text, so the function returns false and the text path runs. Requirement: a copied image still attaches. Firefox Copy Image (&lt;img&gt; in text/html, URL as text) sets htmlIsOnlyImage through isImageOnlyClipboardHtml, so it attaches. Finder image copies match the file-name rule, so they attach. The issue's suggested rule (prefer non-empty text/plain when text/html is present) is implemented. bypassAutoAttachment (Paste as Text) keeps its prior behavior. The change does not address #21006 shortcut or menu items, which the issue marks as tracked elsewhere and the PR does not claim. Coding requirement is met by source evidence. Test results (11 passed) are reported by the author and were not re-run. The 'Evidence' section (real-app before/after capture) is pending. This is not a coding requirement. ChatComposer.tsx diff could not be read, so the htmlIsOnlyImage wiring is taken from the supplied summary.

Full details: Out of Scope Changes check

Explanation

All changes are in the paste-classification path: composerAttachmentFiles.ts (new isOnlyFileNames, isImageOnlyClipboardHtml, htmlIsOnlyImage input), ChatComposer.tsx (passes htmlIsOnlyImage to the decision), and composerAttachmentFiles.test.ts (new cases for Word, Copy Image, and Finder paths). Each change supports the Word paste fix or tests it. The DNG and SVG early-return remains and is documented as intended behavior. No unrelated changes were identified in the available evidence. The ChatComposer.tsx diff was not readable, so that file is assessed from the supplied summary only.

Full details: Description check

Explanation

The description covers the problem (Word paste attaches a picture of the paragraph and inserts no text), the change (text takes precedence over raster images unless the clipboard HTML is image-only or the text is only copied file names; isImageOnlyClipboardHtml is passed as htmlIsOnlyImage), a reproduction on main with a synthetic Word-shaped clipboard, before/after evidence, test results, and known gaps. The Scope section links issue #40681 as the bug report, so the requirement to link the bug is met. The Verification section is detailed and names the focused test command and its results. Minor gap: the Scope section does not explicitly state that this is a bug fix rather than a feature, although the linked issue describes a bug. The real-Word-on-macOS check was not run, and the description states this openly.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 28a4200 and 8e16eb7.

Files selected for processing: 3

  • apps/web/src/components/chat/ChatComposer.tsx
  • apps/web/src/components/chat/composerAttachmentFiles.test.ts
  • apps/web/src/components/chat/composerAttachmentFiles.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

@juliusmarminge
juliusmarminge merged commit c1fbdf6 into main Nov 22, 2026
41 checks passed
@juliusmarminge
juliusmarminge deleted the factory/issue-40681 branch November 22, 2026 05:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M 30-99 changed lines (additions + deletions). vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Pasting text copied from Microsoft Word attaches an image instead of the text

1 participant