javascriptjqueryeditorace-editor

How can I make an event when theme change


When theme change, I want to make a event. not use setTheme().

var editor = ace.edit("editor");
ace.require("ace/ext/settings_menu").init(editor);
editor.session.setMode("ace/mode/java");
editor.setOptions({
    theme: "ace/theme/tomorrow_night_bright"
});

editor.on('changeTheme', function() {    -> This is not working
    console.log(editor.mode)
})

I try to changeTheme event, and I use $("#-theme").change() event but not working


Solution

  • There are themeChange and themeLoaded events on editor.renderer see https://github.com/ajaxorg/ace/blob/31bbd6ade094c1e142565837a4ee93c7931399a4/src/virtual_renderer.js#L1721

    editor.renderer.on('themeChange', function() {
        // theme setting changed
    })
    editor.renderer.on('themeLoaded', function() {
        // theme loaded and applied to editor
    })