我使用以下代码创建了一个ACE编辑器实例:
var editor = ace.edit("editor");
editor.setTheme("ace/theme/monokai");
editor.getSession().setMode("ace/mode/javascript");
#editor {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.1.9/ace.js"></script>
<div id="editor">function foo (x) {
return 2 * x;
}
function bar (y) {
return foo(y) / 2;
}
console.log(bar(2) + foo(3));</div>
我想控制缩进大小(特别是在按 tab 键时)。我怎么能这样做?
我在API参考中搜索但我找不到解决方案......
答案 0 :(得分:16)
您可以使用下面显示的setOption("tabSize", 8)
或类似的setOptions函数
var editor = ace.edit("editor");
editor.setTheme("ace/theme/monokai");
editor.session.setOptions({
mode: "ace/mode/javascript",
tabSize: 8,
useSoftTabs: true
});
&#13;
#editor {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
&#13;
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.1.9/ace.js">
</script>
<div id="editor">function foo (x) {
return 2 * x;
}</div>
&#13;