From b83bff76e635fbacb5e97da09497734e32866491 Mon Sep 17 00:00:00 2001 From: kevinwright Date: Sat, 17 Jan 2026 01:10:41 +0100 Subject: [PATCH] Full file paths in drop handlers (#5211) * Use native drop handler to push full file paths into element drop handler * Remove debug code * fmt --------- Co-authored-by: Jonathan Kelley --- packages/desktop/src/file_upload.rs | 10 +++++++++ packages/desktop/src/webview.rs | 32 +++++++++++++++++++++-------- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/packages/desktop/src/file_upload.rs b/packages/desktop/src/file_upload.rs index 198a89ffe..e4a1e4728 100644 --- a/packages/desktop/src/file_upload.rs +++ b/packages/desktop/src/file_upload.rs @@ -305,15 +305,25 @@ impl HasFormData for DesktopFormData { #[derive(Default, Clone)] pub struct NativeFileHover { event: Rc>>, + paths: Rc>>, } impl NativeFileHover { pub fn set(&self, event: DragDropEvent) { + match event { + DragDropEvent::Enter { ref paths, .. } => self.paths.borrow_mut().clone_from(paths), + DragDropEvent::Drop { ref paths, .. } => self.paths.borrow_mut().clone_from(paths), + _ => {} + } self.event.borrow_mut().replace(event); } pub fn current(&self) -> Option { self.event.borrow_mut().clone() } + + pub fn current_paths(&self) -> Vec { + self.paths.borrow_mut().clone() + } } #[derive(Clone)] diff --git a/packages/desktop/src/webview.rs b/packages/desktop/src/webview.rs index 921f39dc3..d6a0d5738 100644 --- a/packages/desktop/src/webview.rs +++ b/packages/desktop/src/webview.rs @@ -13,7 +13,7 @@ use dioxus_core::{consume_context, provide_context, Runtime, ScopeId, VirtualDom use dioxus_document::Document; use dioxus_history::{History, MemoryHistory}; use dioxus_hooks::to_owned; -use dioxus_html::{FileData, FormValue, HtmlEvent, PlatformEventData}; +use dioxus_html::{FileData, FormValue, HtmlEvent, PlatformEventData, SerializedFileData}; use futures_util::{pin_mut, FutureExt}; use std::sync::{atomic::AtomicBool, Arc}; use std::{cell::OnceCell, time::Duration}; @@ -152,19 +152,35 @@ impl WebviewEdits { .collect(), }))) } + // Which also includes drops... dioxus_html::EventData::Drag(ref drag) => { // we want to override this with a native file engine, provided by the most recent drag event - let file_event = hovered_file.current(); - let file_paths = match file_event { - Some(wry::DragDropEvent::Enter { paths, .. }) => paths, - Some(wry::DragDropEvent::Drop { paths, .. }) => paths, - _ => vec![], + let full_file_paths = hovered_file.current_paths(); + + let xfer_data = drag.data_transfer.clone(); + let new_file_data = xfer_data + .files + .iter() + .map(|f| { + let new_path = full_file_paths + .iter() + .find(|p| p.ends_with(&f.path)) + .unwrap_or(&f.path); + SerializedFileData { + path: new_path.clone(), + ..f.clone() + } + }) + .collect::>(); + let new_xfer_data = dioxus_html::SerializedDataTransfer { + files: new_file_data, + ..xfer_data }; Rc::new(PlatformEventData::new(Box::new(DesktopFileDragEvent { mouse: drag.mouse.clone(), - data_transfer: drag.data_transfer.clone(), - files: file_paths, + data_transfer: new_xfer_data, + files: full_file_paths, }))) } _ => data.into_any(),