summaryrefslogtreecommitdiffhomepage
path: root/packages/app/src/components/prompt-input/attachments.ts
diff options
context:
space:
mode:
authorShoubhit Dash <[email protected]>2026-03-23 12:14:17 +0530
committerGitHub <[email protected]>2026-03-23 06:44:17 +0000
commit9239d877b9602a5a80e9e69e744abfe011f5f991 (patch)
tree7c097bec13af5e693a7f52a74aebcb7136de782a /packages/app/src/components/prompt-input/attachments.ts
parentfc68c244333a3829177fd0594aa3d5c018203487 (diff)
downloadopencode-9239d877b9602a5a80e9e69e744abfe011f5f991.tar.gz
opencode-9239d877b9602a5a80e9e69e744abfe011f5f991.zip
fix(app): batch multi-file prompt attachments (#18722)
Diffstat (limited to 'packages/app/src/components/prompt-input/attachments.ts')
-rw-r--r--packages/app/src/components/prompt-input/attachments.ts38
1 files changed, 21 insertions, 17 deletions
diff --git a/packages/app/src/components/prompt-input/attachments.ts b/packages/app/src/components/prompt-input/attachments.ts
index eca508c6c..fa9930f68 100644
--- a/packages/app/src/components/prompt-input/attachments.ts
+++ b/packages/app/src/components/prompt-input/attachments.ts
@@ -71,6 +71,18 @@ export function createPromptAttachments(input: PromptAttachmentsInput) {
const addAttachment = (file: File) => add(file)
+ const addAttachments = async (files: File[], toast = true) => {
+ let found = false
+
+ for (const file of files) {
+ const ok = await add(file, false)
+ if (ok) found = true
+ }
+
+ if (!found && files.length > 0 && toast) warn()
+ return found
+ }
+
const removeAttachment = (id: string) => {
const current = prompt.current()
const next = current.filter((part) => part.type !== "image" || part.id !== id)
@@ -84,18 +96,14 @@ export function createPromptAttachments(input: PromptAttachmentsInput) {
event.preventDefault()
event.stopPropagation()
- const items = Array.from(clipboardData.items)
- const fileItems = items.filter((item) => item.kind === "file")
+ const files = Array.from(clipboardData.items).flatMap((item) => {
+ if (item.kind !== "file") return []
+ const file = item.getAsFile()
+ return file ? [file] : []
+ })
- if (fileItems.length > 0) {
- let found = false
- for (const item of fileItems) {
- const file = item.getAsFile()
- if (!file) continue
- const ok = await add(file, false)
- if (ok) found = true
- }
- if (!found) warn()
+ if (files.length > 0) {
+ await addAttachments(files)
return
}
@@ -169,12 +177,7 @@ export function createPromptAttachments(input: PromptAttachmentsInput) {
const dropped = event.dataTransfer?.files
if (!dropped) return
- let found = false
- for (const file of Array.from(dropped)) {
- const ok = await add(file, false)
- if (ok) found = true
- }
- if (!found && dropped.length > 0) warn()
+ await addAttachments(Array.from(dropped))
}
onMount(() => {
@@ -191,6 +194,7 @@ export function createPromptAttachments(input: PromptAttachmentsInput) {
return {
addAttachment,
+ addAttachments,
removeAttachment,
handlePaste,
}