Skip to content

DragTargetDrop does not fire when dragged item is under cursor. #1066

@Its-treason

Description

@Its-treason

When dragging an item, the DragTargetDrop does not fire when the preview of the dragged item is under the cursor.

I've built this fix for me locally, but I'm not sure if this is too much of a hack.

diff --git a/src/event/dispatch.rs b/src/event/dispatch.rs
index 243c999..e5f5b35 100644
--- a/src/event/dispatch.rs
+++ b/src/event/dispatch.rs
@@ -1109,13 +1109,24 @@ impl RouteCx<'_, '_> {
                 self.gcx.window_state.needs_box_tree_commit = true;
                 self.dispatch_drag_event(drag_dispatch);
             }
-            if let Some(_active) = &self.gcx.window_state.drag_tracker.active_drag {
+            if let Some(active) = &self.gcx.window_state.drag_tracker.active_drag {
                 self.gcx.window_state.needs_box_tree_from_layout = true;
                 let hover_path = self
                     .hit_path
                     .as_ref()
                     .map(|p| p.iter().as_slice())
                     .unwrap_or(&[]);
+                // Exclude the dragged element and its descendants from the
+                // hover path so the drag preview does not intercept drop-target
+                // hit-testing.
+                let dragged_id = active.element_id;
+                let hover_path = match hover_path
+                    .iter()
+                    .position(|id| *id == dragged_id)
+                {
+                    Some(idx) => &hover_path[..idx],
+                    None => hover_path,
+                };
                 let drag_events = self
                     .gcx
                     .window_state

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions