Attach clipboard images pasted into the chat box#1740
Open
iyernaveenr wants to merge 1 commit into
Open
Conversation
Pasting into the chat box previously handled only plain text; clipboard file items such as screenshots were silently dropped. Route pasted file items into the existing attachment flow: persist the pasted bytes to a temporary file through the desktop bridge (pasted files carry no filesystem path), or upload them like dropped files on web, and attach the result exactly like drag-and-drop. Text on the clipboard is still inserted as before. Signed-off-by: Naveen R. Iyer <iyernaveenr@gmail.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.
Problem
Pasting an image from the clipboard (e.g. a screenshot) into the chat input does nothing. Only plain text pastes work; attaching an image requires the file picker or drag-and-drop, which is a detour for the most common flow of sharing a screenshot with the agent.
Root cause
The rich input's paste handler calls
preventDefault()and then reads onlyclipboardData.getData('text/plain'); clipboard file items are never inspected, so pasted images are silently discarded. The attachment pipeline is path-based (FileAttachment.filePath), and unlike drag-and-dropped files, pastedFileobjects carry no filesystem path, so they could not simply be forwarded to the existing drop handler.Fix
Route pasted file items into the existing attachment flow:
RichChatInputgains anonPasteFilescallback; its paste handler now extracts clipboard file items (clipboardData.items->getAsFile()) and forwards them, while still inserting any plain text on the clipboard (some sources provide both).save-pasted-fileIPC handler persists the pasted bytes to a temporary directory and returns the path, since pasted files have no path of their own. A newprocessPastedFileshelper (mirroringprocessDroppedFiles) uses it and merges the result into the existing attachments, deduplicated by path.All pasted file kinds are forwarded, so copying a file from a file manager and pasting it also attaches it.
Testing
Verified on Linux desktop: copying a screenshot to the clipboard and pressing Ctrl+V in the chat box attaches it as a file chip (with toast), and the agent can read the attached image in the run; plain-text paste and drag-and-drop behave as before.
tscpasses; lint passes for the changed files.