diff options
author | Gokul Soumya | 2022-03-04 00:35:21 +0000 |
---|---|---|
committer | GitHub | 2022-03-04 00:35:21 +0000 |
commit | 74a9dd51ffb7cd3c14d4c7b5502e4febad24caa0 (patch) | |
tree | 57c03851f647a3fe5e1d613fe46bed835c77a7ec /helix-view/src | |
parent | c484b089230b541e63edc34a041e2842f2942e23 (diff) |
Fallback to broader scope if theme scope not found (#1714)
Diffstat (limited to 'helix-view/src')
-rw-r--r-- | helix-view/src/theme.rs | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/helix-view/src/theme.rs b/helix-view/src/theme.rs index 00c1bbbd..3f45aac6 100644 --- a/helix-view/src/theme.rs +++ b/helix-view/src/theme.rs @@ -153,8 +153,12 @@ impl Theme { self.try_get(scope).unwrap_or_default() } + /// Get the style of a scope, falling back to dot separated broader + /// scopes. For example if `ui.text.focus` is not defined in the theme, + /// `ui.text` is tried and then `ui` is tried. pub fn try_get(&self, scope: &str) -> Option<Style> { - self.styles.get(scope).copied() + std::iter::successors(Some(scope), |s| Some(s.rsplit_once('.')?.0)) + .find_map(|s| self.styles.get(s).copied()) } #[inline] |