最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to set indent size in ACE editor - Stack Overflow

programmeradmin1浏览0评论

I created an ACE editor instance using the following code:

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=".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>

I created an ACE editor instance using the following code:

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>

I want to control the indent size (especially when pressing the tab key). How can I do that?

I searched in the API reference but I couldn't find the solution...

Share Improve this question edited Apr 14, 2015 at 15:12 Johnny Willemsen 3,0021 gold badge16 silver badges17 bronze badges asked Apr 14, 2015 at 6:01 Ionică BizăuIonică Bizău 113k93 gold badges307 silver badges487 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 22

you can use setOption("tabSize", 8) or similar setOptions function shown bellow

var editor = ace.edit("editor");
editor.setTheme("ace/theme/monokai");
editor.session.setOptions({
    mode: "ace/mode/javascript",
    tabSize: 8,
    useSoftTabs: true
});
#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;
}</div>

发布评论

评论列表(0)

  1. 暂无评论