Move mode cycling to mode module

Piotr Osiewicz created

Change summary

crates/search/src/mode.rs           | 14 ++++++++++++++
crates/search/src/project_search.rs | 14 ++------------
2 files changed, 16 insertions(+), 12 deletions(-)

Detailed changes

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,
+    }
+}

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);
             })
         }