# sidebar: Fix focus movement to protect zoomed in panels \(\#53386\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/c32a7c1f616f3f8cbc89157ebf6e6076b3d12474)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: c32a7c1f616f3f8cbc89157ebf6e6076b3d12474

Requested commit: c32a7c1f616f3f8cbc89157ebf6e6076b3d12474

Commit: c32a7c1f616f3f8cbc89157ebf6e6076b3d12474

Tree: 241dc774fb96ab946eb6f8bda5f0bfca1110233d

Author: Danilo Leal

Committer: GitHub

## Message

```
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
```

## Parents

- [ae4404f148b6b8e9dab4f1d9dd9366bc135c37a7](https://git.cafe/gitcafe/zed/commit/ae4404f148b6b8e9dab4f1d9dd9366bc135c37a7?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/c32a7c1f616f3f8cbc89157ebf6e6076b3d12474?format=markdown)
