如何在主题更改时创建一个事件

huangapple go评论75阅读模式
英文:

How can I make an event when theme change

问题

当主题更改时,我想触发一个事件,而不是使用 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() {    // 这部分不起作用
	console.log(editor.mode)
})

我尝试使用 changeTheme 事件,并使用 $("#-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

答案1

得分: 1

editor.renderer 上有 themeChangethemeLoaded 事件,请参见 https://github.com/ajaxorg/ace/blob/31bbd6ade094c1e142565837a4ee93c7931399a4/src/virtual_renderer.js#L1721

editor.renderer.on('themeChange', function() {
    // 主题设置已更改
})
editor.renderer.on('themeLoaded', function() {
    // 主题已加载并应用到编辑器
})
英文:

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
})

huangapple
  • 本文由 发表于 2023年7月13日 13:36:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/76676222.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定