From 3fb1e6846d7f5e06c7740e5296a6f2e1e7243d4e Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Sat, 9 Dec 2023 12:00:33 -0800 Subject: [PATCH] Don't scroll List on out-of-bounds mouse wheel events --- crates/gpui2/src/elements/list.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/crates/gpui2/src/elements/list.rs b/crates/gpui2/src/elements/list.rs index ba479e1ea8..00857fb1df 100644 --- a/crates/gpui2/src/elements/list.rs +++ b/crates/gpui2/src/elements/list.rs @@ -1,6 +1,7 @@ use crate::{ - px, AnyElement, AvailableSpace, BorrowAppContext, DispatchPhase, Element, IntoElement, Pixels, - Point, ScrollWheelEvent, Size, Style, StyleRefinement, Styled, WindowContext, + px, AnyElement, AvailableSpace, BorrowAppContext, BorrowWindow as _, DispatchPhase, Element, + InteractiveBounds, IntoElement, Pixels, Point, ScrollWheelEvent, Size, Style, StyleRefinement, + Styled, WindowContext, }; use collections::VecDeque; use refineable::Refineable as _; @@ -394,10 +395,17 @@ impl Element for List { state.items = new_items; state.last_layout_width = Some(bounds.size.width); + let interactive_bounds = Rc::new(InteractiveBounds { + bounds: bounds.intersect(&cx.content_mask().bounds), + stacking_order: cx.stacking_order().clone(), + }); + let list_state = self.state.clone(); let height = bounds.size.height; cx.on_mouse_event(move |event: &ScrollWheelEvent, phase, cx| { - if phase == DispatchPhase::Bubble { + if interactive_bounds.visibly_contains(&event.position, cx) + && phase == DispatchPhase::Bubble + { list_state.0.borrow_mut().scroll( &scroll_top, height,