Skip to content

ui: Dismiss context menus when window loses focus - #46866

Merged
danilo-leal merged 2 commits into
zed-industries:mainfrom
notnotjake:proposed/context-menu-dismiss-on-blur
Jan 15, 2026
Merged

ui: Dismiss context menus when window loses focus#46866
danilo-leal merged 2 commits into
zed-industries:mainfrom
notnotjake:proposed/context-menu-dismiss-on-blur

Conversation

@notnotjake

Copy link
Copy Markdown
Contributor

Context menus close when the window becomes inactive (e.g., clicking to another window or app). Previously, menus would remain visible until the window regained focus.

This aligns Zed's context menu behavior with native macOS apps, where NSMenu automatically dismisses when the window loses focus. Users expect menus to close when switching windows or apps.

Uses observe_window_activation to detect when the window becomes inactive and calls cancel to dismiss the menu.

Release Notes:

  • Fixed context menus dismiss/cancel when the window loses focus

Context menus now close when the window becomes inactive (e.g., clicking
to another window or app). Previously, menus would remain visible until
the window regained focus.

Uses `observe_window_activation` to detect when the window becomes
inactive and calls `cancel` to dismiss the menu.
@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label Jan 15, 2026
@maxdeviant maxdeviant changed the title ui: dismiss context menus when window loses focus ui: Dismiss context menus when window loses focus Jan 15, 2026

@danilo-leal danilo-leal left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@danilo-leal
danilo-leal enabled auto-merge (squash) January 15, 2026 13:48
@danilo-leal
danilo-leal merged commit d139c5e into zed-industries:main Jan 15, 2026
23 checks passed
@notnotjake
notnotjake deleted the proposed/context-menu-dismiss-on-blur branch January 16, 2026 07:16
ConradIrwin added a commit that referenced this pull request Jan 28, 2026
@ConradIrwin ConradIrwin mentioned this pull request Jan 28, 2026
@ConradIrwin

Copy link
Copy Markdown
Member

I'm not sure why yet, but this seems to have caused two problems: the terminal lost focus when window switching, and the macOS emoji picker stopped working. I'm reverting in #47835

