Merge pull request #144 from 0HyperCube/light-syntax-highlighter

Add light syntax highligher to libcosmic example
This commit is contained in:
Jeremy Soller 2023-06-25 07:07:49 -06:00 committed by GitHub
commit 2c8d7c0bb9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 0 deletions

View file

@ -268,6 +268,13 @@ impl Application for Window {
));
let mut editor = self.editor.lock().unwrap();
// Update the syntax color theme
match theme {
"Light" => editor.update_theme("base16-ocean.light"),
"Dark" | _ => editor.update_theme("base16-eighties.dark"),
};
update_attrs(&mut *editor, self.attrs);
}
}

View file

@ -60,6 +60,19 @@ impl<'a> SyntaxEditor<'a> {
})
}
/// Modifies the theme of the [`SyntaxEditor`], returning false if the theme is missing
pub fn update_theme(&mut self, theme_name: &str) -> bool {
if let Some(theme) = self.syntax_system.theme_set.themes.get(theme_name) {
self.theme = theme;
self.highlighter = Highlighter::new(theme);
self.syntax_cache.clear();
true
} else {
false
}
}
/// Load text from a file, and also set syntax to the best option
///
/// ## Errors