2023-12-08 11:37:20 +00:00
|
|
|
use gpui::{Action, SharedString};
|
|
|
|
|
|
|
|
use crate::{ActivateRegexMode, ActivateSemanticMode, ActivateTextMode};
|
|
|
|
|
2023-11-13 19:38:37 +00:00
|
|
|
// TODO: Update the default search mode to get from config
|
|
|
|
#[derive(Copy, Clone, Debug, Default, PartialEq)]
|
|
|
|
pub enum SearchMode {
|
|
|
|
#[default]
|
|
|
|
Text,
|
|
|
|
Semantic,
|
|
|
|
Regex,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl SearchMode {
|
2023-11-17 16:22:52 +00:00
|
|
|
pub(crate) fn label(&self) -> &'static str {
|
2023-11-13 19:38:37 +00:00
|
|
|
match self {
|
2023-11-17 16:22:52 +00:00
|
|
|
SearchMode::Text => "Text",
|
|
|
|
SearchMode::Semantic => "Semantic",
|
|
|
|
SearchMode::Regex => "Regex",
|
2023-11-13 19:38:37 +00:00
|
|
|
}
|
|
|
|
}
|
2023-12-08 11:37:20 +00:00
|
|
|
pub(crate) fn tooltip(&self) -> SharedString {
|
|
|
|
format!("Activate {} Mode", self.label()).into()
|
|
|
|
}
|
|
|
|
pub(crate) fn action(&self) -> Box<dyn Action> {
|
|
|
|
match self {
|
|
|
|
SearchMode::Text => ActivateTextMode.boxed_clone(),
|
|
|
|
SearchMode::Semantic => ActivateSemanticMode.boxed_clone(),
|
|
|
|
SearchMode::Regex => ActivateRegexMode.boxed_clone(),
|
|
|
|
}
|
|
|
|
}
|
2023-11-13 19:38:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn next_mode(mode: &SearchMode, semantic_enabled: bool) -> SearchMode {
|
|
|
|
match mode {
|
|
|
|
SearchMode::Text => SearchMode::Regex,
|
|
|
|
SearchMode::Regex => {
|
|
|
|
if semantic_enabled {
|
|
|
|
SearchMode::Semantic
|
|
|
|
} else {
|
|
|
|
SearchMode::Text
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SearchMode::Semantic => SearchMode::Text,
|
|
|
|
}
|
|
|
|
}
|