Add drag/drop handler for .txt files in App.tsx

This commit is contained in:
2026-01-31 00:37:32 +01:00
parent d8e05411a2
commit ad9ac08174

View File

@@ -77,6 +77,26 @@ export default function App() {
const bodyRef = useRef(body);
const historySnapshotRef = useRef<HistorySnapshot | null>(null);
useEffect(() => {
let unlisten: (() => void) | null = null;
getCurrentWindow()
.onDragDropEvent(async (event) => {
if (event.payload.type !== "drop") return;
const [path] = event.payload.paths ?? [];
if (!path || !path.toLowerCase().endsWith(".txt")) return;
await createTextFromFile(path);
})
.then((cleanup) => {
unlisten = cleanup;
})
.catch((error) => {
console.error("Failed to register drag/drop handler", error);
});
return () => {
if (unlisten) unlisten();
};
}, [createTextFromFile]);
useEffect(() => {
bodyRef.current = body;
}, [body]);