editor: Fix pane's tab buttons flicker on right-click#42549
Merged
Conversation
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.
6c9e0f4 to
e73a184
Compare
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
This check was returning
falseright after right-clicking but returningtrueright after. When digging into it a little bit more, this appears to be happening because the editor'sMouseContextMenurelies onContextMenuwhich is rendered in a deferred fashion butMouseContextMenuupdates the window's focus to it instantaneously.Since the
ContextMenuis rendered in a deferred fashion, its focus handle is not yet a descendant of the editor (pane's active item) focus handle, so thecontains_focused(window, cx)call would returnfalse, with it returningtrueafter the menu was rendered.This commit updates the
MouseContextMenu::newfunction to leveragecx.on_next_frameand ensure that the focus is only moved to theContextMenu2 frames later, ensuring that by the time the focus is moved, theContextMenu's focus handle is a descendant of the editor's.Closes #41771
Release Notes: