Add cycle mode command for buffer search

This commit is contained in:
Piotr Osiewicz 2023-08-09 18:02:21 +02:00
parent 17d505bb7b
commit c58cf396d3
2 changed files with 28 additions and 4 deletions

View file

@ -224,7 +224,8 @@
"tab": "buffer_search::FocusEditor", "tab": "buffer_search::FocusEditor",
"enter": "search::SelectNextMatch", "enter": "search::SelectNextMatch",
"shift-enter": "search::SelectPrevMatch", "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-c": "search::ToggleCaseSensitive",
"alt-cmd-w": "search::ToggleWholeWord", "alt-cmd-w": "search::ToggleWholeWord",
"alt-cmd-r": "search::ActivateRegexMode", "alt-cmd-r": "search::ActivateRegexMode",
"alt-tab": "search::CycleMode",
"alt-cmd-f": "project_search::ToggleFilters" "alt-cmd-f": "project_search::ToggleFilters"
} }
}, },

View file

@ -1,9 +1,9 @@
use crate::{ use crate::{
history::SearchHistory, history::SearchHistory,
mode::SearchMode, mode::{next_mode, SearchMode},
search_bar::{render_nav_button, render_search_mode_button}, search_bar::{render_nav_button, render_search_mode_button},
NextHistoryQuery, PreviousHistoryQuery, SearchOptions, SelectAllMatches, SelectNextMatch, CycleMode, NextHistoryQuery, PreviousHistoryQuery, SearchOptions, SelectAllMatches,
SelectPrevMatch, ToggleCaseSensitive, ToggleWholeWord, SelectNextMatch, SelectPrevMatch, ToggleCaseSensitive, ToggleWholeWord,
}; };
use collections::HashMap; use collections::HashMap;
use editor::Editor; use editor::Editor;
@ -51,6 +51,8 @@ pub fn init(cx: &mut AppContext) {
cx.add_action(BufferSearchBar::handle_editor_cancel); cx.add_action(BufferSearchBar::handle_editor_cancel);
cx.add_action(BufferSearchBar::next_history_query); cx.add_action(BufferSearchBar::next_history_query);
cx.add_action(BufferSearchBar::previous_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::<ToggleCaseSensitive>(SearchOptions::CASE_SENSITIVE, cx); add_toggle_option_action::<ToggleCaseSensitive>(SearchOptions::CASE_SENSITIVE, cx);
add_toggle_option_action::<ToggleWholeWord>(SearchOptions::WHOLE_WORD, cx); add_toggle_option_action::<ToggleWholeWord>(SearchOptions::WHOLE_WORD, cx);
} }
@ -804,6 +806,26 @@ impl BufferSearchBar {
let _ = self.search(&new_query, Some(self.search_options), cx); let _ = self.search(&new_query, Some(self.search_options), cx);
} }
} }
fn cycle_mode(&mut self, _: &CycleMode, cx: &mut ViewContext<Self>) {
self.activate_search_mode(next_mode(&self.current_mode, false), cx);
}
fn cycle_mode_on_pane(pane: &mut Pane, action: &CycleMode, cx: &mut ViewContext<Pane>) {
let mut should_propagate = true;
if let Some(search_bar) = pane.toolbar().read(cx).item_of_type::<BufferSearchBar>() {
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)] #[cfg(test)]