Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Add deadzones to drag and drop
Kay Simmons36bc90b2b89e
diff --git a/crates/drag_and_drop/src/drag_and_drop.rs b/crates/drag_and_drop/src/drag_and_drop.rsindex 6884de7e208..a34fa83a4c5 100644--- a/crates/drag_and_drop/src/drag_and_drop.rs+++ b/crates/drag_and_drop/src/drag_and_drop.rs@@ -9,11 +9,17 @@ use gpui::{View, WeakViewHandle,};+const DEAD_ZONE: f32 = 4.;+enum State<V: View> {Down {region_offset: Vector2F,region: RectF,},+ DeadZone {+ region_offset: Vector2F,+ region: RectF,+ },Dragging {window_id: usize,position: Vector2F,@@ -35,6 +41,13 @@ impl<V: View> Clone for State<V> {region_offset,region,},+ &State::DeadZone {+ region_offset,+ region,+ } => State::DeadZone {+ region_offset,+ region,+ },State::Dragging {window_id,position,@@ -101,7 +114,7 @@ impl<V: View> DragAndDrop<V> {pub fn drag_started(event: MouseDown, cx: &mut EventContext) {cx.update_global(|this: &mut Self, _| {this.currently_dragged = Some(State::Down {- region_offset: event.region.origin() - event.position,+ region_offset: event.position - event.region.origin(),region: event.region,});})@@ -122,7 +135,31 @@ impl<V: View> DragAndDrop<V> {region_offset,region,})- | Some(&State::Dragging {+ | Some(&State::DeadZone {+ region_offset,+ region,+ }) => {+ if (dbg!(event.position) - (dbg!(region.origin() + region_offset))).length()+ > DEAD_ZONE+ {+ this.currently_dragged = Some(State::Dragging {+ window_id,+ region_offset,+ region,+ position: event.position,+ payload,+ render: Rc::new(move |payload, cx| {+ render(payload.downcast_ref::<T>().unwrap(), cx)+ }),+ });+ } else {+ this.currently_dragged = Some(State::DeadZone {+ region_offset,+ region,+ })+ }+ }+ Some(&State::Dragging {region_offset,region,..@@ -151,6 +188,7 @@ impl<V: View> DragAndDrop<V> {.and_then(|state| {match state {State::Down { .. } => None,+ State::DeadZone { .. } => None,State::Dragging {window_id,region_offset,@@ -163,7 +201,7 @@ impl<V: View> DragAndDrop<V> {return None;}- let position = position + region_offset;+ let position = position - region_offset;Some(Overlay::new(MouseEventHandler::<DraggedElementHandler>::new(0, cx, |_, cx| {