mode.rs

 1use gpui::{Action, SharedString};
 2
 3use crate::{ActivateRegexMode, 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    Regex,
11}
12
13impl SearchMode {
14    pub(crate) fn label(&self) -> &'static str {
15        match self {
16            SearchMode::Text => "Text",
17            SearchMode::Regex => "Regex",
18        }
19    }
20    pub(crate) fn tooltip(&self) -> SharedString {
21        format!("Activate {} Mode", self.label()).into()
22    }
23    pub(crate) fn action(&self) -> Box<dyn Action> {
24        match self {
25            SearchMode::Text => ActivateTextMode.boxed_clone(),
26            SearchMode::Regex => ActivateRegexMode.boxed_clone(),
27        }
28    }
29}
30
31pub(crate) fn next_mode(mode: &SearchMode) -> SearchMode {
32    match mode {
33        SearchMode::Text => SearchMode::Regex,
34        SearchMode::Regex => SearchMode::Text,
35    }
36}