Add paste support for images and files in chat#66
Merged
mcintyre94 merged 8 commits intomainfrom Mar 13, 2026
Merged
Conversation
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
- Paste from Clipboard option in the attachment menu reads UIPasteboard and routes images/files through the existing upload flow - .onPaste modifier on the chat TextField intercepts inline paste (long-press → Paste, or Cmd+V) for images and file URLs, same upload flow - Shared pasteImageFormats constant (UTType, ext) used by both paths - addAttachedFile(remotePath:) helper on ChatViewModel removes repeated lastPathComponent + attachedFiles.append pattern Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Use doc.on.clipboard instead of clipboard for the Paste menu item, which is the standard iOS paste icon (available since iOS 13) - Add ChatViewModelTests for addAttachedFile: verifies lastPathComponent extraction and that multiple calls each append correctly Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1a6bd61 to
d41a02c
Compare
Replaces SwiftUI TextField with a UIViewRepresentable wrapping a custom UITextView subclass (PasteTextView) that overrides canPerformAction and paste to intercept non-text clipboard content. Long-press → Paste on iOS now triggers the same image/file upload flow as the attachment menu button, matching how Messages and Slack behave. Also removes the Mac-only PasteItemsModifier and handlePastedItems since the existing handlePasteFromClipboard covers both paths via UIPasteboard. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replaces SwiftUI TextField with a UIViewRepresentable wrapping a custom UITextView subclass (PasteTextView) that overrides paste(_:) to intercept non-text clipboard content. Long-press → Paste on iOS now triggers the same upload flow as the attachment menu button. Handles images (via hasImages/image formats), file URLs (via itemProviders with public.file-url), and arbitrary files from the Files app (via raw data under content UTIs like com.adobe.pdf). File extension is derived from the UTType when the suggested name doesn't include one. Also removes the Mac-only PasteItemsModifier and handlePastedItems — the handlePasteFromClipboard path via UIPasteboard now covers all cases. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Long-press paste on the text field is more discoverable and covers the same functionality. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds UIApplication.sendAction to explicitly resign first responder when sending, since FocusState alone is unreliable with UIViewRepresentable. Replaces contextMenu on send button with Menu(primaryAction:) so the keyboard stays visible on long-press (contextMenu's preview lift dismisses the keyboard; Menu does not). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
+button) — handles images (PNG/JPEG/GIF/WebP/HEIC) and file URLs.onPaste(of: [.image, .fileURL])to the chatTextFieldso pasting directly into the input box (long-press → Paste, or Cmd+V on iPad/Mac) routes images and files through the same upload flowuploadPhotoData/uploadFileFromDevicemethods — no new upload logicImplementation notes
handlePasteFromClipboardreadsUIPasteboard.general(triggered by the menu button)handlePastedItemsconsumes[NSItemProvider]from SwiftUI's.onPastemodifier (triggered by inline paste in the text field)pasteImageFormats: [(UTType, String)]constant used by both handlersaddAttachedFile(remotePath:)helper toChatViewModelto avoid repeating thelastPathComponent+attachedFiles.appendpatternTest plan
+→ "Paste from Clipboard" → same result+→ "Paste from Clipboard" → file uploads+→ "Paste from Clipboard" with nothing useful in clipboard → error alert shown🤖 Generated with Claude Code