Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Fix tab bar button flickering when opening menus (#45098)
Antonio Scandurra4af26f085280
diff --git a/crates/ui/src/components/popover_menu.rs b/crates/ui/src/components/popover_menu.rsindex b1a52bec8fd..7fdb39126b5 100644--- a/crates/ui/src/components/popover_menu.rs+++ b/crates/ui/src/components/popover_menu.rs@@ -287,7 +287,19 @@ fn show_menu<M: ManagedView>(window.refresh();}).detach();- window.focus(&new_menu.focus_handle(cx));++ // Since menus are rendered in a deferred fashion, their focus handles are+ // not linked in the dispatch tree until after the deferred draw callback+ // runs. We need to wait for that to happen before focusing it, so that+ // calling `contains_focused` on the parent's focus handle returns `true`+ // when the menu is focused. This prevents the pane's tab bar buttons from+ // flickering when opening popover menus.+ let focus_handle = new_menu.focus_handle(cx);+ window.on_next_frame(move |window, _cx| {+ window.on_next_frame(move |window, _cx| {+ window.focus(&focus_handle);+ });+ });*menu.borrow_mut() = Some(new_menu);window.refresh();diff --git a/crates/ui/src/components/right_click_menu.rs b/crates/ui/src/components/right_click_menu.rsindex dff42307371..5b654c295e8 100644--- a/crates/ui/src/components/right_click_menu.rs+++ b/crates/ui/src/components/right_click_menu.rs@@ -259,7 +259,19 @@ impl<M: ManagedView> Element for RightClickMenu<M> {window.refresh();}).detach();- window.focus(&new_menu.focus_handle(cx));++ // Since menus are rendered in a deferred fashion, their focus handles are+ // not linked in the dispatch tree until after the deferred draw callback+ // runs. We need to wait for that to happen before focusing it, so that+ // calling `contains_focused` on the parent's focus handle returns `true`+ // when the menu is focused. This prevents the pane's tab bar buttons from+ // flickering when opening menus.+ let focus_handle = new_menu.focus_handle(cx);+ window.on_next_frame(move |window, _cx| {+ window.on_next_frame(move |window, _cx| {+ window.focus(&focus_handle);+ });+ });*menu.borrow_mut() = Some(new_menu);*position.borrow_mut() = if let Some(child_bounds) = child_bounds {if let Some(attach) = attach {