Ace editor: How to dynamically change the theme

How can I change the theme in the Ace editor in the change event from the selected one? I can programmatically set the theme in the dom event. The code I invoke (for both events) looks below and I pass in values ​​like ("ace / theme / clouds" / "ace / theme / clouds_midnight").

setThemeValue = function(themeVal){ var editor = ace.edit("editor"); editor.setTheme(themeVal); editor.getSession().setMode("ace/mode/javascript"); }; 
+4
source share
1 answer

" setTheme " change the theme you use on the fly and you do not need to reuse ace.edit ("editor").

So, I suggest the following code:

 // Initialize your Ace Editor var editor = (function() { var aceEditor = ace.edit("editor"); // default theme aceEditor.setTheme("ace/theme/clouds"); aceEditor.getSession().setMode("ace/mode/javascript"); return aceEditor; })(); // Change theme on the fly editor.setTheme("ace/theme/clouds_midnight"); 
+11
source

Source: https://habr.com/ru/post/1433462/


All Articles