Move mode cycling to mode module

This commit is contained in:
Piotr Osiewicz
2023-08-08 15:20:34 +02:00
parent 7547fa2679
commit 0374fdfd06
2 changed files with 16 additions and 12 deletions
+14
View File
@@ -71,3 +71,17 @@ impl SearchMode {
}
}
}
pub(crate) fn next_mode(mode: &SearchMode, semantic_enabled: bool) -> SearchMode {
let next_text_state = if semantic_enabled {
SearchMode::Semantic
} else {
SearchMode::Regex
};
match mode {
SearchMode::Text => next_text_state,
SearchMode::Semantic => SearchMode::Regex,
SearchMode::Regex => SearchMode::Text,
}
}
+2 -12
View File
@@ -1155,18 +1155,8 @@ impl ProjectSearchBar {
.and_then(|item| item.downcast::<ProjectSearchView>())
{
search_view.update(cx, |this, cx| {
let mode = &this.current_mode;
let next_text_state = if SemanticIndex::enabled(cx) {
SearchMode::Semantic
} else {
SearchMode::Regex
};
let new_mode = match mode {
&SearchMode::Text => next_text_state,
&SearchMode::Semantic => SearchMode::Regex,
SearchMode::Regex => SearchMode::Text,
};
let new_mode =
crate::mode::next_mode(&this.current_mode, SemanticIndex::enabled(cx));
this.activate_search_mode(new_mode, cx);
})
}