Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
theme_selector: Mark the active theme with a check icon (#58404)
Matei Oprea3f0d233058b4
diff --git a/crates/theme_selector/src/icon_theme_selector.rs b/crates/theme_selector/src/icon_theme_selector.rsindex 725881f8cc1..9abcd9a40cf 100644--- a/crates/theme_selector/src/icon_theme_selector.rs+++ b/crates/theme_selector/src/icon_theme_selector.rs@@ -299,6 +299,7 @@ impl PickerDelegate for IconThemeSelectorDelegate {_cx: &mut Context<Picker<Self>>,) -> Option<Self::ListItem> {let theme_match = &self.matches.get(ix)?;+ let is_original_theme = theme_match.string.as_str() == self.original_theme.0.as_ref();Some(ListItem::new(ix)@@ -308,7 +309,10 @@ impl PickerDelegate for IconThemeSelectorDelegate {.child(HighlightedLabel::new(theme_match.string.clone(),theme_match.positions.clone(),- )),+ ))+ .when(is_original_theme, |this| {+ this.end_slot(Icon::new(IconName::Check).color(Color::Muted))+ }),)}diff --git a/crates/theme_selector/src/theme_selector.rs b/crates/theme_selector/src/theme_selector.rsindex c60218003df..5fc3217f63f 100644--- a/crates/theme_selector/src/theme_selector.rs+++ b/crates/theme_selector/src/theme_selector.rs@@ -134,6 +134,14 @@ struct ThemeSelectorDelegate {original_theme_settings: ThemeSettings,/// The current system appearance.original_system_appearance: Appearance,+ /// The id of the original theme in the list of themes.+ /// Using `Option<usize>` instead of `usize` because it's possible that the+ /// original theme is not present in the list of themes when it is first+ /// built, depending on the provided `themes_filter`. For example, when a+ /// theme is installed, the `themes_filter` is set to the new theme names+ /// and, if we used `unwrap_or(0)` as a fallback, the first theme in the+ /// list would be shown as "active".+ original_theme_id: Option<usize>,/// The currently selected new theme.new_theme: Arc<Theme>,selection_completed: bool,@@ -174,10 +182,15 @@ impl ThemeSelectorDelegate {.then(a.name.cmp(&b.name))});+ let original_theme_id = themes+ .iter()+ .position(|meta| meta.name == original_theme.name);+let matches: Vec<StringMatch> = themes.iter()- .map(|meta| StringMatch {- candidate_id: 0,+ .enumerate()+ .map(|(id, meta)| StringMatch {+ candidate_id: id,score: 0.0,positions: Default::default(),string: meta.name.to_string(),@@ -196,6 +209,7 @@ impl ThemeSelectorDelegate {matches,original_theme_settings,original_system_appearance,+ original_theme_id,new_theme: original_theme, // Start with the original theme.selected_index,selection_completed: false,@@ -204,6 +218,13 @@ impl ThemeSelectorDelegate {}}+ fn is_original_theme(&self, index: usize) -> bool {+ self.matches+ .get(index)+ .zip(self.original_theme_id)+ .is_some_and(|(mat, original_theme_id)| mat.candidate_id == original_theme_id)+ }+fn show_selected_theme(&mut self,cx: &mut Context<Picker<ThemeSelectorDelegate>>,@@ -487,6 +508,7 @@ impl PickerDelegate for ThemeSelectorDelegate {_cx: &mut Context<Picker<Self>>,) -> Option<Self::ListItem> {let theme_match = &self.matches.get(ix)?;+ let is_original_theme = self.is_original_theme(ix);Some(ListItem::new(ix)@@ -496,7 +518,10 @@ impl PickerDelegate for ThemeSelectorDelegate {.child(HighlightedLabel::new(theme_match.string.clone(),theme_match.positions.clone(),- )),+ ))+ .when(is_original_theme, |this| {+ this.end_slot(Icon::new(IconName::Check).color(Color::Muted))+ }),)}