Skip to content

Commit 863d7cc

Browse files
authored
Fix agent panel scroll while editing a past message (#30394)
This is similar to the `block_mouse_down` method added in #20649 (which has a very similar motivation), but is more comprehensive in stopping mouse events. Since I want to cherry-pick this to the releases, keeping this change just to the agent panel. In a follow-up will replace existing use of `block_mouse_down` to instead use this. Release Notes: - N/A
1 parent d270f6b commit 863d7cc

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

crates/agent/src/active_thread.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2235,7 +2235,7 @@ impl ActiveThread {
22352235
// Backdrop to dim out the whole thread below the editing user message
22362236
parent.relative().child(
22372237
div()
2238-
.occlude()
2238+
.stop_mouse_events_except_scroll()
22392239
.absolute()
22402240
.inset_0()
22412241
.size_full()

crates/gpui/src/elements/div.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ impl Interactivity {
490490

491491
/// Bind the given callback on the hover start and end events of this element. Note that the boolean
492492
/// passed to the callback is true when the hover starts and false when it ends.
493-
/// The imperative API equivalent to [`StatefulInteractiveElement::on_drag`]
493+
/// The imperative API equivalent to [`StatefulInteractiveElement::on_hover`]
494494
///
495495
/// See [`Context::listener`](crate::Context::listener) to get access to a view's state from this callback.
496496
pub fn on_hover(&mut self, listener: impl Fn(&bool, &mut Window, &mut App) + 'static)
@@ -544,6 +544,15 @@ impl Interactivity {
544544
pub fn occlude_mouse(&mut self) {
545545
self.occlude_mouse = true;
546546
}
547+
548+
/// Registers event handles that stop propagation of mouse events for non-scroll events.
549+
/// The imperative API equivalent to [`InteractiveElement::block_mouse_except_scroll`]
550+
pub fn stop_mouse_events_except_scroll(&mut self) {
551+
self.on_any_mouse_down(|_, _, cx| cx.stop_propagation());
552+
self.on_any_mouse_up(|_, _, cx| cx.stop_propagation());
553+
self.on_click(|_, _, cx| cx.stop_propagation());
554+
self.on_hover(|_, _, cx| cx.stop_propagation());
555+
}
547556
}
548557

549558
/// A trait for elements that want to use the standard GPUI event handlers that don't
@@ -919,11 +928,17 @@ pub trait InteractiveElement: Sized {
919928
self
920929
}
921930

922-
/// Block the mouse from interacting with this element or any of its children
923-
/// The fluent API equivalent to [`Interactivity::occlude_mouse`]
931+
/// Stops propagation of left mouse down event.
924932
fn block_mouse_down(mut self) -> Self {
925933
self.on_mouse_down(MouseButton::Left, |_, _, cx| cx.stop_propagation())
926934
}
935+
936+
/// Registers event handles that stop propagation of mouse events for non-scroll events.
937+
/// The fluent API equivalent to [`Interactivity::block_mouse_except_scroll`]
938+
fn stop_mouse_events_except_scroll(mut self) -> Self {
939+
self.interactivity().stop_mouse_events_except_scroll();
940+
self
941+
}
927942
}
928943

929944
/// A trait for elements that want to use the standard GPUI interactivity features

0 commit comments

Comments
 (0)