From 8d810db4d50f7f317c3d91c5e69be9f14fad07b8 Mon Sep 17 00:00:00 2001 From: Danilo Leal <67129314+danilo-leal@users.noreply.github.com> Date: Sun, 4 Jan 2026 21:01:08 -0300 Subject: [PATCH] workspace: Remove custom-positioned modal placement logic (#46047) This PR essentially removes the logic I introduced in https://github.com/zed-industries/zed/pull/45361 to position workspace modals based on the pointer click coordinates. All of this code has become unnecessary given in https://github.com/zed-industries/zed/pull/45924 we made the remote, project, and branch modals use popovers when triggered with a pointer, which already handle all the anchored positioning based on the trigger (much better). Release Notes: - N/A --- crates/workspace/src/modal_layer.rs | 77 +++++++---------------------- crates/workspace/src/workspace.rs | 17 +------ 2 files changed, 20 insertions(+), 74 deletions(-) diff --git a/crates/workspace/src/modal_layer.rs b/crates/workspace/src/modal_layer.rs index 4087e1a398ac2b89257fea6b4dce53278d0872a8..58667e7ffa8ad4fe5a22d293e4fc4aa71015a3bd 100644 --- a/crates/workspace/src/modal_layer.rs +++ b/crates/workspace/src/modal_layer.rs @@ -1,18 +1,9 @@ use gpui::{ AnyView, DismissEvent, Entity, EventEmitter, FocusHandle, Focusable as _, ManagedView, - MouseButton, Pixels, Point, Subscription, + MouseButton, Subscription, }; use ui::prelude::*; -#[derive(Debug, Clone, Copy, Default)] -pub enum ModalPlacement { - #[default] - Centered, - Anchored { - position: Point, - }, -} - #[derive(Debug)] pub enum DismissDecision { Dismiss(bool), @@ -67,7 +58,6 @@ pub struct ActiveModal { _subscriptions: [Subscription; 2], previous_focus_handle: Option, focus_handle: FocusHandle, - placement: ModalPlacement, } pub struct ModalLayer { @@ -97,19 +87,6 @@ impl ModalLayer { where V: ModalView, B: FnOnce(&mut Window, &mut Context) -> V, - { - self.toggle_modal_with_placement(window, cx, ModalPlacement::Centered, build_view); - } - - pub fn toggle_modal_with_placement( - &mut self, - window: &mut Window, - cx: &mut Context, - placement: ModalPlacement, - build_view: B, - ) where - V: ModalView, - B: FnOnce(&mut Window, &mut Context) -> V, { if let Some(active_modal) = &self.active_modal { let is_close = active_modal.modal.view().downcast::().is_ok(); @@ -119,17 +96,12 @@ impl ModalLayer { } } let new_modal = cx.new(|cx| build_view(window, cx)); - self.show_modal(new_modal, placement, window, cx); + self.show_modal(new_modal, window, cx); cx.emit(ModalOpenedEvent); } - fn show_modal( - &mut self, - new_modal: Entity, - placement: ModalPlacement, - window: &mut Window, - cx: &mut Context, - ) where + fn show_modal(&mut self, new_modal: Entity, window: &mut Window, cx: &mut Context) + where V: ModalView, { let focus_handle = cx.focus_handle(); @@ -151,7 +123,6 @@ impl ModalLayer { ], previous_focus_handle: window.focused(cx), focus_handle, - placement, }); cx.defer_in(window, move |_, window, cx| { window.focus(&new_modal.focus_handle(cx), cx); @@ -212,30 +183,6 @@ impl Render for ModalLayer { return active_modal.modal.view().into_any_element(); } - let content = h_flex() - .occlude() - .child(active_modal.modal.view()) - .on_mouse_down(MouseButton::Left, |_, _, cx| { - cx.stop_propagation(); - }); - - let positioned = match active_modal.placement { - ModalPlacement::Centered => v_flex() - .h(px(0.0)) - .top_20() - .items_center() - .track_focus(&active_modal.focus_handle) - .child(content) - .into_any_element(), - ModalPlacement::Anchored { position } => div() - .absolute() - .left(position.x) - .top(position.y - px(20.)) - .track_focus(&active_modal.focus_handle) - .child(content) - .into_any_element(), - }; - div() .absolute() .size_full() @@ -252,7 +199,21 @@ impl Render for ModalLayer { this.hide_modal(window, cx); }), ) - .child(positioned) + .child( + v_flex() + .h(px(0.0)) + .top_20() + .items_center() + .track_focus(&active_modal.focus_handle) + .child( + h_flex() + .occlude() + .child(active_modal.modal.view()) + .on_mouse_down(MouseButton::Left, |_, _, cx| { + cx.stop_propagation(); + }), + ), + ) .into_any_element() } } diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index 6dbe58415ff16e55fcaeda163e720605861a52ec..d12aa4f5a8eab3009d83004e50507fc3d07eff03 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -1205,7 +1205,6 @@ pub struct Workspace { last_open_dock_positions: Vec, removing: bool, utility_panes: UtilityPaneState, - next_modal_placement: Option, } impl EventEmitter for Workspace {} @@ -1632,7 +1631,6 @@ impl Workspace { last_open_dock_positions: Vec::new(), removing: false, utility_panes: UtilityPaneState::default(), - next_modal_placement: None, } } @@ -6350,25 +6348,12 @@ impl Workspace { self.modal_layer.read(cx).active_modal() } - pub fn is_modal_open(&self, cx: &App) -> bool { - self.modal_layer.read(cx).active_modal::().is_some() - } - - pub fn set_next_modal_placement(&mut self, placement: ModalPlacement) { - self.next_modal_placement = Some(placement); - } - - fn take_next_modal_placement(&mut self) -> ModalPlacement { - self.next_modal_placement.take().unwrap_or_default() - } - pub fn toggle_modal(&mut self, window: &mut Window, cx: &mut App, build: B) where B: FnOnce(&mut Window, &mut Context) -> V, { - let placement = self.take_next_modal_placement(); self.modal_layer.update(cx, |modal_layer, cx| { - modal_layer.toggle_modal_with_placement(window, cx, placement, build) + modal_layer.toggle_modal(window, cx, build) }) }