Skip to content
This repository was archived by the owner on Aug 6, 2026. It is now read-only.

Commit d6ccda6

Browse files
committed
feat: file drag and drop
1 parent 6699343 commit d6ccda6

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

apps/array/src/renderer/features/message-editor/tiptap/useTiptapEditor.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,42 @@ export function useTiptapEditor(options: UseTiptapEditorOptions) {
141141
}
142142
}
143143

144+
return false;
145+
},
146+
handleDrop: (view, event, _slice, moved) => {
147+
if (moved) return false;
148+
149+
const files = event.dataTransfer?.files;
150+
if (!files || files.length === 0) return false;
151+
152+
const paths: string[] = [];
153+
for (let i = 0; i < files.length; i++) {
154+
const file = files[i];
155+
// In Electron, File objects have a 'path' property
156+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
157+
const path = (file as any).path;
158+
if (path) {
159+
paths.push(path);
160+
}
161+
}
162+
163+
if (paths.length > 0) {
164+
event.preventDefault();
165+
166+
const coordinates = view.posAtCoords({
167+
left: event.clientX,
168+
top: event.clientY,
169+
});
170+
const pos = coordinates
171+
? coordinates.pos
172+
: view.state.selection.from;
173+
174+
const textToInsert = paths.map((p) => `"${p}"`).join(" ");
175+
176+
view.dispatch(view.state.tr.insertText(textToInsert + " ", pos));
177+
return true;
178+
}
179+
144180
return false;
145181
},
146182
},

0 commit comments

Comments
 (0)