1use gpui::{Action, SharedString};
2
3use crate::{ActivateRegexMode, ActivateSemanticMode, ActivateTextMode};
4
5// TODO: Update the default search mode to get from config
6#[derive(Copy, Clone, Debug, Default, PartialEq)]
7pub enum SearchMode {
8 #[default]
9 Text,
10 Semantic,
11 Regex,
12}
13
14impl SearchMode {
15 pub(crate) fn label(&self) -> &'static str {
16 match self {
17 SearchMode::Text => "Text",
18 SearchMode::Semantic => "Semantic",
19 SearchMode::Regex => "Regex",
20 }
21 }
22 pub(crate) fn tooltip(&self) -> SharedString {
23 format!("Activate {} Mode", self.label()).into()
24 }
25 pub(crate) fn action(&self) -> Box<dyn Action> {
26 match self {
27 SearchMode::Text => ActivateTextMode.boxed_clone(),
28 SearchMode::Semantic => ActivateSemanticMode.boxed_clone(),
29 SearchMode::Regex => ActivateRegexMode.boxed_clone(),
30 }
31 }
32}
33
34pub(crate) fn next_mode(mode: &SearchMode, semantic_enabled: bool) -> SearchMode {
35 match mode {
36 SearchMode::Text => SearchMode::Regex,
37 SearchMode::Regex => {
38 if semantic_enabled {
39 SearchMode::Semantic
40 } else {
41 SearchMode::Text
42 }
43 }
44 SearchMode::Semantic => SearchMode::Text,
45 }
46}