From da992374b3a702e1675902325c6fc0870fbbd23a Mon Sep 17 00:00:00 2001 From: Finn Evers Date: Mon, 5 Jan 2026 12:20:25 +0100 Subject: [PATCH] settings_ui: Fix theme not being configurable in certain scenarios (#46069) Closes https://github.com/zed-industries/zed/issues/44091 The issue here was that we were missing a proper default for `ThemeSelection`. This is a disadvantage of not having the defaults in code but actually in the `default.json`, so this here basically copies the default from the `default.json` into code for the settings UI to work properly. Release Notes: - Fixed an issue where the theme was not configurable from the settings UI if no theme was configured prior. --- crates/settings/src/settings_content/theme.rs | 13 ++++++++++++ crates/settings_ui/src/page_data.rs | 20 +++++++++---------- crates/theme/src/settings.rs | 11 ++++------ crates/theme/src/theme.rs | 1 + 4 files changed, 27 insertions(+), 18 deletions(-) diff --git a/crates/settings/src/settings_content/theme.rs b/crates/settings/src/settings_content/theme.rs index 41bd433f28dc6d85955c56d1379aa6fb210db512..d0c2a51d62a9a064e0f9fce3e8bee05b0227c549 100644 --- a/crates/settings/src/settings_content/theme.rs +++ b/crates/settings/src/settings_content/theme.rs @@ -183,6 +183,19 @@ pub enum ThemeSelection { }, } +pub const DEFAULT_LIGHT_THEME: &'static str = "One Light"; +pub const DEFAULT_DARK_THEME: &'static str = "One Dark"; + +impl Default for ThemeSelection { + fn default() -> Self { + Self::Dynamic { + mode: ThemeAppearanceMode::default(), + light: ThemeName(DEFAULT_LIGHT_THEME.into()), + dark: ThemeName(DEFAULT_DARK_THEME.into()), + } + } +} + /// Represents the selection of an icon theme, which can be either static or dynamic. #[derive( Clone, diff --git a/crates/settings_ui/src/page_data.rs b/crates/settings_ui/src/page_data.rs index c88ff53b0535db3bb554b466fa3464720998d8c3..6fb8044e570a5f311ce8fd142f472ceb8b36ac94 100644 --- a/crates/settings_ui/src/page_data.rs +++ b/crates/settings_ui/src/page_data.rs @@ -313,9 +313,7 @@ pub(crate) fn settings_data(cx: &App) -> Vec { settings_content.theme.theme = None; return; }; - let settings_value = settings_content.theme.theme.get_or_insert_with(|| { - settings::ThemeSelection::Static(theme::ThemeName(theme::default_theme(theme::SystemAppearance::default().0).into())) - }); + let settings_value = settings_content.theme.theme.get_or_insert_default(); *settings_value = match value { settings::ThemeSelectionDiscriminants::Static => { let name = match settings_value { @@ -371,8 +369,8 @@ pub(crate) fn settings_data(cx: &App) -> Vec { }; match settings_content .theme - .theme.as_mut() { - Some(settings::ThemeSelection::Static(theme_name)) => *theme_name = value, + .theme.get_or_insert_default() { + settings::ThemeSelection::Static(theme_name) => *theme_name = value, _ => return } }, @@ -399,8 +397,8 @@ pub(crate) fn settings_data(cx: &App) -> Vec { }; match settings_content .theme - .theme.as_mut() { - Some(settings::ThemeSelection::Dynamic{ mode, ..}) => *mode = value, + .theme.get_or_insert_default() { + settings::ThemeSelection::Dynamic{ mode, ..} => *mode = value, _ => return } }, @@ -425,8 +423,8 @@ pub(crate) fn settings_data(cx: &App) -> Vec { }; match settings_content .theme - .theme.as_mut() { - Some(settings::ThemeSelection::Dynamic{ light, ..}) => *light = value, + .theme.get_or_insert_default() { + settings::ThemeSelection::Dynamic{ light, ..} => *light = value, _ => return } }, @@ -451,8 +449,8 @@ pub(crate) fn settings_data(cx: &App) -> Vec { }; match settings_content .theme - .theme.as_mut() { - Some(settings::ThemeSelection::Dynamic{ dark, ..}) => *dark = value, + .theme.get_or_insert_default() { + settings::ThemeSelection::Dynamic{ dark, ..} => *dark = value, _ => return } }, diff --git a/crates/theme/src/settings.rs b/crates/theme/src/settings.rs index d60d4882a68412eeb10a95ba5d8540f5cbc87421..1c4a9540fad4b1cc6438670f5641be88a8b4d081 100644 --- a/crates/theme/src/settings.rs +++ b/crates/theme/src/settings.rs @@ -138,14 +138,11 @@ pub struct ThemeSettings { pub unnecessary_code_fade: f32, } -pub(crate) const DEFAULT_LIGHT_THEME: &'static str = "One Light"; -pub(crate) const DEFAULT_DARK_THEME: &'static str = "One Dark"; - /// Returns the name of the default theme for the given [`Appearance`]. pub fn default_theme(appearance: Appearance) -> &'static str { match appearance { - Appearance::Light => DEFAULT_LIGHT_THEME, - Appearance::Dark => DEFAULT_DARK_THEME, + Appearance::Light => settings::DEFAULT_LIGHT_THEME, + Appearance::Dark => settings::DEFAULT_DARK_THEME, } } @@ -400,8 +397,8 @@ pub fn set_mode(content: &mut SettingsContent, mode: ThemeAppearanceMode) { } else { theme.theme = Some(settings::ThemeSelection::Dynamic { mode, - light: ThemeName(DEFAULT_LIGHT_THEME.into()), - dark: ThemeName(DEFAULT_DARK_THEME.into()), + light: ThemeName(settings::DEFAULT_LIGHT_THEME.into()), + dark: ThemeName(settings::DEFAULT_DARK_THEME.into()), }); } diff --git a/crates/theme/src/theme.rs b/crates/theme/src/theme.rs index c94e0d60bf3fa561c8d49dbaf544f47fe60e7ea9..b38af71fe32373c6a0d05a098fd4a463901840cc 100644 --- a/crates/theme/src/theme.rs +++ b/crates/theme/src/theme.rs @@ -22,6 +22,7 @@ mod styles; use std::path::Path; use std::sync::Arc; +use ::settings::DEFAULT_DARK_THEME; use ::settings::Settings; use ::settings::SettingsStore; use anyhow::Result;