From b6b081596aa32866cb6ba081cb1a55e6ae66cd1a Mon Sep 17 00:00:00 2001 From: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Date: Mon, 12 Aug 2024 16:53:11 +0200 Subject: [PATCH] assistant: Show tooltips on workflow step buttons only when cursor is in step (#16108) Release Notes: - N/A --- crates/assistant/src/assistant_panel.rs | 107 +++++++++++++++++------- 1 file changed, 78 insertions(+), 29 deletions(-) diff --git a/crates/assistant/src/assistant_panel.rs b/crates/assistant/src/assistant_panel.rs index 2e3e1399ae..472ed414d2 100644 --- a/crates/assistant/src/assistant_panel.rs +++ b/crates/assistant/src/assistant_panel.rs @@ -1397,6 +1397,21 @@ impl WorkflowStepStatus { cx: &mut BlockContext<'_, '_>, ) -> AnyElement { let id = EntityId::from(cx.block_id); + fn display_keybind_in_tooltip( + step_range: &Range, + editor: &WeakView, + cx: &mut WindowContext<'_>, + ) -> bool { + editor + .update(cx, |this, _| { + this.active_workflow_step + .as_ref() + .map(|step| &step.range == step_range) + }) + .ok() + .flatten() + .unwrap_or_default() + } match self { WorkflowStepStatus::Resolving => Icon::new(IconName::ArrowCircle) .size(IconSize::Small) @@ -1448,15 +1463,24 @@ impl WorkflowStepStatus { .icon_size(IconSize::Small) .label_size(LabelSize::Small) .style(ButtonStyle::Tinted(TintColor::Accent)) - .tooltip(move |cx| { - cx.new_view(|cx| { - Tooltip::new("Transform").key_binding(KeyBinding::for_action_in( - &Assist, - &focus_handle, - cx, - )) - }) - .into() + .tooltip({ + let step_range = step_range.clone(); + let editor = editor.clone(); + move |cx| { + cx.new_view(|cx| { + let tooltip = Tooltip::new("Transform"); + if display_keybind_in_tooltip(&step_range, &editor, cx) { + tooltip.key_binding(KeyBinding::for_action_in( + &Assist, + &focus_handle, + cx, + )) + } else { + tooltip + } + }) + .into() + } }) .on_click({ let editor = editor.clone(); @@ -1476,15 +1500,24 @@ impl WorkflowStepStatus { .icon_size(IconSize::Small) .label_size(LabelSize::Small) .style(ButtonStyle::Tinted(TintColor::Negative)) - .tooltip(move |cx| { - cx.new_view(|cx| { - Tooltip::new("Stop Transformation").key_binding(KeyBinding::for_action_in( - &editor::actions::Cancel, - &focus_handle, - cx, - )) - }) - .into() + .tooltip({ + let step_range = step_range.clone(); + let editor = editor.clone(); + move |cx| { + cx.new_view(|cx| { + let tooltip = Tooltip::new("Stop Transformation"); + if display_keybind_in_tooltip(&step_range, &editor, cx) { + tooltip.key_binding(KeyBinding::for_action_in( + &editor::actions::Cancel, + &focus_handle, + cx, + )) + } else { + tooltip + } + }) + .into() + } }) .on_click({ let editor = editor.clone(); @@ -1509,15 +1542,20 @@ impl WorkflowStepStatus { .style(ButtonStyle::Tinted(TintColor::Negative)) .tooltip({ let focus_handle = focus_handle.clone(); + let editor = editor.clone(); + let step_range = step_range.clone(); move |cx| { cx.new_view(|cx| { - Tooltip::new("Reject Transformation").key_binding( - KeyBinding::for_action_in( + let tooltip = Tooltip::new("Reject Transformation"); + if display_keybind_in_tooltip(&step_range, &editor, cx) { + tooltip.key_binding(KeyBinding::for_action_in( &editor::actions::Cancel, &focus_handle, cx, - ), - ) + )) + } else { + tooltip + } }) .into() } @@ -1541,13 +1579,24 @@ impl WorkflowStepStatus { .icon_size(IconSize::Small) .label_size(LabelSize::Small) .style(ButtonStyle::Tinted(TintColor::Positive)) - .tooltip(move |cx| { - cx.new_view(|cx| { - Tooltip::new("Accept Transformation").key_binding( - KeyBinding::for_action_in(&Assist, &focus_handle, cx), - ) - }) - .into() + .tooltip({ + let editor = editor.clone(); + let step_range = step_range.clone(); + move |cx| { + cx.new_view(|cx| { + let tooltip = Tooltip::new("Accept Transformation"); + if display_keybind_in_tooltip(&step_range, &editor, cx) { + tooltip.key_binding(KeyBinding::for_action_in( + &Assist, + &focus_handle, + cx, + )) + } else { + tooltip + } + }) + .into() + } }) .on_click({ let editor = editor.clone();