ConradIrwin added a commit that referenced this pull request Jan 28, 2026
- **Revert "ui: Dismiss context menus when window loses focus
(#46866)"**
- **Revert "Preserve and restore focus across window activation cycles
(#47044)"**

Closes #ISSUE

Release Notes:

- (preview only) Fixed typing emoji using the macOS system palette
(cmd-ctrl-space)
github-actions Bot pushed a commit that referenced this pull request Jan 28, 2026
- **Revert "ui: Dismiss context menus when window loses focus
(#46866)"**
- **Revert "Preserve and restore focus across window activation cycles
(#47044)"**

Closes #ISSUE

Release Notes:

- (preview only) Fixed typing emoji using the macOS system palette
(cmd-ctrl-space)
zed-zippy Bot added a commit that referenced this pull request Jan 28, 2026
Cherry-pick of #47835 to preview

----
- **Revert "ui: Dismiss context menus when window loses focus
(#46866)"**
- **Revert "Preserve and restore focus across window activation cycles
(#47044)"**

Closes #ISSUE

Release Notes:

- (preview only) Fixed typing emoji using the macOS system palette
(cmd-ctrl-space)

Co-authored-by: Conrad Irwin <conrad.irwin@gmail.com>
jonx pushed a commit to jonx/zed-aros that referenced this pull request Jul 17, 2026
Context menus close when the window becomes inactive (e.g., clicking to
another window or app). Previously, menus would remain visible until the
window regained focus.

This aligns Zed's context menu behavior with native macOS apps, where
NSMenu automatically dismisses when the window loses focus. Users expect
menus to close when switching windows or apps.

Uses `observe_window_activation` to detect when the window becomes
inactive and calls `cancel` to dismiss the menu.

Release Notes:

- Fixed context menus dismiss/cancel when the window loses focus

---------

Co-authored-by: Danilo Leal <daniloleal09@gmail.com>
jonx pushed a commit to jonx/zed-aros that referenced this pull request Jul 17, 2026
- **Revert "ui: Dismiss context menus when window loses focus
(zed-industries#46866)"**
- **Revert "Preserve and restore focus across window activation cycles
(zed-industries#47044)"**

Closes #ISSUE

Release Notes:

- (preview only) Fixed typing emoji using the macOS system palette
(cmd-ctrl-space)
butvinm added a commit to butvinm/zed that referenced this pull request Aug 5, 2026
Window deactivation blanked the focus path in `Window::draw`, so every
`on_blur` / `on_focus_out` listener fired as if the user had moved focus
away, while `window.focus` and therefore `FocusHandle::is_focused` kept
saying the handle was still focused. Controls that end an edit on blur
destroyed user input whenever the user switched applications, or merely
switched keyboard layout on Wayland, which is zed-industries#39286 and the one-control-
at-a-time patches zed-industries#41320, zed-industries#46866 and zed-industries#47044 that preceded it.

Window activation already has its own channel: `Window::active` is set
before `activation_observers` run, and is exposed as
`Context::observe_window_activation`. So the focus channel simply stops
carrying it. `Frame::window_active` had no other reader and is deleted;
`focus_lost_listeners` keyed off the raw paths and is unaffected.

Consumers that genuinely want the deactivation signal move to a named
helper, `Context::on_deactivated_while_focused`: the editor's hover
popover, completion menu and edit prediction, and context menus. The
terminal needs both edges for xterm focus reporting, so it observes
window activation directly. The `is_window_active()` guards in the
picker, project panel, collab panel and Go to Line become dead and are
removed.

Fixes zed-industries#39286
jolutz pushed a commit to jolutz/zed that referenced this pull request Aug 8, 2026
Context menus close when the window becomes inactive (e.g., clicking to
another window or app). Previously, menus would remain visible until the
window regained focus.

This aligns Zed's context menu behavior with native macOS apps, where
NSMenu automatically dismisses when the window loses focus. Users expect
menus to close when switching windows or apps.

Uses `observe_window_activation` to detect when the window becomes
inactive and calls `cancel` to dismiss the menu.

Release Notes:

- Fixed context menus dismiss/cancel when the window loses focus

---------

Co-authored-by: Danilo Leal <daniloleal09@gmail.com>
jolutz pushed a commit to jolutz/zed that referenced this pull request Aug 8, 2026
- **Revert "ui: Dismiss context menus when window loses focus
(zed-industries#46866)"**
- **Revert "Preserve and restore focus across window activation cycles
(zed-industries#47044)"**

Closes #ISSUE

Release Notes:

- (preview only) Fixed typing emoji using the macOS system palette
(cmd-ctrl-space)
butvinm added a commit to butvinm/zed that referenced this pull request Aug 8, 2026
Window deactivation blanked the focus path in `Window::draw`, so every
`on_blur` / `on_focus_out` listener fired as if the user had moved focus
away, while `window.focus` and therefore `FocusHandle::is_focused` kept
saying the handle was still focused. Controls that end an edit on blur
destroyed user input whenever the user switched applications, or merely
switched keyboard layout on Wayland, which is zed-industries#39286 and the one-control-
at-a-time patches zed-industries#41320, zed-industries#46866 and zed-industries#47044 that preceded it.

Window activation already has its own channel: `Window::active` is set
before `activation_observers` run, and is exposed as
`Context::observe_window_activation`. So the focus channel simply stops
carrying it. `Frame::window_active` had no other reader and is deleted;
`focus_lost_listeners` keyed off the raw paths and is unaffected.

Consumers that genuinely want the deactivation signal move to a named
helper, `Context::on_deactivated_while_focused`: the editor's hover
popover, completion menu and edit prediction, and context menus. The
terminal needs both edges for xterm focus reporting, so it observes
window activation directly. The `is_window_active()` guards in the
picker, project panel, collab panel and Go to Line become dead and are
removed.

Fixes zed-industries#39286
butvinm added a commit to butvinm/zed that referenced this pull request Aug 16, 2026
Window deactivation blanked the focus path in `Window::draw`, so every
`on_blur` / `on_focus_out` listener fired as if the user had moved focus
away, while `window.focus` and therefore `FocusHandle::is_focused` kept
saying the handle was still focused. Controls that end an edit on blur
destroyed user input whenever the user switched applications, or merely
switched keyboard layout on Wayland, which is zed-industries#39286 and the one-control-
at-a-time patches zed-industries#41320, zed-industries#46866 and zed-industries#47044 that preceded it.

Window activation already has its own channel: `Window::active` is set
before `activation_observers` run, and is exposed as
`Context::observe_window_activation`. So the focus channel simply stops
carrying it. `Frame::window_active` had no other reader and is deleted;
`focus_lost_listeners` keyed off the raw paths and is unaffected.

Consumers that genuinely want the deactivation signal move to a named
helper, `Context::on_deactivated_while_focused`: the editor's hover
popover, completion menu and edit prediction, and context menus. The
terminal needs both edges for xterm focus reporting, so it observes
window activation directly. The `is_window_active()` guards in the
picker, project panel, collab panel and Go to Line become dead and are
removed.

Fixes zed-industries#39286
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants