mode.rs

 1use gpui::Action;
 2
 3use crate::{ActivateRegexMode, ActivateSemanticMode, ActivateTextMode};
 4// TODO: Update the default search mode to get from config
 5#[derive(Copy, Clone, Debug, Default, PartialEq)]
 6pub enum SearchMode {
 7    #[default]
 8    Text,
 9    Semantic,
10    Regex,
11}
12
13impl SearchMode {
14    pub(crate) fn label(&self) -> &'static str {
15        match self {
16            SearchMode::Text => "Text",
17            SearchMode::Semantic => "Semantic",
18            SearchMode::Regex => "Regex",
19        }
20    }
21
22    pub(crate) fn region_id(&self) -> usize {
23        match self {
24            SearchMode::Text => 3,
25            SearchMode::Semantic => 4,
26            SearchMode::Regex => 5,
27        }
28    }
29
30    pub(crate) fn tooltip_text(&self) -> &'static str {
31        match self {
32            SearchMode::Text => "Activate Text Search",
33            SearchMode::Semantic => "Activate Semantic Search",
34            SearchMode::Regex => "Activate Regex Search",
35        }
36    }
37
38    pub(crate) fn activate_action(&self) -> Box<dyn Action> {
39        match self {
40            SearchMode::Text => Box::new(ActivateTextMode),
41            SearchMode::Semantic => Box::new(ActivateSemanticMode),
42            SearchMode::Regex => Box::new(ActivateRegexMode),
43        }
44    }
45}
46
47pub(crate) fn next_mode(mode: &SearchMode, semantic_enabled: bool) -> SearchMode {
48    match mode {
49        SearchMode::Text => SearchMode::Regex,
50        SearchMode::Regex => {
51            if semantic_enabled {
52                SearchMode::Semantic
53            } else {
54                SearchMode::Text
55            }
56        }
57        SearchMode::Semantic => SearchMode::Text,
58    }
59}