Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the theme in an Ace editor?

Tags:

ace-editor

I've been trying to add syntax highlighting to my web app and found ace. However, after working at the solution provided in the documentation, I am still unable to change the editor theme. Does anyone know how to go about this?

So far I've just initialized the element with the following code

var editor = ace.edit("editor");
editor.getSession().setUseWrapMode(true);
editor.setHighlightActiveLine(true);
editor.setShowPrintMargin(false);
editor.setTheme('ace-builds-master/theme/tomorrow_night.css');
editor.getSession().setMode("ace/mode/javascript");
like image 670
mattd Avatar asked Dec 06 '25 17:12

mattd


1 Answers

In the build mode argument to setTheme() is not a path but an id of the theme so you need to call .setTheme('ace/theme/tomorrow_night') instead

Note that you also can set all the options in one call using

editor.setOptions({
    useWrapMode: true,
    highlightActiveLine: true,
    showPrintMargin: false,
    theme: 'ace/theme/tomorrow_night',
    mode: 'ace/mode/javascript'
})

or in newer version of ace pass object with options to ace.edit

var editor = ace.edit("editor"{
    useWrapMode: true,
    ...
})
like image 142
a user Avatar answered Dec 12 '25 02:12

a user