From a835dcefa2de923e569e5483efb4920e4396b327 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Thu, 16 Jun 2022 13:44:00 +0200 Subject: [PATCH 1/6] Toggle buffer search options via the keyboard --- assets/keymaps/default.json | 22 +++++++++- crates/search/src/buffer_search.rs | 66 ++++++++++++++++++----------- crates/search/src/project_search.rs | 14 ++++-- crates/search/src/search.rs | 23 +++++++--- 4 files changed, 90 insertions(+), 35 deletions(-) diff --git a/assets/keymaps/default.json b/assets/keymaps/default.json index 635adfb64d..46474fd33a 100644 --- a/assets/keymaps/default.json +++ b/assets/keymaps/default.json @@ -15,7 +15,7 @@ "shift-cmd-}": "pane::ActivateNextItem", "cmd-w": "pane::CloseActiveItem", "cmd-shift-W": "workspace::CloseWindow", - "alt-cmd-w": "pane::CloseInactiveItems", + "cmd-k alt-cmd-w": "pane::CloseInactiveItems", "cmd-s": "workspace::Save", "cmd-shift-S": "workspace::SaveAs", "cmd-=": "zed::IncreaseBufferFontSize", @@ -146,7 +146,25 @@ "bindings": { "cmd-f": "project_search::ToggleFocus", "cmd-g": "search::SelectNextMatch", - "cmd-shift-G": "search::SelectPrevMatch" + "cmd-shift-G": "search::SelectPrevMatch", + "alt-cmd-c": [ + "search::ToggleSearchOption", + { + "option": "CaseSensitive" + } + ], + "alt-cmd-w": [ + "search::ToggleSearchOption", + { + "option": "WholeWord" + } + ], + "alt-cmd-r": [ + "search::ToggleSearchOption", + { + "option": "Regex" + } + ] } }, { diff --git a/crates/search/src/buffer_search.rs b/crates/search/src/buffer_search.rs index ce36e63ad2..f96801f050 100644 --- a/crates/search/src/buffer_search.rs +++ b/crates/search/src/buffer_search.rs @@ -1,12 +1,12 @@ use crate::{ active_match_index, match_index_for_direction, query_suggestion_for_editor, Direction, - SearchOption, SelectNextMatch, SelectPrevMatch, + SearchOption, SelectNextMatch, SelectPrevMatch, ToggleSearchOption, }; use collections::HashMap; use editor::{Anchor, Autoscroll, Editor}; use gpui::{ - actions, elements::*, impl_actions, impl_internal_actions, platform::CursorStyle, AppContext, - Entity, MutableAppContext, RenderContext, Subscription, Task, View, ViewContext, ViewHandle, + actions, elements::*, impl_actions, platform::CursorStyle, AppContext, Entity, + MutableAppContext, RenderContext, Subscription, Task, View, ViewContext, ViewHandle, WeakViewHandle, }; use language::OffsetRangeExt; @@ -21,12 +21,8 @@ pub struct Deploy { pub focus: bool, } -#[derive(Clone, PartialEq)] -pub struct ToggleSearchOption(pub SearchOption); - actions!(buffer_search, [Dismiss, FocusEditor]); impl_actions!(buffer_search, [Deploy]); -impl_internal_actions!(buffer_search, [ToggleSearchOption]); pub enum Event { UpdateLocation, @@ -36,7 +32,21 @@ pub fn init(cx: &mut MutableAppContext) { cx.add_action(BufferSearchBar::deploy); cx.add_action(BufferSearchBar::dismiss); cx.add_action(BufferSearchBar::focus_editor); - cx.add_action(BufferSearchBar::toggle_search_option); + cx.add_action( + |pane: &mut Pane, + ToggleSearchOption { option }: &ToggleSearchOption, + cx: &mut ViewContext| { + if let Some(search_bar) = pane.toolbar().read(cx).item_of_type::() { + if search_bar.update(cx, |search_bar, cx| search_bar.show(false, false, cx)) { + search_bar.update(cx, |search_bar, cx| { + search_bar.toggle_search_option(*option, cx); + }); + return; + } + } + cx.propagate_action(); + }, + ); cx.add_action(BufferSearchBar::select_next_match); cx.add_action(BufferSearchBar::select_prev_match); cx.add_action(BufferSearchBar::select_next_match_on_pane); @@ -215,16 +225,18 @@ impl BufferSearchBar { cx.notify(); } - fn show(&mut self, focus: bool, cx: &mut ViewContext) -> bool { + fn show(&mut self, focus: bool, suggest_query: bool, cx: &mut ViewContext) -> bool { let editor = if let Some(editor) = self.active_editor.clone() { editor } else { return false; }; - let text = query_suggestion_for_editor(&editor, cx); - if !text.is_empty() { - self.set_query(&text, cx); + if suggest_query { + let text = query_suggestion_for_editor(&editor, cx); + if !text.is_empty() { + self.set_query(&text, cx); + } } if focus { @@ -253,11 +265,12 @@ impl BufferSearchBar { fn render_search_option( &self, icon: &str, - search_option: SearchOption, + option: SearchOption, cx: &mut RenderContext, ) -> ElementBox { - let is_active = self.is_search_option_enabled(search_option); - MouseEventHandler::new::(search_option as usize, cx, |state, cx| { + let tooltip_style = cx.global::().theme.tooltip.clone(); + let is_active = self.is_search_option_enabled(option); + MouseEventHandler::new::(option as usize, cx, |state, cx| { let style = &cx .global::() .theme @@ -269,8 +282,15 @@ impl BufferSearchBar { .with_style(style.container) .boxed() }) - .on_click(move |_, _, cx| cx.dispatch_action(ToggleSearchOption(search_option))) + .on_click(move |_, _, cx| cx.dispatch_action(ToggleSearchOption { option })) .with_cursor_style(CursorStyle::PointingHand) + .with_tooltip::( + option as usize, + format!("Toggle {}", option.label()), + Some(Box::new(ToggleSearchOption { option })), + tooltip_style, + cx, + ) .boxed() } @@ -303,7 +323,7 @@ impl BufferSearchBar { fn deploy(pane: &mut Pane, action: &Deploy, cx: &mut ViewContext) { if let Some(search_bar) = pane.toolbar().read(cx).item_of_type::() { - if search_bar.update(cx, |search_bar, cx| search_bar.show(action.focus, cx)) { + if search_bar.update(cx, |search_bar, cx| search_bar.show(action.focus, true, cx)) { return; } } @@ -334,11 +354,7 @@ impl BufferSearchBar { } } - fn toggle_search_option( - &mut self, - ToggleSearchOption(search_option): &ToggleSearchOption, - cx: &mut ViewContext, - ) { + fn toggle_search_option(&mut self, search_option: SearchOption, cx: &mut ViewContext) { let value = match search_option { SearchOption::WholeWord => &mut self.whole_word, SearchOption::CaseSensitive => &mut self.case_sensitive, @@ -591,7 +607,7 @@ mod tests { let search_bar = cx.add_view(Default::default(), |cx| { let mut search_bar = BufferSearchBar::new(cx); search_bar.set_active_pane_item(Some(&editor), cx); - search_bar.show(false, cx); + search_bar.show(false, true, cx); search_bar }); @@ -619,7 +635,7 @@ mod tests { // Switch to a case sensitive search. search_bar.update(cx, |search_bar, cx| { - search_bar.toggle_search_option(&ToggleSearchOption(SearchOption::CaseSensitive), cx); + search_bar.toggle_search_option(SearchOption::CaseSensitive, cx); }); editor.next_notification(&cx).await; editor.update(cx, |editor, cx| { @@ -676,7 +692,7 @@ mod tests { // Switch to a whole word search. search_bar.update(cx, |search_bar, cx| { - search_bar.toggle_search_option(&ToggleSearchOption(SearchOption::WholeWord), cx); + search_bar.toggle_search_option(SearchOption::WholeWord, cx); }); editor.next_notification(&cx).await; editor.update(cx, |editor, cx| { diff --git a/crates/search/src/project_search.rs b/crates/search/src/project_search.rs index a7cfb020b5..0ba74348f8 100644 --- a/crates/search/src/project_search.rs +++ b/crates/search/src/project_search.rs @@ -655,7 +655,7 @@ impl ProjectSearchBar { fn toggle_search_option( &mut self, - ToggleSearchOption(option): &ToggleSearchOption, + ToggleSearchOption { option }: &ToggleSearchOption, cx: &mut ViewContext, ) { if let Some(search_view) = self.active_project_search.as_ref() { @@ -705,8 +705,9 @@ impl ProjectSearchBar { option: SearchOption, cx: &mut RenderContext, ) -> ElementBox { + let tooltip_style = cx.global::().theme.tooltip.clone(); let is_active = self.is_option_enabled(option, cx); - MouseEventHandler::new::(option as usize, cx, |state, cx| { + MouseEventHandler::new::(option as usize, cx, |state, cx| { let style = &cx .global::() .theme @@ -718,8 +719,15 @@ impl ProjectSearchBar { .with_style(style.container) .boxed() }) - .on_click(move |_, _, cx| cx.dispatch_action(ToggleSearchOption(option))) + .on_click(move |_, _, cx| cx.dispatch_action(ToggleSearchOption { option })) .with_cursor_style(CursorStyle::PointingHand) + .with_tooltip::( + option as usize, + format!("Toggle {}", option.label()), + Some(Box::new(ToggleSearchOption { option })), + tooltip_style, + cx, + ) .boxed() } diff --git a/crates/search/src/search.rs b/crates/search/src/search.rs index 68bdc78c7a..048eb1ddeb 100644 --- a/crates/search/src/search.rs +++ b/crates/search/src/search.rs @@ -1,7 +1,8 @@ pub use buffer_search::BufferSearchBar; use editor::{display_map::ToDisplayPoint, Anchor, Bias, Editor, MultiBufferSnapshot}; -use gpui::{actions, impl_internal_actions, MutableAppContext, ViewHandle}; +use gpui::{actions, impl_actions, MutableAppContext, ViewHandle}; pub use project_search::{ProjectSearchBar, ProjectSearchView}; +use serde::Deserialize; use std::{ cmp::{self, Ordering}, ops::Range, @@ -15,19 +16,31 @@ pub fn init(cx: &mut MutableAppContext) { project_search::init(cx); } -#[derive(Clone, PartialEq)] -pub struct ToggleSearchOption(pub SearchOption); +#[derive(Clone, PartialEq, Deserialize)] +pub struct ToggleSearchOption { + pub option: SearchOption, +} actions!(search, [SelectNextMatch, SelectPrevMatch]); -impl_internal_actions!(search, [ToggleSearchOption]); +impl_actions!(search, [ToggleSearchOption]); -#[derive(Clone, Copy, PartialEq)] +#[derive(Clone, Copy, PartialEq, Deserialize)] pub enum SearchOption { WholeWord, CaseSensitive, Regex, } +impl SearchOption { + pub fn label(&self) -> &'static str { + match self { + SearchOption::WholeWord => "Match Whole Word", + SearchOption::CaseSensitive => "Match Case", + SearchOption::Regex => "Use Regular Expression", + } + } +} + #[derive(Clone, Copy, PartialEq, Eq)] pub enum Direction { Prev, From d0d6c27ae9df7cb90d8b120a1b7e1fdd2f8f104d Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Thu, 16 Jun 2022 14:06:47 +0200 Subject: [PATCH 2/6] Don't select next match when toggling buffer search option --- crates/search/src/buffer_search.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/search/src/buffer_search.rs b/crates/search/src/buffer_search.rs index f96801f050..d00bc32b08 100644 --- a/crates/search/src/buffer_search.rs +++ b/crates/search/src/buffer_search.rs @@ -361,7 +361,7 @@ impl BufferSearchBar { SearchOption::Regex => &mut self.regex, }; *value = !*value; - self.update_matches(true, cx); + self.update_matches(false, cx); cx.notify(); } From 29e57c8e3cefd23731b19b1aa3e015f2ebb834f7 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Thu, 16 Jun 2022 14:18:45 +0200 Subject: [PATCH 3/6] Toggle project search options via the keyboard --- crates/search/src/project_search.rs | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/crates/search/src/project_search.rs b/crates/search/src/project_search.rs index 0ba74348f8..e2b3a90782 100644 --- a/crates/search/src/project_search.rs +++ b/crates/search/src/project_search.rs @@ -35,10 +35,23 @@ pub fn init(cx: &mut MutableAppContext) { cx.add_action(ProjectSearchView::deploy); cx.add_action(ProjectSearchBar::search); cx.add_action(ProjectSearchBar::search_in_new); - cx.add_action(ProjectSearchBar::toggle_search_option); cx.add_action(ProjectSearchBar::select_next_match); cx.add_action(ProjectSearchBar::select_prev_match); cx.add_action(ProjectSearchBar::toggle_focus); + cx.add_action( + |pane: &mut Pane, + ToggleSearchOption { option }: &ToggleSearchOption, + cx: &mut ViewContext| { + if let Some(search_bar) = pane.toolbar().read(cx).item_of_type::() { + if search_bar.update(cx, |search_bar, cx| { + search_bar.toggle_search_option(*option, cx) + }) { + return; + } + } + cx.propagate_action(); + }, + ); cx.capture_action(ProjectSearchBar::tab); } @@ -653,11 +666,7 @@ impl ProjectSearchBar { } } - fn toggle_search_option( - &mut self, - ToggleSearchOption { option }: &ToggleSearchOption, - cx: &mut ViewContext, - ) { + fn toggle_search_option(&mut self, option: SearchOption, cx: &mut ViewContext) -> bool { if let Some(search_view) = self.active_project_search.as_ref() { search_view.update(cx, |search_view, cx| { let value = match option { @@ -669,6 +678,9 @@ impl ProjectSearchBar { search_view.search(cx); }); cx.notify(); + true + } else { + false } } From 649185da9c0a69ebcdd7c813dc27b1c5c021169e Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Thu, 16 Jun 2022 14:28:37 +0200 Subject: [PATCH 4/6] Allow toggling search options via the command palette --- assets/keymaps/default.json | 21 ++------------ crates/search/src/buffer_search.rs | 41 ++++++++++++++------------- crates/search/src/project_search.rs | 43 +++++++++++++++-------------- crates/search/src/search.rs | 30 +++++++++++++------- 4 files changed, 68 insertions(+), 67 deletions(-) diff --git a/assets/keymaps/default.json b/assets/keymaps/default.json index 46474fd33a..da0e904cca 100644 --- a/assets/keymaps/default.json +++ b/assets/keymaps/default.json @@ -147,24 +147,9 @@ "cmd-f": "project_search::ToggleFocus", "cmd-g": "search::SelectNextMatch", "cmd-shift-G": "search::SelectPrevMatch", - "alt-cmd-c": [ - "search::ToggleSearchOption", - { - "option": "CaseSensitive" - } - ], - "alt-cmd-w": [ - "search::ToggleSearchOption", - { - "option": "WholeWord" - } - ], - "alt-cmd-r": [ - "search::ToggleSearchOption", - { - "option": "Regex" - } - ] + "alt-cmd-c": "search::ToggleCaseSensitive", + "alt-cmd-w": "search::ToggleWholeWord", + "alt-cmd-r": "search::ToggleRegex" } }, { diff --git a/crates/search/src/buffer_search.rs b/crates/search/src/buffer_search.rs index d00bc32b08..dcd0dbc891 100644 --- a/crates/search/src/buffer_search.rs +++ b/crates/search/src/buffer_search.rs @@ -1,11 +1,12 @@ use crate::{ active_match_index, match_index_for_direction, query_suggestion_for_editor, Direction, - SearchOption, SelectNextMatch, SelectPrevMatch, ToggleSearchOption, + SearchOption, SelectNextMatch, SelectPrevMatch, ToggleCaseSensitive, ToggleRegex, + ToggleWholeWord, }; use collections::HashMap; use editor::{Anchor, Autoscroll, Editor}; use gpui::{ - actions, elements::*, impl_actions, platform::CursorStyle, AppContext, Entity, + actions, elements::*, impl_actions, platform::CursorStyle, Action, AppContext, Entity, MutableAppContext, RenderContext, Subscription, Task, View, ViewContext, ViewHandle, WeakViewHandle, }; @@ -32,26 +33,28 @@ pub fn init(cx: &mut MutableAppContext) { cx.add_action(BufferSearchBar::deploy); cx.add_action(BufferSearchBar::dismiss); cx.add_action(BufferSearchBar::focus_editor); - cx.add_action( - |pane: &mut Pane, - ToggleSearchOption { option }: &ToggleSearchOption, - cx: &mut ViewContext| { - if let Some(search_bar) = pane.toolbar().read(cx).item_of_type::() { - if search_bar.update(cx, |search_bar, cx| search_bar.show(false, false, cx)) { - search_bar.update(cx, |search_bar, cx| { - search_bar.toggle_search_option(*option, cx); - }); - return; - } - } - cx.propagate_action(); - }, - ); cx.add_action(BufferSearchBar::select_next_match); cx.add_action(BufferSearchBar::select_prev_match); cx.add_action(BufferSearchBar::select_next_match_on_pane); cx.add_action(BufferSearchBar::select_prev_match_on_pane); cx.add_action(BufferSearchBar::handle_editor_cancel); + add_toggle_option_action::(SearchOption::CaseSensitive, cx); + add_toggle_option_action::(SearchOption::WholeWord, cx); + add_toggle_option_action::(SearchOption::Regex, cx); +} + +fn add_toggle_option_action(option: SearchOption, cx: &mut MutableAppContext) { + cx.add_action(move |pane: &mut Pane, _: &A, cx: &mut ViewContext| { + if let Some(search_bar) = pane.toolbar().read(cx).item_of_type::() { + if search_bar.update(cx, |search_bar, cx| search_bar.show(false, false, cx)) { + search_bar.update(cx, |search_bar, cx| { + search_bar.toggle_search_option(option, cx); + }); + return; + } + } + cx.propagate_action(); + }); } pub struct BufferSearchBar { @@ -282,12 +285,12 @@ impl BufferSearchBar { .with_style(style.container) .boxed() }) - .on_click(move |_, _, cx| cx.dispatch_action(ToggleSearchOption { option })) + .on_click(move |_, _, cx| cx.dispatch_any_action(option.to_toggle_action())) .with_cursor_style(CursorStyle::PointingHand) .with_tooltip::( option as usize, format!("Toggle {}", option.label()), - Some(Box::new(ToggleSearchOption { option })), + Some(option.to_toggle_action()), tooltip_style, cx, ) diff --git a/crates/search/src/project_search.rs b/crates/search/src/project_search.rs index e2b3a90782..7be7cc3d95 100644 --- a/crates/search/src/project_search.rs +++ b/crates/search/src/project_search.rs @@ -1,13 +1,14 @@ use crate::{ active_match_index, match_index_for_direction, query_suggestion_for_editor, Direction, - SearchOption, SelectNextMatch, SelectPrevMatch, ToggleSearchOption, + SearchOption, SelectNextMatch, SelectPrevMatch, ToggleCaseSensitive, ToggleRegex, + ToggleWholeWord, }; use collections::HashMap; use editor::{Anchor, Autoscroll, Editor, MultiBuffer, SelectAll}; use gpui::{ - actions, elements::*, platform::CursorStyle, AppContext, ElementBox, Entity, ModelContext, - ModelHandle, MutableAppContext, RenderContext, Subscription, Task, View, ViewContext, - ViewHandle, WeakModelHandle, WeakViewHandle, + actions, elements::*, platform::CursorStyle, Action, AppContext, ElementBox, Entity, + ModelContext, ModelHandle, MutableAppContext, RenderContext, Subscription, Task, View, + ViewContext, ViewHandle, WeakModelHandle, WeakViewHandle, }; use menu::Confirm; use project::{search::SearchQuery, Project}; @@ -38,21 +39,23 @@ pub fn init(cx: &mut MutableAppContext) { cx.add_action(ProjectSearchBar::select_next_match); cx.add_action(ProjectSearchBar::select_prev_match); cx.add_action(ProjectSearchBar::toggle_focus); - cx.add_action( - |pane: &mut Pane, - ToggleSearchOption { option }: &ToggleSearchOption, - cx: &mut ViewContext| { - if let Some(search_bar) = pane.toolbar().read(cx).item_of_type::() { - if search_bar.update(cx, |search_bar, cx| { - search_bar.toggle_search_option(*option, cx) - }) { - return; - } - } - cx.propagate_action(); - }, - ); cx.capture_action(ProjectSearchBar::tab); + add_toggle_option_action::(SearchOption::CaseSensitive, cx); + add_toggle_option_action::(SearchOption::WholeWord, cx); + add_toggle_option_action::(SearchOption::Regex, cx); +} + +fn add_toggle_option_action(option: SearchOption, cx: &mut MutableAppContext) { + cx.add_action(move |pane: &mut Pane, _: &A, cx: &mut ViewContext| { + if let Some(search_bar) = pane.toolbar().read(cx).item_of_type::() { + if search_bar.update(cx, |search_bar, cx| { + search_bar.toggle_search_option(option, cx) + }) { + return; + } + } + cx.propagate_action(); + }); } struct ProjectSearch { @@ -731,12 +734,12 @@ impl ProjectSearchBar { .with_style(style.container) .boxed() }) - .on_click(move |_, _, cx| cx.dispatch_action(ToggleSearchOption { option })) + .on_click(move |_, _, cx| cx.dispatch_any_action(option.to_toggle_action())) .with_cursor_style(CursorStyle::PointingHand) .with_tooltip::( option as usize, format!("Toggle {}", option.label()), - Some(Box::new(ToggleSearchOption { option })), + Some(option.to_toggle_action()), tooltip_style, cx, ) diff --git a/crates/search/src/search.rs b/crates/search/src/search.rs index 048eb1ddeb..5d6014eaeb 100644 --- a/crates/search/src/search.rs +++ b/crates/search/src/search.rs @@ -1,8 +1,7 @@ pub use buffer_search::BufferSearchBar; use editor::{display_map::ToDisplayPoint, Anchor, Bias, Editor, MultiBufferSnapshot}; -use gpui::{actions, impl_actions, MutableAppContext, ViewHandle}; +use gpui::{actions, Action, MutableAppContext, ViewHandle}; pub use project_search::{ProjectSearchBar, ProjectSearchView}; -use serde::Deserialize; use std::{ cmp::{self, Ordering}, ops::Range, @@ -16,15 +15,18 @@ pub fn init(cx: &mut MutableAppContext) { project_search::init(cx); } -#[derive(Clone, PartialEq, Deserialize)] -pub struct ToggleSearchOption { - pub option: SearchOption, -} +actions!( + search, + [ + ToggleWholeWord, + ToggleCaseSensitive, + ToggleRegex, + SelectNextMatch, + SelectPrevMatch + ] +); -actions!(search, [SelectNextMatch, SelectPrevMatch]); -impl_actions!(search, [ToggleSearchOption]); - -#[derive(Clone, Copy, PartialEq, Deserialize)] +#[derive(Clone, Copy, PartialEq)] pub enum SearchOption { WholeWord, CaseSensitive, @@ -39,6 +41,14 @@ impl SearchOption { SearchOption::Regex => "Use Regular Expression", } } + + pub fn to_toggle_action(&self) -> Box { + match self { + SearchOption::WholeWord => Box::new(ToggleWholeWord), + SearchOption::CaseSensitive => Box::new(ToggleCaseSensitive), + SearchOption::Regex => Box::new(ToggleRegex), + } + } } #[derive(Clone, Copy, PartialEq, Eq)] From 88d8696414573a8b083053c1ba4d2b13bb701b6a Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Thu, 16 Jun 2022 14:37:33 +0200 Subject: [PATCH 5/6] 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 da0e904cca..87fddc8ce1 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 dcd0dbc891..de9e8af9c4 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 7be7cc3d95..bf862f0d9d 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() } From 9defbf7c76985141e8dd1067c911bd995fbf60cc Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Thu, 16 Jun 2022 14:41:55 +0200 Subject: [PATCH 6/6] Bind `CloseInactiveItems` to `alt-cmd-t` --- assets/keymaps/default.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/keymaps/default.json b/assets/keymaps/default.json index 87fddc8ce1..6b8bf4ffb2 100644 --- a/assets/keymaps/default.json +++ b/assets/keymaps/default.json @@ -15,7 +15,7 @@ "shift-cmd-}": "pane::ActivateNextItem", "cmd-w": "pane::CloseActiveItem", "cmd-shift-W": "workspace::CloseWindow", - "cmd-k alt-cmd-w": "pane::CloseInactiveItems", + "alt-cmd-t": "pane::CloseInactiveItems", "cmd-s": "workspace::Save", "cmd-shift-S": "workspace::SaveAs", "cmd-=": "zed::IncreaseBufferFontSize",