Skip to content

fix(components): prefer plain text over synthetic clipboard images (#262) - #422

Open
hasak21 wants to merge 1 commit into
LodyAI:mainfrom
hasak21:fix/pasted-text-image-attachment
Open

fix(components): prefer plain text over synthetic clipboard images (#262)#422
hasak21 wants to merge 1 commit into
LodyAI:mainfrom
hasak21:fix/pasted-text-image-attachment

Conversation

@hasak21

@hasak21 hasak21 commented Sep 5, 2026

Copy link
Copy Markdown

Related issue

Closes #262

Problem / pressure

When copying text from Microsoft Word (and certain other rich-text editors on macOS/Windows), Word places multiple MIME representations on the clipboard simultaneously: text/plain, text/html, text/rtf, and a rasterized snapshot image (image/png).

In Lody's composer inputs (SessionChatInputArea, WorkspaceChatLanding, useChatLandingImageDraft, TaskBodyEditorFallback, and TaskThread), paste handlers inspected event.clipboardData.items for file entries. Because the rasterized PNG file was present in items, Lody immediately intercepted the paste via event.preventDefault() and treated the clipboard content as an image file upload. This prevented the copied plain text from being inserted as editable text in the textarea.

Summary

  • In SessionChatInputArea, WorkspaceChatLanding, useChatLandingImageDraft, TaskBodyEditorFallback, and TaskThread, check whether non-empty text/plain is present on the clipboard.
  • When text.length > 0, avoid intercepting the paste as a file attachment, allowing normal text insertion into the textarea (or draft capture for texts > 1024 characters).
  • Pure image pastes (e.g. screenshots or copied images without text content) continue to be intercepted and uploaded as image attachments as before.
  • Added comprehensive unit tests in packages/components/tests/session-chat-input-paste.test.tsx.

Before / after

Before After
Pasting text copied from Microsoft Word into the composer intercepts the paste and uploads it as an image attachment because Word attaches a synthetic PNG preview to the clipboard. Text copied from Microsoft Word pastes cleanly as editable plain text into the composer, while pure image pastes (screenshots) continue to attach as images.

Test plan

  • Ran pnpm --filter @lody/components test tests/session-chat-input-paste.test.tsx (all 4 tests passed).
  • Ran pnpm --filter @lody/components test paste (all 23 tests across paste suites passed).
  • Ran pnpm check:quick (oxlint, lint:i18n, check:code-collab-imports, check:platform-boundaries, check:public-boundary all passed with 0 errors).
  • Ran Prettier check on all modified files (packages/components/src/... and packages/components/tests/...).

Context handoff

Instructions for reviewing agents

  • Review focus: Verify paste event handling in session-chat-input-area.tsx, chat-landing.tsx, use-chat-landing-image-draft.ts, task-body-editor-fallback.tsx, and task-thread.tsx.
  • Decisions to challenge: Ensure checking text.length > 0 before checking event.clipboardData.items for file entries correctly prioritizes user-intended text without regressing pure image/screenshot pastes.
  • Plausible failures / evidence gaps: Clipboard formats vary across operating systems; tests mock multi-MIME clipboards (text/plain + image/png) to verify precedence.

Authoring context

  • User goal / directives: Fix issue [Bug] Pasting plain text copied from Microsoft Word is treated as an image attachment #262 so that copying plain text from Microsoft Word into chat and task composers pastes as text instead of an image attachment.
  • Constraints / non-goals: Do not break existing large text draft capture (> 1024 characters) or pure image/screenshot attachments.
  • Risk-bearing decisions: When both text and image MIME types exist, text is prioritized on text inputs.
  • Destructive or irreversible behavior: None; no schema or persistent data changes.
  • Deliberately not done or tested: Did not change rich-text HTML rendering in composer; plain text insertion remains standard.
  • Unknowns / confidence: High confidence; unit tests cover Word-like multi-format clipboard payloads, pure image pastes, and large text drafts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Pasting plain text copied from Microsoft Word is treated as an image attachment

1 participant