From a54932e35442e50201e59e44a1da36e07dad77d9 Mon Sep 17 00:00:00 2001 From: Eric Holk Date: Mon, 16 Mar 2026 16:30:06 -0700 Subject: [PATCH] Don't snap back to old position when resizing drawer --- crates/agent_ui/src/agent_panel.rs | 9 ++++++++- crates/workspace/src/workspace.rs | 32 +++++++++++++++--------------- crates/zed/src/zed.rs | 2 ++ 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/crates/agent_ui/src/agent_panel.rs b/crates/agent_ui/src/agent_panel.rs index 293b0fca42bba650dfd67c57dcc2e367c2e5b305..fb4ff1a4dcf37ae028d21ed2b2131865237f5813 100644 --- a/crates/agent_ui/src/agent_panel.rs +++ b/crates/agent_ui/src/agent_panel.rs @@ -787,7 +787,10 @@ impl AgentPanel { return; }; - let width = self.width; + let width = self + .workspace + .upgrade() + .and_then(|workspace| workspace.read(cx).drawer_width::()); let selected_agent_type = self.selected_agent_type.clone(); let start_thread_in = Some(self.start_thread_in); @@ -1188,6 +1191,10 @@ impl AgentPanel { &self.context_server_registry } + pub fn width(&self) -> Option { + self.width + } + pub fn is_visible(workspace: &Entity, cx: &App) -> bool { workspace.read(cx).drawer_is_open::() } diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index 10492a3062a3f6e4bf01105cd75414bdd181c313..27048fc7a23237594c9410e3663595cea4176e73 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -54,9 +54,9 @@ use gpui::{ Action, AnyEntity, AnyView, AnyWeakView, App, AsyncApp, AsyncWindowContext, Bounds, Context, CursorStyle, Decorations, DragMoveEvent, Entity, EntityId, EventEmitter, FocusHandle, Focusable, Global, HitboxBehavior, Hsla, KeyContext, Keystroke, ManagedView, MouseButton, - MouseUpEvent, PathPromptOptions, Point, PromptLevel, Render, ResizeEdge, Size, Stateful, - Subscription, SystemWindowTabController, Task, Tiling, WeakEntity, WindowBounds, WindowHandle, - WindowId, WindowOptions, actions, canvas, deferred, point, relative, size, transparent_black, + PathPromptOptions, Point, PromptLevel, Render, ResizeEdge, Size, Stateful, Subscription, + SystemWindowTabController, Task, Tiling, WeakEntity, WindowBounds, WindowHandle, WindowId, + WindowOptions, actions, canvas, deferred, point, relative, size, transparent_black, }; pub use history_manager::*; pub use item::{ @@ -7176,6 +7176,18 @@ impl Workspace { } } + pub fn drawer_width(&self) -> Option { + self.drawer_ref::() + .and_then(|(_, drawer)| drawer.custom_width) + } + + pub fn set_drawer_width(&mut self, width: Option, cx: &mut Context) { + if let Some((_, drawer)) = self.drawer_mut::() { + drawer.custom_width = width; + cx.notify(); + } + } + pub fn drawer_is_open(&self) -> bool { if let Some((_, drawer)) = self.drawer_ref::() { drawer.open @@ -7290,19 +7302,6 @@ impl Workspace { .on_mouse_down(MouseButton::Left, |_, _, cx| { cx.stop_propagation(); }) - .on_mouse_up( - MouseButton::Left, - cx.listener(move |workspace, _: &MouseUpEvent, _, cx| { - let drawer = match position { - DrawerPosition::Left => &mut workspace.left_drawer, - DrawerPosition::Right => &mut workspace.right_drawer, - }; - if let Some(drawer) = drawer { - drawer.custom_width = None; - cx.notify(); - } - }), - ) .occlude(); match position { DrawerPosition::Left => deferred( @@ -8182,6 +8181,7 @@ impl Render for Workspace { ); } } + workspace.serialize_workspace(window, cx); }, )) }) diff --git a/crates/zed/src/zed.rs b/crates/zed/src/zed.rs index 20378904f3ee996af04e9b5c88e9da5cf70f2040..c813fad0595006c5ca4308b9be997de88e798ec7 100644 --- a/crates/zed/src/zed.rs +++ b/crates/zed/src/zed.rs @@ -688,6 +688,7 @@ fn setup_or_teardown_ai_panels( let position = PanelHandle::position(&threads_panel, window, cx); if !disable_ai && !have_panel { workspace.add_panel(threads_panel, window, cx); + let width = agent_drawer.read(cx).width(); match position { workspace::dock::DockPosition::Left => { workspace.set_left_drawer(agent_drawer, cx) @@ -699,6 +700,7 @@ fn setup_or_teardown_ai_panels( unreachable!("drawers cannot go on the bottom") } } + workspace.set_drawer_width::(width, cx); } }) });