我有以下代码:
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>
正如您所看到的,太长的行被正确地包裹到下一行,但由于某种原因,在包裹的行部分前面有一些奇怪的缩进。我怎么能摆脱它?
答案 0 :(得分:3)
在致电indentedSoftWrap
之前,您需要在false
上将选项session
设置为setUseWrapMode
。请参阅下面的工作示例:
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>