@@ -153,31 +153,44 @@ export function useTiptapEditor(options: UseTiptapEditorOptions) {
153153 const files = event . dataTransfer ?. files ;
154154 if ( ! files || files . length === 0 ) return false ;
155155
156- const paths : string [ ] = [ ] ;
156+ const paths : { path : string ; name : string } [ ] = [ ] ;
157157 for ( let i = 0 ; i < files . length ; i ++ ) {
158158 const file = files [ i ] ;
159159 // In Electron, File objects have a 'path' property
160160 // eslint-disable-next-line @typescript-eslint/no-explicit-any
161161 const path = ( file as any ) . path ;
162162 if ( path ) {
163- paths . push ( path ) ;
163+ paths . push ( { path, name : file . name } ) ;
164164 }
165165 }
166166
167167 if ( paths . length > 0 ) {
168168 event . preventDefault ( ) ;
169169
170+ // Insert file mention chips for each dropped file
171+ const { tr } = view . state ;
170172 const coordinates = view . posAtCoords ( {
171173 left : event . clientX ,
172174 top : event . clientY ,
173175 } ) ;
174- const pos = coordinates
175- ? coordinates . pos
176- : view . state . selection . from ;
177-
178- const textToInsert = paths . map ( ( p ) => `"${ p } "` ) . join ( " " ) ;
176+ let pos = coordinates ? coordinates . pos : view . state . selection . from ;
177+
178+ for ( const { path, name } of paths ) {
179+ const chipNode = view . state . schema . nodes . mentionChip ?. create ( {
180+ type : "file" ,
181+ id : path ,
182+ label : name ,
183+ } ) ;
184+ if ( chipNode ) {
185+ tr . insert ( pos , chipNode ) ;
186+ pos += chipNode . nodeSize ;
187+ // Add space after chip
188+ tr . insertText ( " " , pos ) ;
189+ pos += 1 ;
190+ }
191+ }
179192
180- view . dispatch ( view . state . tr . insertText ( ` ${ textToInsert } ` , pos ) ) ;
193+ view . dispatch ( tr ) ;
181194 return true ;
182195 }
183196
0 commit comments