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
13#[derive(Copy, Clone, Debug, PartialEq)]
14pub(crate) enum Side {
15    Left,
16    Right,
17}
18
19impl SearchMode {
20    pub(crate) fn label(&self) -> &'static str {
21        match self {
22            SearchMode::Text => "Text",
23            SearchMode::Semantic => "Semantic",
24            SearchMode::Regex => "Regex",
25        }
26    }
27
28    pub(crate) fn region_id(&self) -> usize {
29        match self {
30            SearchMode::Text => 3,
31            SearchMode::Semantic => 4,
32            SearchMode::Regex => 5,
33        }
34    }
35
36    pub(crate) fn tooltip_text(&self) -> &'static str {
37        match self {
38            SearchMode::Text => "Activate Text Search",
39            SearchMode::Semantic => "Activate Semantic Search",
40            SearchMode::Regex => "Activate Regex Search",
41        }
42    }
43
44    pub(crate) fn activate_action(&self) -> Box<dyn Action> {
45        match self {
46            SearchMode::Text => Box::new(ActivateTextMode),
47            SearchMode::Semantic => Box::new(ActivateSemanticMode),
48            SearchMode::Regex => Box::new(ActivateRegexMode),
49        }
50    }
51}
52
53pub(crate) fn next_mode(mode: &SearchMode, semantic_enabled: bool) -> SearchMode {
54    match mode {
55        SearchMode::Text => SearchMode::Regex,
56        SearchMode::Regex => {
57            if semantic_enabled {
58                SearchMode::Semantic
59            } else {
60                SearchMode::Text
61            }
62        }
63        SearchMode::Semantic => SearchMode::Text,
64    }
65}