@@ -164,31 +164,44 @@ export function useTiptapEditor(options: UseTiptapEditorOptions) {
164164 const files = event . dataTransfer ?. files ;
165165 if ( ! files || files . length === 0 ) return false ;
166166
167- const paths : string [ ] = [ ] ;
167+ const paths : { path : string ; name : string } [ ] = [ ] ;
168168 for ( let i = 0 ; i < files . length ; i ++ ) {
169169 const file = files [ i ] ;
170170 // In Electron, File objects have a 'path' property
171171 // eslint-disable-next-line @typescript-eslint/no-explicit-any
172172 const path = ( file as any ) . path ;
173173 if ( path ) {
174- paths . push ( path ) ;
174+ paths . push ( { path, name : file . name } ) ;
175175 }
176176 }
177177
178178 if ( paths . length > 0 ) {
179179 event . preventDefault ( ) ;
180180
181+ // Insert file mention chips for each dropped file
182+ const { tr } = view . state ;
181183 const coordinates = view . posAtCoords ( {
182184 left : event . clientX ,
183185 top : event . clientY ,
184186 } ) ;
185- const pos = coordinates
186- ? coordinates . pos
187- : view . state . selection . from ;
188-
189- const textToInsert = paths . map ( ( p ) => `"${ p } "` ) . join ( " " ) ;
187+ let pos = coordinates ? coordinates . pos : view . state . selection . from ;
188+
189+ for ( const { path, name } of paths ) {
190+ const chipNode = view . state . schema . nodes . mentionChip ?. create ( {
191+ type : "file" ,
192+ id : path ,
193+ label : name ,
194+ } ) ;
195+ if ( chipNode ) {
196+ tr . insert ( pos , chipNode ) ;
197+ pos += chipNode . nodeSize ;
198+ // Add space after chip
199+ tr . insertText ( " " , pos ) ;
200+ pos += 1 ;
201+ }
202+ }
190203
191- view . dispatch ( view . state . tr . insertText ( ` ${ textToInsert } ` , pos ) ) ;
204+ view . dispatch ( tr ) ;
192205 return true ;
193206 }
194207
0 commit comments