Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat(ui): handle image paste
  • Loading branch information
Theodore Li committed Mar 28, 2026
commit 474c1fd3ed81fee152db17e19fea3b44a8eaf83c
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,31 @@ export function UserInput({
[isInitialView]
)

const handlePaste = useCallback(
(e: React.ClipboardEvent<HTMLTextAreaElement>) => {
const items = e.clipboardData?.items
if (!items) return

const imageFiles: File[] = []
for (const item of Array.from(items)) {
if (item.kind === 'file' && item.type.startsWith('image/')) {
const file = item.getAsFile()
if (file) imageFiles.push(file)
}
}

if (imageFiles.length === 0) return

e.preventDefault()
const dt = new DataTransfer()
for (const file of imageFiles) {
dt.items.add(file)
}
filesRef.current.processFiles(dt.files)
},
[]
)

Comment thread
TheodoreSpeaks marked this conversation as resolved.
const handleScroll = useCallback((e: React.UIEvent<HTMLTextAreaElement>) => {
if (overlayRef.current) {
overlayRef.current.scrollTop = e.currentTarget.scrollTop
Expand Down Expand Up @@ -661,6 +686,7 @@ export function UserInput({
onChange={handleInputChange}
onKeyDown={handleKeyDown}
onInput={handleInput}
onPaste={handlePaste}
onCut={mentionTokensWithContext.handleCut}
onSelect={handleSelectAdjust}
onMouseUp={handleSelectAdjust}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,5 +320,6 @@ export function useFileAttachments(props: UseFileAttachmentsProps) {
handleDragOver,
handleDrop,
clearAttachedFiles,
processFiles,
}
}
Loading