Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Don't start dragging until you move to 2px
Nathan Sobo38a7b39070b1
diff --git a/crates/gpui2/src/geometry.rs b/crates/gpui2/src/geometry.rsindex b472d77f574..95fa6c23535 100644--- a/crates/gpui2/src/geometry.rs+++ b/crates/gpui2/src/geometry.rs@@ -7,9 +7,7 @@ use std::{ops::{Add, Div, Mul, MulAssign, Sub},};-#[derive(- Refineable, Default, Add, AddAssign, Sub, SubAssign, Copy, Debug, PartialEq, Eq, Hash,-)]+#[derive(Refineable, Default, Add, AddAssign, Sub, SubAssign, Copy, Debug, PartialEq, Eq, Hash)]#[refineable(debug)]#[repr(C)]pub struct Point<T: Default + Clone + Debug> {@@ -41,6 +39,10 @@ impl Point<Pixels> {y: self.y.scale(factor),}}++ pub fn magnitude(&self) -> f64 {+ ((self.x.0.powi(2) + self.y.0.powi(2)) as f64).sqrt()+ }}impl<T, Rhs> Mul<Rhs> for Point<T>diff --git a/crates/gpui2/src/interactive.rs b/crates/gpui2/src/interactive.rsindex 0479d49f748..a078efff308 100644--- a/crates/gpui2/src/interactive.rs+++ b/crates/gpui2/src/interactive.rs@@ -16,6 +16,8 @@ use std::{sync::Arc,};+const DRAG_THRESHOLD: f64 = 2.;+pub trait StatelessInteractive: Element {fn stateless_interactivity(&mut self) -> &mut StatelessInteraction<Self::ViewState>;@@ -531,6 +533,7 @@ pub trait ElementInteraction<V: 'static + Send + Sync>: 'static + Send + Sync {if let Some(mouse_down) = mouse_down {if let Some(drag_listener) = drag_listener {let active_state = element_state.active_state.clone();+cx.on_mouse_event(move |view_state, event: &MouseMoveEvent, phase, cx| {if cx.active_drag.is_some() {if phase == DispatchPhase::Capture {@@ -538,6 +541,8 @@ pub trait ElementInteraction<V: 'static + Send + Sync>: 'static + Send + Sync {}} else if phase == DispatchPhase::Bubble&& bounds.contains_point(&event.position)+ && (event.position - mouse_down.position).magnitude()+ > DRAG_THRESHOLD{let cursor_offset = event.position - bounds.origin;let any_drag = drag_listener(view_state, cursor_offset, cx);