feat(app): drag-n-drop to @mention file (#12569)

This commit is contained in:
Devin Griffin
2026-02-07 13:33:00 -06:00
committed by GitHub
parent 4efbfcd087
commit 6bdd3528ac
19 changed files with 48 additions and 12 deletions

View File

@@ -205,7 +205,7 @@ export const PromptInput: Component<PromptInputProps> = (props) => {
historyIndex: number
savedPrompt: Prompt | null
placeholder: number
dragging: boolean
draggingType: "image" | "@mention" | null
mode: "normal" | "shell"
applyingHistory: boolean
}>({
@@ -213,7 +213,7 @@ export const PromptInput: Component<PromptInputProps> = (props) => {
historyIndex: -1,
savedPrompt: null,
placeholder: Math.floor(Math.random() * EXAMPLES.length),
dragging: false,
draggingType: null,
mode: "normal",
applyingHistory: false,
})
@@ -760,7 +760,11 @@ export const PromptInput: Component<PromptInputProps> = (props) => {
editor: () => editorRef,
isFocused,
isDialogActive: () => !!dialog.active,
setDragging: (value) => setStore("dragging", value),
setDraggingType: (type) => setStore("draggingType", type),
focusEditor: () => {
editorRef.focus()
setCursorPosition(editorRef, promptLength(prompt.current()))
},
addPart,
})
@@ -946,11 +950,14 @@ export const PromptInput: Component<PromptInputProps> = (props) => {
"group/prompt-input": true,
"bg-surface-raised-stronger-non-alpha shadow-xs-border relative": true,
"rounded-[14px] overflow-clip focus-within:shadow-xs-border": true,
"border-icon-info-active border-dashed": store.dragging,
"border-icon-info-active border-dashed": store.draggingType !== null,
[props.class ?? ""]: !!props.class,
}}
>
<PromptDragOverlay dragging={store.dragging} label={language.t("prompt.dropzone.label")} />
<PromptDragOverlay
type={store.draggingType}
label={language.t(store.draggingType === "@mention" ? "prompt.dropzone.file.label" : "prompt.dropzone.label")}
/>
<PromptContextItems
items={prompt.context.items()}
active={(item) => {

View File

@@ -11,7 +11,8 @@ type PromptAttachmentsInput = {
editor: () => HTMLDivElement | undefined
isFocused: () => boolean
isDialogActive: () => boolean
setDragging: (value: boolean) => void
setDraggingType: (type: "image" | "@mention" | null) => void
focusEditor: () => void
addPart: (part: ContentPart) => void
}
@@ -84,15 +85,18 @@ export function createPromptAttachments(input: PromptAttachmentsInput) {
event.preventDefault()
const hasFiles = event.dataTransfer?.types.includes("Files")
const hasText = event.dataTransfer?.types.includes("text/plain")
if (hasFiles) {
input.setDragging(true)
input.setDraggingType("image")
} else if (hasText) {
input.setDraggingType("@mention")
}
}
const handleGlobalDragLeave = (event: DragEvent) => {
if (input.isDialogActive()) return
if (!event.relatedTarget) {
input.setDragging(false)
input.setDraggingType(null)
}
}
@@ -100,7 +104,16 @@ export function createPromptAttachments(input: PromptAttachmentsInput) {
if (input.isDialogActive()) return
event.preventDefault()
input.setDragging(false)
input.setDraggingType(null)
const plainText = event.dataTransfer?.getData("text/plain")
const filePrefix = "file:"
if (plainText?.startsWith(filePrefix)) {
const filePath = plainText.slice(filePrefix.length)
input.focusEditor()
input.addPart({ type: "file", path: filePath, content: "@" + filePath, start: 0, end: 0 })
return
}
const dropped = event.dataTransfer?.files
if (!dropped) return

View File

@@ -2,16 +2,16 @@ import { Component, Show } from "solid-js"
import { Icon } from "@opencode-ai/ui/icon"
type PromptDragOverlayProps = {
dragging: boolean
type: "image" | "@mention" | null
label: string
}
export const PromptDragOverlay: Component<PromptDragOverlayProps> = (props) => {
return (
<Show when={props.dragging}>
<Show when={props.type !== null}>
<div class="absolute inset-0 z-10 flex items-center justify-center bg-surface-raised-stronger-non-alpha/90 pointer-events-none">
<div class="flex flex-col items-center gap-2 text-text-weak">
<Icon name="photo" class="size-8" />
<Icon name={props.type === "@mention" ? "link" : "photo"} class="size-8" />
<span class="text-14-regular">{props.label}</span>
</div>
</div>