sidebar: Fix focus movement to protect zoomed in panels (#53386)

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
This commit is contained in:
Danilo Leal 2026-04-08 13:29:40 -03:00 committed by GitHub
parent ae4404f148
commit c32a7c1f61
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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();
}