Skip to content

Commit 2c8d7c0

Browse files
authored
Merge pull request #144 from 0HyperCube/light-syntax-highlighter
Add light syntax highligher to libcosmic example
2 parents e8b10fd + bc1a327 commit 2c8d7c0

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

examples/editor-libcosmic/src/main.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,13 @@ impl Application for Window {
268268
));
269269

270270
let mut editor = self.editor.lock().unwrap();
271+
272+
// Update the syntax color theme
273+
match theme {
274+
"Light" => editor.update_theme("base16-ocean.light"),
275+
"Dark" | _ => editor.update_theme("base16-eighties.dark"),
276+
};
277+
271278
update_attrs(&mut *editor, self.attrs);
272279
}
273280
}

src/edit/syntect.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,19 @@ impl<'a> SyntaxEditor<'a> {
6060
})
6161
}
6262

63+
/// Modifies the theme of the [`SyntaxEditor`], returning false if the theme is missing
64+
pub fn update_theme(&mut self, theme_name: &str) -> bool {
65+
if let Some(theme) = self.syntax_system.theme_set.themes.get(theme_name) {
66+
self.theme = theme;
67+
self.highlighter = Highlighter::new(theme);
68+
self.syntax_cache.clear();
69+
70+
true
71+
} else {
72+
false
73+
}
74+
}
75+
6376
/// Load text from a file, and also set syntax to the best option
6477
///
6578
/// ## Errors

0 commit comments

Comments
 (0)