ace-editor - 如何在 Ace 编辑器中更改主题?

标签 ace-editor

我一直在尝试将语法突出显示添加到我的网络应用程序并找到了 ace。但是,在使用文档中提供的解决方案后,我仍然无法更改编辑器主题。有谁知道该怎么做?

到目前为止,我只是用下面的代码初始化了元素

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");

最佳答案

setTheme() 的构建模式参数不是路径而是主题的 id,因此您需要调用 .setTheme('ace/theme/tomorrow_night') 代替

请注意,您还可以使用一次调用设置所有选项

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

或者在带有 ace.edit 选项的新版本的 ace pass 对象中

var editor = ace.edit("editor"{
    useWrapMode: true,
    ...
})

关于ace-editor - 如何在 Ace 编辑器中更改主题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27335866/

相关文章:

ace-editor - 根据浏览器的大小调整 ajax.org ACE 编辑器的大小

javascript - 重构 Ace 编辑器

ace-editor - 突出显示已更改的行

html - 将 Ace 编辑器与 Twitter Bootstrap 结合使用

javascript - Ace 编辑器中的递归 block

javascript - Ace Editor 中 iframe 源代码输出中出现不需要的空间

javascript - Ace 编辑器 API : How to select line 2?

javascript - 单击进入 ace 编辑器时防止模态窗口向上滚动

javascript - 根据其中字符的长度设置ace编辑器实例的宽度