5 <title>CodeMirror: Indented wrapped line demo</title>
6 <link rel="stylesheet" href="../lib/codemirror.css">
7 <script src="../lib/codemirror.js"></script>
8 <script src="../mode/xml/xml.js"></script>
9 <link rel="stylesheet" href="../doc/docs.css">
11 <style type="text/css">
12 .CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}
16 <h1>CodeMirror: Indented wrapped line demo</h1>
18 <form><textarea id="code" name="code">
21 <h2 id="overview">Overview</h2>
23 <p>CodeMirror is a code-editor component that can be embedded in Web pages. The core library provides <em>only</em> the editor component, no accompanying buttons, auto-completion, or other IDE functionality. It does provide a rich API on top of which such functionality can be straightforwardly implemented. See the <a href="#addons">add-ons</a> included in the distribution, and the <a href="https://github.com/jagthedrummer/codemirror-ui">CodeMirror UI</a> project, for reusable implementations of extra features.</p>
25 <p>CodeMirror works with language-specific modes. Modes are JavaScript programs that help color (and optionally indent) text written in a given language. The distribution comes with a number of modes (see the <a href="../mode/"><code>mode/</code></a> directory), and it isn't hard to <a href="#modeapi">write new ones</a> for other languages.</p>
29 <p>This page uses a hack on top of the <code>"renderLine"</code>
30 event to make wrapped text line up with the base indentation of
34 var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
39 var charWidth = editor.defaultCharWidth(), basePadding = 4;
40 editor.on("renderLine", function(cm, line, elt) {
41 var off = CodeMirror.countColumn(line.text, null, cm.getOption("tabSize")) * charWidth;
42 elt.style.textIndent = "-" + off + "px";
43 elt.style.paddingLeft = (basePadding + off) + "px";