diff --git a/assets/keymaps/default.json b/assets/keymaps/default.json index 97dad7a831..3b894de723 100644 --- a/assets/keymaps/default.json +++ b/assets/keymaps/default.json @@ -224,7 +224,8 @@ "tab": "buffer_search::FocusEditor", "enter": "search::SelectNextMatch", "shift-enter": "search::SelectPrevMatch", - "alt-enter": "search::SelectAllMatches" + "alt-enter": "search::SelectAllMatches", + "alt-tab": "search::CycleMode" } }, { @@ -265,6 +266,7 @@ "alt-cmd-c": "search::ToggleCaseSensitive", "alt-cmd-w": "search::ToggleWholeWord", "alt-cmd-r": "search::ActivateRegexMode", + "alt-tab": "search::CycleMode", "alt-cmd-f": "project_search::ToggleFilters" } }, diff --git a/crates/search/src/buffer_search.rs b/crates/search/src/buffer_search.rs index cffbe91fbe..ec2f1c6855 100644 --- a/crates/search/src/buffer_search.rs +++ b/crates/search/src/buffer_search.rs @@ -1,9 +1,9 @@ use crate::{ history::SearchHistory, - mode::SearchMode, + mode::{next_mode, SearchMode}, search_bar::{render_nav_button, render_search_mode_button}, - NextHistoryQuery, PreviousHistoryQuery, SearchOptions, SelectAllMatches, SelectNextMatch, - SelectPrevMatch, ToggleCaseSensitive, ToggleWholeWord, + CycleMode, NextHistoryQuery, PreviousHistoryQuery, SearchOptions, SelectAllMatches, + SelectNextMatch, SelectPrevMatch, ToggleCaseSensitive, ToggleWholeWord, }; use collections::HashMap; use editor::Editor; @@ -51,6 +51,8 @@ pub fn init(cx: &mut AppContext) { cx.add_action(BufferSearchBar::handle_editor_cancel); cx.add_action(BufferSearchBar::next_history_query); cx.add_action(BufferSearchBar::previous_history_query); + cx.add_action(BufferSearchBar::cycle_mode); + cx.add_action(BufferSearchBar::cycle_mode_on_pane); add_toggle_option_action::(SearchOptions::CASE_SENSITIVE, cx); add_toggle_option_action::(SearchOptions::WHOLE_WORD, cx); } @@ -804,6 +806,26 @@ impl BufferSearchBar { let _ = self.search(&new_query, Some(self.search_options), cx); } } + fn cycle_mode(&mut self, _: &CycleMode, cx: &mut ViewContext) { + self.activate_search_mode(next_mode(&self.current_mode, false), cx); + } + fn cycle_mode_on_pane(pane: &mut Pane, action: &CycleMode, cx: &mut ViewContext) { + let mut should_propagate = true; + if let Some(search_bar) = pane.toolbar().read(cx).item_of_type::() { + search_bar.update(cx, |bar, cx| { + if bar.show(cx) { + should_propagate = false; + bar.cycle_mode(action, cx); + false + } else { + true + } + }); + } + if should_propagate { + cx.propagate_action(); + } + } } #[cfg(test)]