Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable indentation of subsequent lines in Ace Editor when line wrapping is enabled

I have the following code:

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/[email protected](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>

As you can see, the lines that are too long are correctly wrapped to the next line, but for some reason there's some strange indentation in front of the part of the line that wraps. How can I get rid of it?

like image 215
SeinopSys Avatar asked Oct 18 '25 16:10

SeinopSys


1 Answers

You need to set the option indentedSoftWrap to false on your session before calling setUseWrapMode. See a working example below:

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/[email protected](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>

It was initially called indentSubsequentLines[1] (which - in my opinion - would make more sense), but it was changed[2] before landing in the codebase of the plugin.

like image 115
SeinopSys Avatar answered Oct 21 '25 05:10

SeinopSys



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!