# Fix zoomed panels closing when focus moves within the panel \(\#59439\) · gitcafe/zed

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

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

Visibility: public

Requested revision: 94c6647995181ea5e5f4888b4dda2f6d078e78b5

Requested commit: 94c6647995181ea5e5f4888b4dda2f6d078e78b5

Commit: 94c6647995181ea5e5f4888b4dda2f6d078e78b5

Tree: 9835eaa79ad5ee6afeaa4cf8a66d2f03fc9a0358

Author: Ben Kunkle

Committer: GitHub

## Message

```
Fix zoomed panels closing when focus moves within the panel (#59439)

Closes FR-139

Most focus-lost issues that close the agent panel in Zen mode stem from
panels returning a transient child editor's focus handle from
`Focusable::focus_handle`. The Zen-mode check closes the zoomed panel
when the focused element is not a descendant of the panel's focus
handle, so any focus movement inside the panel that landed outside that
child editor looked like the panel losing focus.

This PR separates the two roles that handle was serving:

- `Focusable::focus_handle` now always returns a stable handle tracked
at the panel's root element, used for containment checks (Zen-mode
auto-close, `toggle_panel_focus`, dock focus subscriptions).
- The new `Panel::activation_focus_handle` returns what should receive
focus when the panel is activated (e.g. a filter/commit/message editor)
and must be a focus-tree descendant of the root handle. All "focus the
panel" callsites in workspace/dock now use it.

Migrated panels: `AgentPanel` (including thread views and the toolbar
title editor), `CollabPanel`, `GitPanel`, `OutlinePanel`, and
`TerminalPanel` (previously delegated to the active pane, so focus in a
non-active pane dropped containment). `CollabPanel` activation falls
back to the panel root when signed out or collaboration is disabled,
since the filter editor isn't rendered in those states. Also fixes
duplicate element ids for tool calls with multiple content blocks.

Tests: a regression test that clicks tool-call output and focuses the
thread title editor while zoomed (both previously closed Zen mode), and
a dock-level test asserting the activation handle receives focus on
panel activation while the panel root reports containment.

Release Notes:

- Fixed zoomed panels (e.g. the agent panel in Zen mode) closing
unexpectedly when focus moved to elements inside the panel, such as tool
call output or the thread title editor.
```

## Parents

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

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