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

@@ -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>