Fix a bug where the modal layer could not be dismissed by the mouse

This commit is contained in:
Mikayla Maki 2025-03-12 16:44:16 -07:00
parent 21949bcf1a
commit 0081b816fe

View file

@ -1,4 +1,7 @@
use gpui::{AnyView, DismissEvent, Entity, FocusHandle, Focusable as _, ManagedView, Subscription};
use gpui::{
AnyView, DismissEvent, Entity, FocusHandle, Focusable as _, ManagedView, MouseButton,
Subscription,
};
use ui::prelude::*;
#[derive(Debug)]
@ -172,11 +175,13 @@ impl Render for ModalLayer {
let mut background = cx.theme().colors().elevated_surface_background;
background.fade_out(0.2);
el.bg(background)
.occlude()
.on_mouse_down_out(cx.listener(|this, _, window, cx| {
this.hide_modal(window, cx);
}))
})
.on_mouse_down(
MouseButton::Left,
cx.listener(|this, _, window, cx| {
this.hide_modal(window, cx);
}),
)
.child(
v_flex()
.h(px(0.0))
@ -185,7 +190,14 @@ impl Render for ModalLayer {
.flex_col()
.items_center()
.track_focus(&active_modal.focus_handle)
.child(h_flex().occlude().child(active_modal.modal.view())),
.child(
h_flex()
.occlude()
.child(div().child(active_modal.modal.view()))
.on_mouse_down(MouseButton::Left, |_, _, cx| {
cx.stop_propagation();
}),
),
)
}
}