# editor: Fix pane's tab buttons flicker on right-click \(\#42549\) · gitcafe/zed

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

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

Visibility: public

Requested revision: b709996ec6e57d7593f409fe519695df7d5e2608

Requested commit: b709996ec6e57d7593f409fe519695df7d5e2608

Commit: b709996ec6e57d7593f409fe519695df7d5e2608

Tree: 14d36f3f3b50bad2e2e441694a47b2bb54412e7a

Author: Dino

Committer: GitHub

## Message

````
editor: Fix pane's tab buttons flicker on right-click (#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 #41771 

Release Notes:

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

## Parents

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

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