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"><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
<p>Pellentesque sed enim vel turpis euismod tristique nec vitae odio. Fusce eu nisi vel ligula vehicula ornare.</p>
<p>Phasellus ornare purus et ultrices dapibus. Donec ullamcorper dapibus quam non imperdiet.</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"><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
<p>Pellentesque sed enim vel turpis euismod tristique nec vitae odio. Fusce eu nisi vel ligula vehicula ornare.</p>
<p>Phasellus ornare purus et ultrices dapibus. Donec ullamcorper dapibus quam non imperdiet.</p></textarea>
它最初被称为indentSubsequentLines[1](我认为这会更有意义),但是在登陆插件的代码库之前已被更改为[2].
标签:ace-editor,word-wrap,indentation,javascript 来源: https://codeday.me/bug/20191118/2028263.html