Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Move mode cycling to mode module

Piotr Osiewicz0374fdfd0627
diff --git a/crates/search/src/mode.rs b/crates/search/src/mode.rs
index aaaebc6e860..072b9ffd804 100644
--- a/crates/search/src/mode.rs
+++ b/crates/search/src/mode.rs
@@ -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,
+ }
+}
diff --git a/crates/search/src/project_search.rs b/crates/search/src/project_search.rs
index 4852e770040..97b9f7b75bf 100644
--- a/crates/search/src/project_search.rs
+++ b/crates/search/src/project_search.rs
@@ -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);
})
}