add keymaps for activating text, regex and semantic modes

This commit is contained in:
KCaverly 2023-09-20 10:04:43 -04:00
parent 912e6e8091
commit 28ed406d54
2 changed files with 29 additions and 5 deletions

View File

@ -248,7 +248,10 @@
"context": "ProjectSearchBar",
"bindings": {
"escape": "project_search::ToggleFocus",
"alt-tab": "search::CycleMode"
"alt-tab": "search::CycleMode",
"alt-cmd-g": "search::ActivateRegexMode",
"alt-cmd-s": "search::ActivateSemanticMode",
"alt-cmd-x": "search::ActivateTextMode"
}
},
{
@ -262,7 +265,10 @@
"context": "ProjectSearchView",
"bindings": {
"escape": "project_search::ToggleFocus",
"alt-tab": "search::CycleMode"
"alt-tab": "search::CycleMode",
"alt-cmd-g": "search::ActivateRegexMode",
"alt-cmd-s": "search::ActivateSemanticMode",
"alt-cmd-x": "search::ActivateTextMode"
}
},
{
@ -275,7 +281,10 @@
"alt-cmd-c": "search::ToggleCaseSensitive",
"alt-cmd-w": "search::ToggleWholeWord",
"alt-tab": "search::CycleMode",
"alt-cmd-f": "project_search::ToggleFilters"
"alt-cmd-f": "project_search::ToggleFilters",
"alt-cmd-g": "search::ActivateRegexMode",
"alt-cmd-s": "search::ActivateSemanticMode",
"alt-cmd-x": "search::ActivateTextMode"
}
},
// Bindings from VS Code

View File

@ -2,8 +2,9 @@ use crate::{
history::SearchHistory,
mode::{SearchMode, Side},
search_bar::{render_nav_button, render_option_button_icon, render_search_mode_button},
ActivateRegexMode, ActivateSemanticMode, CycleMode, NextHistoryQuery, PreviousHistoryQuery,
SearchOptions, SelectNextMatch, SelectPrevMatch, ToggleCaseSensitive, ToggleWholeWord,
ActivateRegexMode, ActivateSemanticMode, ActivateTextMode, CycleMode, NextHistoryQuery,
PreviousHistoryQuery, SearchOptions, SelectNextMatch, SelectPrevMatch, ToggleCaseSensitive,
ToggleWholeWord,
};
use anyhow::{Context, Result};
use collections::HashMap;
@ -63,6 +64,7 @@ pub fn init(cx: &mut AppContext) {
cx.add_action(ProjectSearchBar::next_history_query);
cx.add_action(ProjectSearchBar::previous_history_query);
cx.add_action(ProjectSearchBar::activate_regex_mode);
cx.add_action(ProjectSearchBar::activate_text_mode);
// This action should only be registered if the semantic index is enabled
if SemanticIndex::enabled(cx) {
@ -1341,6 +1343,19 @@ impl ProjectSearchBar {
}
}
fn activate_text_mode(pane: &mut Pane, _: &ActivateTextMode, cx: &mut ViewContext<Pane>) {
if let Some(search_view) = pane
.active_item()
.and_then(|item| item.downcast::<ProjectSearchView>())
{
search_view.update(cx, |view, cx| {
view.activate_search_mode(SearchMode::Text, cx)
});
} else {
cx.propagate_action();
}
}
fn activate_regex_mode(pane: &mut Pane, _: &ActivateRegexMode, cx: &mut ViewContext<Pane>) {
if let Some(search_view) = pane
.active_item()