Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
pane: Fix tooltips of navigation buttons (#17035)
Piotr Osiewiczdfd113dfb046
diff --git a/crates/assistant/src/assistant_panel.rs b/crates/assistant/src/assistant_panel.rsindex a50c105171f..f915e221fbd 100644--- a/crates/assistant/src/assistant_panel.rs+++ b/crates/assistant/src/assistant_panel.rs@@ -360,12 +360,7 @@ impl AssistantPanel {}})).tooltip(move |cx| {- cx.new_view(|cx| {- let keybind =- KeyBinding::for_action_in(&DeployHistory, &focus_handle, cx);- Tooltip::new("Open History").key_binding(keybind)- })- .into()+ Tooltip::for_action_in("Open History", &DeployHistory, &focus_handle, cx)}).selected(pane.active_item()diff --git a/crates/ui/src/components/tooltip.rs b/crates/ui/src/components/tooltip.rsindex e8e837784bd..dc02d60b36d 100644--- a/crates/ui/src/components/tooltip.rs+++ b/crates/ui/src/components/tooltip.rs@@ -1,4 +1,4 @@-use gpui::{Action, AnyView, IntoElement, Render, VisualContext};+use gpui::{Action, AnyView, FocusHandle, IntoElement, Render, VisualContext};use settings::Settings;use theme::ThemeSettings;@@ -34,6 +34,19 @@ impl Tooltip {.into()}+ pub fn for_action_in(+ title: impl Into<SharedString>,+ action: &dyn Action,+ focus_handle: &FocusHandle,+ cx: &mut WindowContext,+ ) -> AnyView {+ cx.new_view(|cx| Self {+ title: title.into(),+ meta: None,+ key_binding: KeyBinding::for_action_in(action, focus_handle, cx),+ })+ .into()+ }pub fn with_meta(title: impl Into<SharedString>,action: Option<&dyn Action>,diff --git a/crates/workspace/src/pane.rs b/crates/workspace/src/pane.rsindex 0262ecf5acc..84c404c9f65 100644--- a/crates/workspace/src/pane.rs+++ b/crates/workspace/src/pane.rs@@ -1979,6 +1979,7 @@ impl Pane {}fn render_tab_bar(&mut self, cx: &mut ViewContext<'_, Pane>) -> impl IntoElement {+ let focus_handle = self.focus_handle.clone();let navigate_backward = IconButton::new("navigate_backward", IconName::ArrowLeft).shape(IconButtonShape::Square).icon_size(IconSize::Small)@@ -1987,7 +1988,10 @@ impl Pane {move |_, cx| view.update(cx, Self::navigate_backward)}).disabled(!self.can_navigate_backward())- .tooltip(|cx| Tooltip::for_action("Go Back", &GoBack, cx));+ .tooltip({+ let focus_handle = focus_handle.clone();+ move |cx| Tooltip::for_action_in("Go Back", &GoBack, &focus_handle, cx)+ });let navigate_forward = IconButton::new("navigate_forward", IconName::ArrowRight).shape(IconButtonShape::Square)@@ -1997,7 +2001,10 @@ impl Pane {move |_, cx| view.update(cx, Self::navigate_forward)}).disabled(!self.can_navigate_forward())- .tooltip(|cx| Tooltip::for_action("Go Forward", &GoForward, cx));+ .tooltip({+ let focus_handle = focus_handle.clone();+ move |cx| Tooltip::for_action_in("Go Forward", &GoForward, &focus_handle, cx)+ });TabBar::new("tab_bar").track_scroll(self.tab_bar_scroll_handle.clone())