From 0a04c5734baa51d3d93752861054f430f6400b09 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Thu, 26 Oct 2023 13:50:35 +0200 Subject: [PATCH] Update mouse position during file drag and drop --- crates/gpui2/src/window.rs | 33 ++++++++++++++++++------------ crates/ui2/src/components/panes.rs | 1 - 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/crates/gpui2/src/window.rs b/crates/gpui2/src/window.rs index 8b3aa7a11768c9177e81fbd48f4cc2e744b5daa6..fc9b8b8de88a6da2c3624bde1e74056f54c61f72 100644 --- a/crates/gpui2/src/window.rs +++ b/crates/gpui2/src/window.rs @@ -1,7 +1,7 @@ use crate::{ px, size, Action, AnyBox, AnyDrag, AnyView, AppContext, AsyncWindowContext, AvailableSpace, - Bounds, BoxShadow, Context, Corners, DevicePixels, DispatchContext, DisplayId, ExternalPaths, - Edges, Effect, Element, EntityId, EventEmitter, FileDropEvent, FocusEvent, FontId, + Bounds, BoxShadow, Context, Corners, DevicePixels, DispatchContext, DisplayId, Edges, Effect, + Element, EntityId, EventEmitter, ExternalPaths, FileDropEvent, FocusEvent, FontId, GlobalElementId, GlyphId, Handle, Hsla, ImageData, InputEvent, IsZero, KeyListener, KeyMatch, KeyMatcher, Keystroke, LayoutId, MainThread, MainThreadOnly, Modifiers, MonochromeSprite, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent, Path, Pixels, PlatformAtlas, @@ -899,6 +899,7 @@ impl<'a, 'w> WindowContext<'a, 'w> { } InputEvent::FileDrop(file_drop) => match file_drop { FileDropEvent::Entered { position, files } => { + self.window.mouse_position = position; self.active_drag.get_or_insert_with(|| AnyDrag { drag_handle_view: None, cursor_offset: position, @@ -912,17 +913,23 @@ impl<'a, 'w> WindowContext<'a, 'w> { modifiers: Modifiers::default(), }) } - FileDropEvent::Pending { position } => InputEvent::MouseMove(MouseMoveEvent { - position, - pressed_button: Some(MouseButton::Left), - modifiers: Modifiers::default(), - }), - FileDropEvent::Submit { position } => InputEvent::MouseUp(MouseUpEvent { - button: MouseButton::Left, - position, - modifiers: Modifiers::default(), - click_count: 1, - }), + FileDropEvent::Pending { position } => { + self.window.mouse_position = position; + InputEvent::MouseMove(MouseMoveEvent { + position, + pressed_button: Some(MouseButton::Left), + modifiers: Modifiers::default(), + }) + } + FileDropEvent::Submit { position } => { + self.window.mouse_position = position; + InputEvent::MouseUp(MouseUpEvent { + button: MouseButton::Left, + position, + modifiers: Modifiers::default(), + click_count: 1, + }) + } FileDropEvent::Exited => InputEvent::MouseUp(MouseUpEvent { button: MouseButton::Left, position: Point::default(), diff --git a/crates/ui2/src/components/panes.rs b/crates/ui2/src/components/panes.rs index 77b6817d89f2da35d24976ea4b3f5228ae6c3f39..fd1ec56ae7cdf185bf00e2cf556b0e6d19ca4757 100644 --- a/crates/ui2/src/components/panes.rs +++ b/crates/ui2/src/components/panes.rs @@ -56,7 +56,6 @@ impl Pane { .children(self.children.drain(..)), ) .child( - // TODO kb! Figure out why we can't we see the red background when we drag a file over this div. div() .z_index(1) .id("drag-target")