@@ -11,7 +11,8 @@ type PromptAttachmentsInput = {
1111 editor : ( ) => HTMLDivElement | undefined
1212 isFocused : ( ) => boolean
1313 isDialogActive : ( ) => boolean
14- setDragging : ( value : boolean ) => void
14+ setDraggingType : ( type : "image" | "@mention" | null ) => void
15+ focusEditor : ( ) => void
1516 addPart : ( part : ContentPart ) => void
1617}
1718
@@ -84,23 +85,35 @@ export function createPromptAttachments(input: PromptAttachmentsInput) {
8485
8586 event . preventDefault ( )
8687 const hasFiles = event . dataTransfer ?. types . includes ( "Files" )
88+ const hasText = event . dataTransfer ?. types . includes ( "text/plain" )
8789 if ( hasFiles ) {
88- input . setDragging ( true )
90+ input . setDraggingType ( "image" )
91+ } else if ( hasText ) {
92+ input . setDraggingType ( "@mention" )
8993 }
9094 }
9195
9296 const handleGlobalDragLeave = ( event : DragEvent ) => {
9397 if ( input . isDialogActive ( ) ) return
9498 if ( ! event . relatedTarget ) {
95- input . setDragging ( false )
99+ input . setDraggingType ( null )
96100 }
97101 }
98102
99103 const handleGlobalDrop = async ( event : DragEvent ) => {
100104 if ( input . isDialogActive ( ) ) return
101105
102106 event . preventDefault ( )
103- input . setDragging ( false )
107+ input . setDraggingType ( null )
108+
109+ const plainText = event . dataTransfer ?. getData ( "text/plain" )
110+ const filePrefix = "file:"
111+ if ( plainText ?. startsWith ( filePrefix ) ) {
112+ const filePath = plainText . slice ( filePrefix . length )
113+ input . focusEditor ( )
114+ input . addPart ( { type : "file" , path : filePath , content : "@" + filePath , start : 0 , end : 0 } )
115+ return
116+ }
104117
105118 const dropped = event . dataTransfer ?. files
106119 if ( ! dropped ) return
0 commit comments