feat: off mode for filter
1 file changed, +8 -2
+8-2src/widgets/miller.rs
| @@ -112,6 +112,7 @@ pub struct MillerFilterResponse { | ||
| 112 | 112 | /// Shows a text input with placeholder. Focus with shortcut key, Escape unfocuses. |
| 113 | 113 | #[derive(Debug, Clone, Copy, PartialEq)] |
| 114 | 114 | pub enum FilterMode { |
| 115 | + Off, // no filtering | |
| 115 | 116 | Fuzzy, // chars in order anywhere |
| 116 | 117 | Contains, // case-insensitive substring |
| 117 | 118 | Exact, // case-insensitive full match |
| @@ -120,14 +121,16 @@ pub enum FilterMode { | ||
| 120 | 121 | impl FilterMode { |
| 121 | 122 | fn next(self) -> Self { |
| 122 | 123 | match self { |
| 124 | + FilterMode::Off => FilterMode::Fuzzy, | |
| 123 | 125 | FilterMode::Fuzzy => FilterMode::Contains, |
| 124 | 126 | FilterMode::Contains => FilterMode::Exact, |
| 125 | - FilterMode::Exact => FilterMode::Fuzzy, | |
| 127 | + FilterMode::Exact => FilterMode::Off, | |
| 126 | 128 | } |
| 127 | 129 | } |
| 128 | 130 | |
| 129 | 131 | fn icon(self) -> &'static str { |
| 130 | 132 | match self { |
| 133 | + FilterMode::Off => egui_phosphor::regular::PROHIBIT, | |
| 131 | 134 | FilterMode::Fuzzy => egui_phosphor::regular::WAVES, |
| 132 | 135 | FilterMode::Contains => egui_phosphor::regular::TEXTBOX, |
| 133 | 136 | FilterMode::Exact => egui_phosphor::regular::EQUALS, |
| @@ -136,6 +139,7 @@ impl FilterMode { | ||
| 136 | 139 | |
| 137 | 140 | fn color(self) -> egui::Color32 { |
| 138 | 141 | match self { |
| 142 | + FilterMode::Off => crate::theme::CatppuccinMocha::OVERLAY0, | |
| 139 | 143 | FilterMode::Fuzzy => crate::theme::CatppuccinMocha::PEACH, |
| 140 | 144 | FilterMode::Contains => crate::theme::CatppuccinMocha::BLUE, |
| 141 | 145 | FilterMode::Exact => crate::theme::CatppuccinMocha::GREEN, |
| @@ -144,6 +148,7 @@ impl FilterMode { | ||
| 144 | 148 | |
| 145 | 149 | fn tooltip(self) -> &'static str { |
| 146 | 150 | match self { |
| 151 | + FilterMode::Off => "Off (ctrl-f to cycle)", | |
| 147 | 152 | FilterMode::Fuzzy => "Fuzzy (ctrl-f to cycle)", |
| 148 | 153 | FilterMode::Contains => "Contains (ctrl-f to cycle)", |
| 149 | 154 | FilterMode::Exact => "Exact (ctrl-f to cycle)", |
| @@ -263,7 +268,7 @@ impl MillerFilter { | ||
| 263 | 268 | /// Match a label against the query using the current filter mode. |
| 264 | 269 | /// Supports `|` to OR multiple terms (e.g. "start|report" matches either). |
| 265 | 270 | pub fn matches(&self, label: &str) -> bool { |
| 266 | - if self.query.is_empty() { | |
| 271 | + if self.mode == FilterMode::Off || self.query.is_empty() { | |
| 267 | 272 | return true; |
| 268 | 273 | } |
| 269 | 274 | self.query.split('|') |
| @@ -271,6 +276,7 @@ impl MillerFilter { | ||
| 271 | 276 | let term = term.trim(); |
| 272 | 277 | if term.is_empty() { return false; } |
| 273 | 278 | match self.mode { |
| 279 | + FilterMode::Off => true, | |
| 274 | 280 | FilterMode::Fuzzy => fuzzy_matches(term, label), |
| 275 | 281 | FilterMode::Contains => label.to_lowercase().contains(&term.to_lowercase()), |
| 276 | 282 | FilterMode::Exact => label.to_lowercase() == term.to_lowercase(), |