From 88d8696414573a8b083053c1ba4d2b13bb701b6a Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Thu, 16 Jun 2022 14:37:33 +0200 Subject: [PATCH] Display tooltip for select prev/next match buttons --- assets/keymaps/default.json | 18 +++++++++--------- crates/search/src/buffer_search.rs | 27 ++++++++++++++++++++++++--- crates/search/src/project_search.rs | 27 ++++++++++++++++++++++++--- 3 files changed, 57 insertions(+), 15 deletions(-) diff --git a/assets/keymaps/default.json b/assets/keymaps/default.json index da0e904cca590903758098a53829ec956d22118e..87fddc8ce1e4ae42dc9d3e81d003b588b6379059 100644 --- a/assets/keymaps/default.json +++ b/assets/keymaps/default.json @@ -141,6 +141,15 @@ ] } }, + { + "context": "BufferSearchBar", + "bindings": { + "escape": "buffer_search::Dismiss", + "cmd-f": "buffer_search::FocusEditor", + "enter": "search::SelectNextMatch", + "shift-enter": "search::SelectPrevMatch" + } + }, { "context": "Pane", "bindings": { @@ -152,15 +161,6 @@ "alt-cmd-r": "search::ToggleRegex" } }, - { - "context": "BufferSearchBar", - "bindings": { - "escape": "buffer_search::Dismiss", - "cmd-f": "buffer_search::FocusEditor", - "enter": "search::SelectNextMatch", - "shift-enter": "search::SelectPrevMatch" - } - }, // Bindings from VS Code { "context": "Editor", diff --git a/crates/search/src/buffer_search.rs b/crates/search/src/buffer_search.rs index dcd0dbc891186f4660ea205d98b01aea33691570..de9e8af9c45edd04604e277ce9e1314b21073873 100644 --- a/crates/search/src/buffer_search.rs +++ b/crates/search/src/buffer_search.rs @@ -303,6 +303,20 @@ impl BufferSearchBar { direction: Direction, cx: &mut RenderContext, ) -> ElementBox { + let action: Box; + let tooltip; + match direction { + Direction::Prev => { + action = Box::new(SelectPrevMatch); + tooltip = "Select Previous Match"; + } + Direction::Next => { + action = Box::new(SelectNextMatch); + tooltip = "Select Next Match"; + } + }; + let tooltip_style = cx.global::().theme.tooltip.clone(); + enum NavButton {} MouseEventHandler::new::(direction as usize, cx, |state, cx| { let style = &cx @@ -316,11 +330,18 @@ impl BufferSearchBar { .with_style(style.container) .boxed() }) - .on_click(move |_, _, cx| match direction { - Direction::Prev => cx.dispatch_action(SelectPrevMatch), - Direction::Next => cx.dispatch_action(SelectNextMatch), + .on_click({ + let action = action.boxed_clone(); + move |_, _, cx| cx.dispatch_any_action(action.boxed_clone()) }) .with_cursor_style(CursorStyle::PointingHand) + .with_tooltip::( + direction as usize, + tooltip.to_string(), + Some(action), + tooltip_style, + cx, + ) .boxed() } diff --git a/crates/search/src/project_search.rs b/crates/search/src/project_search.rs index 7be7cc3d956ac36dde050ac7ce645d2fecaa53b8..bf862f0d9d0433c08b316ba34951af1eb1d4ac36 100644 --- a/crates/search/src/project_search.rs +++ b/crates/search/src/project_search.rs @@ -693,6 +693,20 @@ impl ProjectSearchBar { direction: Direction, cx: &mut RenderContext, ) -> ElementBox { + let action: Box; + let tooltip; + match direction { + Direction::Prev => { + action = Box::new(SelectPrevMatch); + tooltip = "Select Previous Match"; + } + Direction::Next => { + action = Box::new(SelectNextMatch); + tooltip = "Select Next Match"; + } + }; + let tooltip_style = cx.global::().theme.tooltip.clone(); + enum NavButton {} MouseEventHandler::new::(direction as usize, cx, |state, cx| { let style = &cx @@ -706,11 +720,18 @@ impl ProjectSearchBar { .with_style(style.container) .boxed() }) - .on_click(move |_, _, cx| match direction { - Direction::Prev => cx.dispatch_action(SelectPrevMatch), - Direction::Next => cx.dispatch_action(SelectNextMatch), + .on_click({ + let action = action.boxed_clone(); + move |_, _, cx| cx.dispatch_any_action(action.boxed_clone()) }) .with_cursor_style(CursorStyle::PointingHand) + .with_tooltip::( + direction as usize, + tooltip.to_string(), + Some(action), + tooltip_style, + cx, + ) .boxed() }