Skip to content

Add paste support for images and files in chat#66

Merged
mcintyre94 merged 8 commits intomainfrom
add-iphone-attachment-feature-d68954aa
Mar 13, 2026
Merged

Add paste support for images and files in chat#66
mcintyre94 merged 8 commits intomainfrom
add-iphone-attachment-feature-d68954aa

Conversation

@mcintyre94
Copy link
Copy Markdown
Owner

Summary

  • Adds a "Paste from Clipboard" option to the attachment menu (+ button) — handles images (PNG/JPEG/GIF/WebP/HEIC) and file URLs
  • Adds .onPaste(of: [.image, .fileURL]) to the chat TextField so pasting directly into the input box (long-press → Paste, or Cmd+V on iPad/Mac) routes images and files through the same upload flow
  • Both paths call the existing uploadPhotoData / uploadFileFromDevice methods — no new upload logic

Implementation notes

  • handlePasteFromClipboard reads UIPasteboard.general (triggered by the menu button)
  • handlePastedItems consumes [NSItemProvider] from SwiftUI's .onPaste modifier (triggered by inline paste in the text field)
  • Shared pasteImageFormats: [(UTType, String)] constant used by both handlers
  • Added addAttachedFile(remotePath:) helper to ChatViewModel to avoid repeating the lastPathComponent + attachedFiles.append pattern

Test plan

  • Copy an image in Photos, open Wisp, long-press in chat input → Paste → image uploads and appears as attachment chip
  • Copy an image in Photos, tap + → "Paste from Clipboard" → same result
  • Copy a file URL, tap + → "Paste from Clipboard" → file uploads
  • Tap + → "Paste from Clipboard" with nothing useful in clipboard → error alert shown
  • Text paste in the input field continues to work normally

🤖 Generated with Claude Code

@claude
Copy link
Copy Markdown

claude bot commented Mar 12, 2026

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

mcintyre94 and others added 2 commits March 12, 2026 23:35
- 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>
@mcintyre94 mcintyre94 force-pushed the add-iphone-attachment-feature-d68954aa branch from 1a6bd61 to d41a02c Compare March 12, 2026 23:39
mcintyre94 and others added 6 commits March 13, 2026 07:40
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>
@mcintyre94 mcintyre94 merged commit df63e0f into main Mar 13, 2026
2 checks passed
@mcintyre94 mcintyre94 deleted the add-iphone-attachment-feature-d68954aa branch March 13, 2026 22:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant