From 0497b2f212b46efb9bb32876d0b3a02b24be7bbb Mon Sep 17 00:00:00 2001 From: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Date: Wed, 24 Jan 2024 13:57:55 +0100 Subject: [PATCH] pane: Another stab at focus flickers in tab bar This time around, we address the flicker seen in #3857 by querying the active item (that might've just been added), as it knows whether it has focus even if the parent Pane does not. Co-authored-by: Thorsten --- crates/workspace/src/pane.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/crates/workspace/src/pane.rs b/crates/workspace/src/pane.rs index cc7eeb1a8a3f7ff1542988b36b21903dab30665f..dd134576f5ec9bc8094975ce95df7a07c0e6332c 100644 --- a/crates/workspace/src/pane.rs +++ b/crates/workspace/src/pane.rs @@ -342,7 +342,18 @@ impl Pane { } pub fn has_focus(&self, cx: &WindowContext) -> bool { + // In addition to checking our own focus handle, + // we need to account for a brief moment (when active item is being switched) + // where we don't have focus. + // We not only check whether our focus handle contains focus, but also + // whether the active_item might have focus, because we might have just activated an item + // but that hasn't rendered yet. So before the next render, we might have transfered focus + // to the item and `focus_handle.contains_focus` returns false because the `active_item` + // is not hooked up to us in the dispatch tree. self.focus_handle.contains_focused(cx) + || self + .active_item() + .map_or(false, |item| item.focus_handle(cx).contains_focused(cx)) } fn focus_in(&mut self, cx: &mut ViewContext) {