From 0bc75d5ef50a050c2cd87e424a06314f0d2e0496 Mon Sep 17 00:00:00 2001 From: Ridan Vandenbergh Date: Sat, 21 Jun 2025 14:11:45 +0200 Subject: [PATCH] Fix issue where `hicolor` may not end up last in chain --- src/search.rs | 22 +++++++++++++--------- src/theme.rs | 17 ++++++++--------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/search.rs b/src/search.rs index 38dd19f..7828215 100644 --- a/src/search.rs +++ b/src/search.rs @@ -259,11 +259,16 @@ impl IconLocations { pub fn icons(self) -> Icons { let themes = self.resolve(); - - let standalone_icons = self.standalone_icons + + let standalone_icons = self + .standalone_icons .into_iter() .map(|file| { - let key = file.path.file_stem().map(|s| s.to_string_lossy().to_string()).unwrap_or(String::new()); + let key = file + .path + .file_stem() + .map(|s| s.to_string_lossy().to_string()) + .unwrap_or(String::new()); (key, file) }) .collect(); @@ -388,18 +393,17 @@ impl IconLocations { continue; }; - if !chain.contains(&parent_idx) { - chain.push(parent_idx); - } + // add this parent, removing any previous occurrences + chain.retain(|idx| *idx != parent_idx); + chain.push(parent_idx); } } // From the spec: "If no theme is specified, implementations are required to add the // "hicolor" theme to the inheritance tree." if let Some(hicolor_idx) = hicolor_idx { - if !chain.contains(&hicolor_idx) { - chain.push(hicolor_idx); - } + chain.retain(|idx| *idx != hicolor_idx); + chain.push(hicolor_idx); } theme_chains.push(chain); diff --git a/src/theme.rs b/src/theme.rs index 9451f24..cb47ad6 100644 --- a/src/theme.rs +++ b/src/theme.rs @@ -51,13 +51,13 @@ impl Icons { /// - If the icon is not found in any of the themes, the standalone icon list is checked. /// /// # Icon matching - /// + /// /// This function will return an icon matching the specified size and scale exactly if it exists. /// Otherwise, an icon with the smallest "distance" (in icon size) is returned. - /// + /// /// This will only return `None` if no icon by the specified name exists in the specified theme /// and its parents, and no standalone icon by the same name exists either. - /// + /// pub fn find_icon( &self, icon_name: &str, @@ -68,7 +68,7 @@ impl Icons { if icon_name.is_empty() { return None; } - + let theme = self.theme(theme).or_else(|| self.theme("hicolor"))?; theme .find_icon(icon_name, size, scale) @@ -76,14 +76,13 @@ impl Icons { } /// Look up a standalone icon by name. - /// + /// /// "Standalone" icons are icons that live outside icon themes, residing at the root in the /// search directories instead. - /// - /// These icons do not have any size or scalability information attached to them. + /// + /// These icons do not have any size or scalability information attached to them. pub fn find_standalone_icon(&self, icon_name: &str) -> Option { - self.standalone_icons.get(icon_name) - .cloned() + self.standalone_icons.get(icon_name).cloned() } }