From e2fc17d486c21eff57004dad502c20b05ff36b8b Mon Sep 17 00:00:00 2001 From: "gcp-cherry-pick-bot[bot]" <98988430+gcp-cherry-pick-bot[bot]@users.noreply.github.com> Date: Wed, 19 Mar 2025 15:11:59 -0400 Subject: [PATCH] theme: Add fallback colors for `version_control.` properties (cherry-pick #27104) (#27106) Cherry-picked theme: Add fallback colors for `version_control.` properties (#27104) This PR adds fallback colors for the `version_control.` theme properties. This fixes the colors when themes do not provide the properties. Related to https://github.com/zed-industries/zed/pull/26951. Release Notes: - Added fallback colors for the `version_control.` theme properties. Co-authored-by: Marshall Bowers --- crates/theme/src/schema.rs | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/crates/theme/src/schema.rs b/crates/theme/src/schema.rs index d68a66e2a3e98c0d05a5a6a62a00b45aa4ca4d32..3d57a63bf000a97d415bfe66e305689abba6f06d 100644 --- a/crates/theme/src/schema.rs +++ b/crates/theme/src/schema.rs @@ -98,7 +98,8 @@ impl ThemeStyleContent { /// Returns a [`ThemeColorsRefinement`] based on the colors in the [`ThemeContent`]. #[inline(always)] pub fn theme_colors_refinement(&self) -> ThemeColorsRefinement { - self.colors.theme_colors_refinement() + self.colors + .theme_colors_refinement(&self.status_colors_refinement()) } /// Returns a [`StatusColorsRefinement`] based on the colors in the [`ThemeContent`]. @@ -589,7 +590,10 @@ pub struct ThemeColorsContent { impl ThemeColorsContent { /// Returns a [`ThemeColorsRefinement`] based on the colors in the [`ThemeColorsContent`]. - pub fn theme_colors_refinement(&self) -> ThemeColorsRefinement { + pub fn theme_colors_refinement( + &self, + status_colors: &StatusColorsRefinement, + ) -> ThemeColorsRefinement { let border = self .border .as_ref() @@ -1000,27 +1004,39 @@ impl ThemeColorsContent { version_control_added: self .version_control_added .as_ref() - .and_then(|color| try_parse_color(color).ok()), + .and_then(|color| try_parse_color(color).ok()) + // Fall back to `created`, for backwards compatibility. + .or(status_colors.created), version_control_deleted: self .version_control_deleted .as_ref() - .and_then(|color| try_parse_color(color).ok()), + .and_then(|color| try_parse_color(color).ok()) + // Fall back to `deleted`, for backwards compatibility. + .or(status_colors.deleted), version_control_modified: self .version_control_modified .as_ref() - .and_then(|color| try_parse_color(color).ok()), + .and_then(|color| try_parse_color(color).ok()) + // Fall back to `modified`, for backwards compatibility. + .or(status_colors.modified), version_control_renamed: self .version_control_renamed .as_ref() - .and_then(|color| try_parse_color(color).ok()), + .and_then(|color| try_parse_color(color).ok()) + // Fall back to `modified`, for backwards compatibility. + .or(status_colors.modified), version_control_conflict: self .version_control_conflict .as_ref() - .and_then(|color| try_parse_color(color).ok()), + .and_then(|color| try_parse_color(color).ok()) + // Fall back to `ignored`, for backwards compatibility. + .or(status_colors.ignored), version_control_ignored: self .version_control_ignored .as_ref() - .and_then(|color| try_parse_color(color).ok()), + .and_then(|color| try_parse_color(color).ok()) + // Fall back to `conflict`, for backwards compatibility. + .or(status_colors.ignored), } } }