From 1301e56ad4a792ab2151e8f44b333f2af6a31d3f Mon Sep 17 00:00:00 2001 From: Christoph Schmidler Date: Thu, 14 Jul 2022 17:22:45 +0200 Subject: [PATCH] Allow naming custom theme same as inherited one --- helix-view/src/theme.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/helix-view/src/theme.rs b/helix-view/src/theme.rs index 3314e036c856c..6774eb582738f 100644 --- a/helix-view/src/theme.rs +++ b/helix-view/src/theme.rs @@ -46,11 +46,12 @@ impl Loader { return Ok(self.base16_default()); } - let mut raw_theme: RawTheme = self.load_raw(name)?; + let path = self.path(name, false); + let mut raw_theme: RawTheme = self.load_raw(path)?; if let Some(parent_theme_name) = &raw_theme.inherits_from { - //let parent_theme_name = "bogster"; - let parent_raw_theme = self.load_raw(parent_theme_name)?; + let path = self.path(parent_theme_name, parent_theme_name == name); + let parent_raw_theme = self.load_raw(path)?; raw_theme.inherit(parent_raw_theme); } @@ -74,19 +75,18 @@ impl Loader { } // Loads the raw theme data first from the user_dir then in default_dir - fn load_raw(&self, name: &str) -> Result { - let path = self.path(name); + fn load_raw(&self, path: PathBuf) -> Result { let data = std::fs::read(&path)?; toml::from_slice(data.as_slice()).context("Faled to deserialize theme") } // Returns the path to the theme name - fn path(&self, name: &str) -> PathBuf { + fn path(&self, name: &str, only_default_dir: bool) -> PathBuf { let filename = format!("{}.toml", name); let user_path = self.user_dir.join(&filename); - if user_path.exists() { + if !only_default_dir && user_path.exists() { user_path } else { self.default_dir.join(filename)