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