Skip to content

sidebar: Fix focus movement while toggling it on and off#53283

Merged
danilo-leal merged 3 commits intomainfrom
sidebar-focus-return
Apr 7, 2026
Merged

sidebar: Fix focus movement while toggling it on and off#53283
danilo-leal merged 3 commits intomainfrom
sidebar-focus-return

Conversation

@danilo-leal
Copy link
Copy Markdown
Member

I was testing out the changes in #52730 and realized that the agent panel, when full screen, would be auto-dismissed if I toggled the sidebar off. Turns out this happens because we were "hard-coding" the focus back to the center pane, which was automatically dismissing zoomed items. So, in this PR, I essentially am copying the ModalLayer approach of storing whatever was focused before so we can return focus back to it if possible.

Release Notes:

  • N/A

@danilo-leal danilo-leal self-assigned this Apr 7, 2026
@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Apr 7, 2026
@zed-community-bot zed-community-bot bot added the staff Pull requests authored by a current member of Zed staff label Apr 7, 2026
@danilo-leal danilo-leal requested a review from cameron1024 April 7, 2026 14:50
@danilo-leal danilo-leal merged commit a856093 into main Apr 7, 2026
47 of 49 checks passed
@danilo-leal danilo-leal deleted the sidebar-focus-return branch April 7, 2026 14:51
MasoudAlali pushed a commit to MasoudAlali/zed-ide that referenced this pull request Apr 7, 2026
…ies#53283)

I was testing out the changes in
zed-industries#52730 and realized that the
agent panel, when full screen, would be auto-dismissed if I toggled the
sidebar off. Turns out this happens because we were "hard-coding" the
focus back to the center pane, which was automatically dismissing zoomed
items. So, in this PR, I essentially am copying the ModalLayer approach
of storing whatever was focused before so we can return focus back to it
if possible.

Release Notes:

- N/A
danilo-leal added a commit that referenced this pull request Apr 8, 2026
Follow up to #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
Caio-Ze pushed a commit to Caio-Ze/postprod-ide that referenced this pull request Apr 8, 2026
…es#53386)

Follow up to zed-industries#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
rtfeldman pushed a commit that referenced this pull request Apr 10, 2026
Follow up to #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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement staff Pull requests authored by a current member of Zed staff

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants