From 40a242b7a70ac50c8036fca454f3f155059d58a3 Mon Sep 17 00:00:00 2001 From: Razee4315 Date: Fri, 2 Jan 2026 15:18:26 +0500 Subject: [PATCH] Fixed the drag and drop feature. --- src/App.tsx | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/App.tsx b/src/App.tsx index a1db0da..eebe3fe 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,6 +1,7 @@ import { useState, useEffect, useCallback } from "react"; import { invoke } from "@tauri-apps/api/core"; import { open, save } from "@tauri-apps/plugin-dialog"; +import { listen, TauriEvent } from "@tauri-apps/api/event"; import { ThemeProvider } from "./context/ThemeContext"; import { TitleBar } from "./components/TitleBar"; @@ -61,6 +62,35 @@ function AppContent() { } }, []); + // Listen for Tauri drag-drop events + useEffect(() => { + const setupDragDrop = async () => { + const unlisten = await listen<{ paths: string[] }>(TauriEvent.DRAG_DROP, async (event) => { + const paths = event.payload.paths; + if (paths && paths.length > 0) { + const firstPath = paths[0]; + // Only load markdown files + if (firstPath.endsWith('.md') || firstPath.endsWith('.markdown')) { + await loadFile(firstPath); + } + } + }); + + return unlisten; + }; + + let unlisten: (() => void) | undefined; + setupDragDrop().then((fn) => { + unlisten = fn; + }); + + return () => { + if (unlisten) { + unlisten(); + } + }; + }, [loadFile]); + // Open file dialog const handleOpenFile = useCallback(async () => { try {