From c32a7c1f616f3f8cbc89157ebf6e6076b3d12474 Mon Sep 17 00:00:00 2001 From: Danilo Leal <67129314+danilo-leal@users.noreply.github.com> Date: Wed, 8 Apr 2026 13:29:40 -0300 Subject: [PATCH] sidebar: Fix focus movement to protect zoomed in panels (#53386) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Follow up to https://github.com/zed-industries/zed/pull/53283. That PR replaced _where_ focus goes — from "always the center pane" to "the saved element." But it didn't fix _when_ focus moves — it still moves every time the sidebar closes, unconditionally. The problem is the saved focus can be wrong... it's saved when the sidebar opens, but then it can go to somewhere else after. An example: 1. Open sidebar → save focus (center pane), focus sidebar 2. Open agent panel from sidebar → focus moves to agent panel 3. Close sidebar → restore saved focus → **focuses center pane** (that's what was saved in step 1, not the agent panel) Effectively, this would still cause the agent panel to auto-dismiss. This PR fixes it by no moving focus at all if the sidebar doesn't have it. If the user already moved focus to the agent panel, there's nothing to "restore". Release Notes: - N/A --- crates/workspace/src/multi_workspace.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/crates/workspace/src/multi_workspace.rs b/crates/workspace/src/multi_workspace.rs index e9baccb4d93c9406d7b766db3d8e4ce4cb7198b7..aad5207e8b8d119ed6381a59665782c2b1e540d1 100644 --- a/crates/workspace/src/multi_workspace.rs +++ b/crates/workspace/src/multi_workspace.rs @@ -491,7 +491,15 @@ impl MultiWorkspace { workspace.set_sidebar_focus_handle(None); }); } - self.restore_previous_focus(true, window, cx); + let sidebar_has_focus = self + .sidebar + .as_ref() + .is_some_and(|s| s.focus_handle(cx).contains_focused(window, cx)); + if sidebar_has_focus { + self.restore_previous_focus(true, window, cx); + } else { + self.previous_focus_handle.take(); + } self.serialize(cx); cx.notify(); }