File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed
examples/editor-libcosmic/src Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -268,6 +268,13 @@ impl Application for Window {
268
268
) ) ;
269
269
270
270
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
+
271
278
update_attrs ( & mut * editor, self . attrs ) ;
272
279
}
273
280
}
Original file line number Diff line number Diff line change @@ -60,6 +60,19 @@ impl<'a> SyntaxEditor<'a> {
60
60
} )
61
61
}
62
62
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
+
63
76
/// Load text from a file, and also set syntax to the best option
64
77
///
65
78
/// ## Errors
You can’t perform that action at this time.
0 commit comments