From 027f425804cbe0e7bd6f90ce36c5886fec4ae2c3 Mon Sep 17 00:00:00 2001 From: Thorsten Ball Date: Wed, 24 Jan 2024 11:47:59 +0100 Subject: [PATCH 1/4] Fix tab bar button's focus handling lagging behind This fixes https://github.com/zed-industries/community/issues/2442 for me. Previously, the tab bar buttons would stay when the chat panel was opened (and received focus) until something else was drawn (or caused a render?) With this change, the tab bar buttons are only shown if the pane was focus. I'm not sure about the side-effects of this, but the toolbar still seems to work fine. --- crates/workspace/src/pane.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/workspace/src/pane.rs b/crates/workspace/src/pane.rs index 10209f6e88..cc7eeb1a8a 100644 --- a/crates/workspace/src/pane.rs +++ b/crates/workspace/src/pane.rs @@ -1470,7 +1470,7 @@ impl Pane { ), ) }) - .when(self.was_focused || self.has_focus(cx), |tab_bar| { + .when(self.has_focus(cx), |tab_bar| { tab_bar.end_child({ let render_tab_buttons = self.render_tab_bar_buttons.clone(); render_tab_buttons(self, cx) 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 2/4] 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 cc7eeb1a8a..dd134576f5 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) { From fe2cb9f9ca5f6b727d28d1d7436bc4a6f65b485f Mon Sep 17 00:00:00 2001 From: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Date: Wed, 24 Jan 2024 14:01:17 +0100 Subject: [PATCH 3/4] fixup! pane: Another stab at focus flickers in tab bar --- crates/workspace/src/pane.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/crates/workspace/src/pane.rs b/crates/workspace/src/pane.rs index dd134576f5..ab8e248ac0 100644 --- a/crates/workspace/src/pane.rs +++ b/crates/workspace/src/pane.rs @@ -342,12 +342,10 @@ 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 + // 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) From 0d0c85a5ee5d2a1b57bca35d4248ec1e124834d9 Mon Sep 17 00:00:00 2001 From: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Date: Wed, 24 Jan 2024 14:03:12 +0100 Subject: [PATCH 4/4] Fix typo in comment --- crates/workspace/src/pane.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/workspace/src/pane.rs b/crates/workspace/src/pane.rs index ab8e248ac0..7f164c6e69 100644 --- a/crates/workspace/src/pane.rs +++ b/crates/workspace/src/pane.rs @@ -345,7 +345,7 @@ impl Pane { // 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 + // So before the next render, we might have transferred 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)