Skip to content

Commit 474c1fd

Browse files
author
Theodore Li
committed
feat(ui): handle image paste
1 parent b4064c5 commit 474c1fd

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

apps/sim/app/workspace/[workspaceId]/home/components/user-input/user-input.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,31 @@ export function UserInput({
522522
[isInitialView]
523523
)
524524

525+
const handlePaste = useCallback(
526+
(e: React.ClipboardEvent<HTMLTextAreaElement>) => {
527+
const items = e.clipboardData?.items
528+
if (!items) return
529+
530+
const imageFiles: File[] = []
531+
for (const item of Array.from(items)) {
532+
if (item.kind === 'file' && item.type.startsWith('image/')) {
533+
const file = item.getAsFile()
534+
if (file) imageFiles.push(file)
535+
}
536+
}
537+
538+
if (imageFiles.length === 0) return
539+
540+
e.preventDefault()
541+
const dt = new DataTransfer()
542+
for (const file of imageFiles) {
543+
dt.items.add(file)
544+
}
545+
filesRef.current.processFiles(dt.files)
546+
},
547+
[]
548+
)
549+
525550
const handleScroll = useCallback((e: React.UIEvent<HTMLTextAreaElement>) => {
526551
if (overlayRef.current) {
527552
overlayRef.current.scrollTop = e.currentTarget.scrollTop
@@ -661,6 +686,7 @@ export function UserInput({
661686
onChange={handleInputChange}
662687
onKeyDown={handleKeyDown}
663688
onInput={handleInput}
689+
onPaste={handlePaste}
664690
onCut={mentionTokensWithContext.handleCut}
665691
onSelect={handleSelectAdjust}
666692
onMouseUp={handleSelectAdjust}

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/components/user-input/hooks/use-file-attachments.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,5 +320,6 @@ export function useFileAttachments(props: UseFileAttachmentsProps) {
320320
handleDragOver,
321321
handleDrop,
322322
clearAttachedFiles,
323+
processFiles,
323324
}
324325
}

0 commit comments

Comments
 (0)