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    pub(crate) fn border_left(&self) -> bool {
53        match self {
54            SearchMode::Text => false,
55            _ => true,
56        }
57    }
58
59    pub(crate) fn border_right(&self) -> bool {
60        match self {
61            SearchMode::Regex => false,
62            _ => true,
63        }
64    }
65
66    pub(crate) fn button_side(&self) -> Option<Side> {
67        match self {
68            SearchMode::Text => Some(Side::Left),
69            SearchMode::Semantic => None,
70            SearchMode::Regex => Some(Side::Right),
71        }
72    }
73}
74
75pub(crate) fn next_mode(mode: &SearchMode, semantic_enabled: bool) -> SearchMode {
76    let next_text_state = if semantic_enabled {
77        SearchMode::Semantic
78    } else {
79        SearchMode::Regex
80    };
81
82    match mode {
83        SearchMode::Text => next_text_state,
84        SearchMode::Semantic => SearchMode::Regex,
85        SearchMode::Regex => SearchMode::Text,
86    }
87}