javascript-启用换行时如何在Ace Editor中禁用后续行的缩进

我有以下代码:

var editor = ace.edit("editor");
editor.setTheme("ace/theme/dreamweaver");
editor.setShowPrintMargin(false);
var session = editor.getSession();
session.setMode("ace/mode/html");
session.setUseWrapMode(true);
.ace_editor {
  position: absolute !important;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
}
<script src="https://cdn.jsdelivr.net/g/ace@1.2.3(min/ace.js+min/mode-html.js+min/theme-dreamweaver.js)" type="text/javascript"></script>
<textarea id="editor">&lt;p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.&lt;/p>
&lt;p>Pellentesque sed enim vel turpis euismod tristique nec vitae odio. Fusce eu nisi vel ligula vehicula ornare.&lt;/p>
&lt;p>Phasellus ornare purus et ultrices dapibus. Donec ullamcorper dapibus quam non imperdiet.&lt;/p></textarea>

如您所见,太长的行正确地换行到了下一行,但是由于某种原因,在换行的那部分前面有一些奇怪的缩进.我该如何摆脱呢?

解决方法:

在调用setUseWrapMode之前,需要在会话上将选项indentedSoftWrap设置为false.请参见下面的工作示例:

var editor = ace.edit("editor");
editor.setTheme("ace/theme/dreamweaver");
editor.setShowPrintMargin(false);
var session = editor.getSession();
session.setMode("ace/mode/html");

// Setting the option
session.setOption('indentedSoftWrap', false);

session.setUseWrapMode(true);
.ace_editor {
  position: absolute !important;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
}
<script src="https://cdn.jsdelivr.net/g/ace@1.2.3(min/ace.js+min/mode-html.js+min/theme-dreamweaver.js)" type="text/javascript"></script>
<textarea id="editor">&lt;p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.&lt;/p>
&lt;p>Pellentesque sed enim vel turpis euismod tristique nec vitae odio. Fusce eu nisi vel ligula vehicula ornare.&lt;/p>
&lt;p>Phasellus ornare purus et ultrices dapibus. Donec ullamcorper dapibus quam non imperdiet.&lt;/p></textarea>

它最初被称为indentSubsequentLines[1](我认为这会更有意义),但是在登陆插件的代码库之前已被更改为[2].

上一篇:从零开始学Python(一)—— Sublime Text简介


下一篇:「GNU Emacs」- Treemacs(文件管理器) @20210402