Skip to content

editor: Fix pane's tab buttons flicker on right-click#42549

Merged
dinocosta merged 2 commits intomainfrom
41771-button-flicker
Nov 13, 2025
Merged

editor: Fix pane's tab buttons flicker on right-click#42549
dinocosta merged 2 commits intomainfrom
41771-button-flicker

Conversation

@dinocosta
Copy link
Member

Whenever right-click was used on the editor, the pane's tab buttons would flicker, which was confirmed to happen because of the following check:

self.focus_handle.contains_focused(window, cx)
    || self
        .active_item()
        .is_some_and(|item| {
            item.item_focus_handle(cx).contains_focused(window, cx)
        })

This check was returning false right after right-clicking but returning true right after. When digging into it a little bit more, this appears to be happening because the editor's MouseContextMenu relies on ContextMenu which is rendered in a deferred fashion but MouseContextMenu updates the window's focus to it instantaneously.

Since the ContextMenu is rendered in a deferred fashion, its focus handle is not yet a descendant of the editor (pane's active item) focus handle, so the contains_focused(window, cx) call would return false, with it returning true after the menu was rendered.

This commit updates the MouseContextMenu::new function to leverage cx.on_next_frame and ensure that the focus is only moved to the ContextMenu 2 frames later, ensuring that by the time the focus is moved, the ContextMenu's focus handle is a descendant of the editor's.

Closes #41771

Release Notes:

  • Fixed pane's tab buttons flickering when using right-click on the editor

Whenever right-click was used on the editor, the pane's tab buttons
would flicker, which was confirmed to happen because of the following check:

```
self.focus_handle.contains_focused(window, cx)
    || self
        .active_item()
        .is_some_and(|item| {
            item.item_focus_handle(cx).contains_focused(window, cx)
        })
```

This check was returning `false` right after right-clicking but
returning `true` right after. When digging into it a little bit more,
this appears to be happening because the editor's `MouseContextMenu`
relies on `ContextMenu` which is rendered in a deferred fashion but
`MouseContextMenu` updates the window's focus to it instantaneously.

Since the `ContextMenu` is rendered in a deferred fashion, its focus
handle is not yet a descendant of the editor (pane's active item) focus
handle, so the `contains_focused(window, cx)` call would return `false`,
with it returning `true` after the menu was rendered.

This commit updates the `MouseContextMenu::new` function to leverage
`cx.on_next_frame` and ensure that the focus is only moved to the
`ContextMenu` 2 frames later, ensuring that by the time the focus is
moved, the `ContextMenu`'s focus handle is a descendant of the editor's.
@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Nov 12, 2025
@dinocosta dinocosta marked this pull request as ready for review November 12, 2025 17:43
@dinocosta dinocosta force-pushed the 41771-button-flicker branch from 6c9e0f4 to e73a184 Compare November 13, 2025 15:37
@dinocosta dinocosta merged commit b709996 into main Nov 13, 2025
23 checks passed
@dinocosta dinocosta deleted the 41771-button-flicker branch November 13, 2025 15:57
11happy pushed a commit to 11happy/zed that referenced this pull request Dec 1, 2025
…#42549)

Whenever right-click was used on the editor, the pane's tab buttons
would flicker, which was confirmed to happen because of the following
check:

```
self.focus_handle.contains_focused(window, cx)
    || self
        .active_item()
        .is_some_and(|item| {
            item.item_focus_handle(cx).contains_focused(window, cx)
        })
```

This check was returning `false` right after right-clicking but
returning `true` right after. When digging into it a little bit more,
this appears to be happening because the editor's `MouseContextMenu`
relies on `ContextMenu` which is rendered in a deferred fashion but
`MouseContextMenu` updates the window's focus to it instantaneously.

Since the `ContextMenu` is rendered in a deferred fashion, its focus
handle is not yet a descendant of the editor (pane's active item) focus
handle, so the `contains_focused(window, cx)` call would return `false`,
with it returning `true` after the menu was rendered.

This commit updates the `MouseContextMenu::new` function to leverage
`cx.on_next_frame` and ensure that the focus is only moved to the
`ContextMenu` 2 frames later, ensuring that by the time the focus is
moved, the `ContextMenu`'s focus handle is a descendant of the editor's.

Closes zed-industries#41771 

Release Notes:

- Fixed pane's tab buttons flickering when using right-click on the
editor
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.

New, Split Pane, and Zoom buttons flicker on Right Click

1 participant