From c126fdb616a30e8c5c6faf65a35fc3df5bdd946d Mon Sep 17 00:00:00 2001 From: Bennet Bo Fenner <53836821+bennetbo@users.noreply.github.com> Date: Mon, 1 Apr 2024 12:31:19 +0200 Subject: [PATCH] Fix panel drag leaking through overlay (#10035) Closes #10017. While reworking the `overlay` element in #9911, I did not realize that all overlay elements called `defer_draw` with a priority of `1`. /cc @as-cii Not including release notes, since it was only present in nightly. Release Notes: - N/A --- crates/collab_ui/src/collab_panel.rs | 1 + crates/collab_ui/src/collab_panel/channel_modal.rs | 13 ++++++++----- crates/editor/src/element.rs | 1 + crates/gpui/src/elements/deferred.rs | 10 ++++++++++ crates/project_panel/src/project_panel.rs | 1 + crates/terminal_view/src/terminal_view.rs | 1 + crates/ui/src/components/popover_menu.rs | 5 +++-- crates/ui/src/components/right_click_menu.rs | 5 +++-- crates/workspace/src/pane.rs | 12 +++++------- 9 files changed, 33 insertions(+), 16 deletions(-) diff --git a/crates/collab_ui/src/collab_panel.rs b/crates/collab_ui/src/collab_panel.rs index f0fbd66f0342e..20943922e8506 100644 --- a/crates/collab_ui/src/collab_panel.rs +++ b/crates/collab_ui/src/collab_panel.rs @@ -2773,6 +2773,7 @@ impl Render for CollabPanel { .anchor(gpui::AnchorCorner::TopLeft) .child(menu.clone()), ) + .with_priority(1) })) } } diff --git a/crates/collab_ui/src/collab_panel/channel_modal.rs b/crates/collab_ui/src/collab_panel/channel_modal.rs index 65f266323aa75..3bc3fc1650c26 100644 --- a/crates/collab_ui/src/collab_panel/channel_modal.rs +++ b/crates/collab_ui/src/collab_panel/channel_modal.rs @@ -408,11 +408,14 @@ impl PickerDelegate for ChannelModalDelegate { .when(is_me, |el| el.child(Label::new("You").color(Color::Muted))) .children( if let (Some((menu, _)), true) = (&self.context_menu, selected) { - Some(deferred( - anchored() - .anchor(gpui::AnchorCorner::TopRight) - .child(menu.clone()), - )) + Some( + deferred( + anchored() + .anchor(gpui::AnchorCorner::TopRight) + .child(menu.clone()), + ) + .with_priority(1), + ) } else { None }, diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index 00877dc5309c0..787e70ff880d9 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -1812,6 +1812,7 @@ impl EditorElement { .anchor(AnchorCorner::TopLeft) .snap_to_window(), ) + .with_priority(1) .into_any(); element.layout(gpui::Point::default(), AvailableSpace::min_size(), cx); diff --git a/crates/gpui/src/elements/deferred.rs b/crates/gpui/src/elements/deferred.rs index c1e3942ca86fc..32a775f00ae05 100644 --- a/crates/gpui/src/elements/deferred.rs +++ b/crates/gpui/src/elements/deferred.rs @@ -15,6 +15,16 @@ pub struct Deferred { priority: usize, } +impl Deferred { + /// Sets the `priority` value of the `deferred` element, which + /// determines the drawing order relative to other deferred elements, + /// with higher values being drawn on top. + pub fn with_priority(mut self, priority: usize) -> Self { + self.priority = priority; + self + } +} + impl Element for Deferred { type BeforeLayout = (); type AfterLayout = (); diff --git a/crates/project_panel/src/project_panel.rs b/crates/project_panel/src/project_panel.rs index 6fb3bcda82ee9..467358215b587 100644 --- a/crates/project_panel/src/project_panel.rs +++ b/crates/project_panel/src/project_panel.rs @@ -1590,6 +1590,7 @@ impl Render for ProjectPanel { .anchor(gpui::AnchorCorner::TopLeft) .child(menu.clone()), ) + .with_priority(1) })) } else { v_flex() diff --git a/crates/terminal_view/src/terminal_view.rs b/crates/terminal_view/src/terminal_view.rs index 64e2a4eceeb37..fa0a7d0ec9552 100644 --- a/crates/terminal_view/src/terminal_view.rs +++ b/crates/terminal_view/src/terminal_view.rs @@ -771,6 +771,7 @@ impl Render for TerminalView { .anchor(gpui::AnchorCorner::TopLeft) .child(menu.clone()), ) + .with_priority(1) })) } } diff --git a/crates/ui/src/components/popover_menu.rs b/crates/ui/src/components/popover_menu.rs index a1062c8c08cc4..6c16bc565dd54 100644 --- a/crates/ui/src/components/popover_menu.rs +++ b/crates/ui/src/components/popover_menu.rs @@ -182,8 +182,9 @@ impl Element for PopoverMenu { this.resolved_attach().corner(child_bounds) + this.resolved_offset(cx), ); } - let mut element = - deferred(anchored.child(div().occlude().child(menu.clone()))).into_any(); + let mut element = deferred(anchored.child(div().occlude().child(menu.clone()))) + .with_priority(1) + .into_any(); menu_layout_id = Some(element.before_layout(cx)); element diff --git a/crates/ui/src/components/right_click_menu.rs b/crates/ui/src/components/right_click_menu.rs index bd9bbdbe5f9b7..b14963d07d7fd 100644 --- a/crates/ui/src/components/right_click_menu.rs +++ b/crates/ui/src/components/right_click_menu.rs @@ -110,8 +110,9 @@ impl Element for RightClickMenu { } anchored = anchored.position(*element_state.position.borrow()); - let mut element = - deferred(anchored.child(div().occlude().child(menu.clone()))).into_any(); + let mut element = deferred(anchored.child(div().occlude().child(menu.clone()))) + .with_priority(1) + .into_any(); menu_layout_id = Some(element.before_layout(cx)); element diff --git a/crates/workspace/src/pane.rs b/crates/workspace/src/pane.rs index 39b694e07009f..211fd3dad46f7 100644 --- a/crates/workspace/src/pane.rs +++ b/crates/workspace/src/pane.rs @@ -1562,16 +1562,14 @@ impl Pane { } fn render_menu_overlay(menu: &View) -> Div { - div() - .absolute() - .bottom_0() - .right_0() - .size_0() - .child(deferred( + div().absolute().bottom_0().right_0().size_0().child( + deferred( anchored() .anchor(AnchorCorner::TopRight) .child(menu.clone()), - )) + ) + .with_priority(1), + ) } pub fn set_zoomed(&mut self, zoomed: bool, cx: &mut ViewContext) {