| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 | <!doctype html><html>  <head>    <meta charset="utf-8"/>    <title>CodeMirror: Upgrading to v2.2</title>    <link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Droid+Sans|Droid+Sans:bold"/>    <link rel="stylesheet" type="text/css" href="docs.css"/>  </head>  <body><h1><span class="logo-braces">{ }</span> <a href="http://codemirror.net/">CodeMirror</a></h1><div class="grey"><img src="baboon.png" class="logo" alt="logo"/><pre>/* Upgrading to   v2.2 */</pre></div><div class="left"><p>There are a few things in the 2.2 release that require some carewhen upgrading.</p><h2>No more default.css</h2><p>The default theme is now includedin <a href="../lib/codemirror.css"><code>codemirror.css</code></a>, soyou do not have to included it separately anymore. (It was tiny, soeven if you're not using it, the extra data overhead is negligible.)<h2>Different key customization</h2><p>CodeMirror has moved to a systemwhere <a href="manual.html#option_keyMap">keymaps</a> are used tobind behavior to keys. This means <a href="../demo/emacs.html">custombindings</a> are now possible.</p><p>Three options that influenced keybehavior, <code>tabMode</code>, <code>enterMode</code>,and <code>smartHome</code>, are no longer supported. Instead, you canprovide custom bindings to influence the way these keys act. This isdone through thenew <a href="manual.html#option_extraKeys"><code>extraKeys</code></a>option, which can hold an object mapping key names to functionality. Asimple example would be:</p><pre>  extraKeys: {    "Ctrl-S": function(instance) { saveText(instance.getValue()); },    "Ctrl-/": "undo"  }</pre><p>Keys can be mapped either to functions, which will be given theeditor instance as argument, or to strings, which are mapped throughfunctions through the <code>CodeMirror.commands</code> table, whichcontains all the built-in editing commands, and can be inspected andextended by external code.</p><p>By default, the <code>Home</code> key is bound tothe <code>"goLineStartSmart"</code> command, which moves the cursor tothe first non-whitespace character on the line. You can set do this tomake it always go to the very start instead:</p><pre>  extraKeys: {"Home": "goLineStart"}</pre><p>Similarly, <code>Enter</code> is boundto <code>"newlineAndIndent"</code> by default. You can bind it tosomething else to get different behavior. To disable special handlingcompletely and only get a newline character inserted, you can bind itto <code>false</code>:</p><pre>  extraKeys: {"Enter": false}</pre><p>The same works for <code>Tab</code>. If you don't want CodeMirrorto handle it, bind it to <code>false</code>. The default behaviour isto indent the current line more (<code>"indentMore"</code> command),and indent it less when shift is held (<code>"indentLess"</code>).There are also <code>"indentAuto"</code> (smart indent)and <code>"insertTab"</code> commands provided for alternatebehaviors. Or you can write your own handler function to do somethingdifferent altogether.</p><h2>Tabs</h2><p>Handling of tabs changed completely. The display width of tabs cannow be set with the <code>tabSize</code> option, and tabs canbe <a href="../demo/visibletabs.html">styled</a> by setting CSS rulesfor the <code>cm-tab</code> class.</p><p>The default width for tabs is now 4, as opposed to the 8 that ishard-wired into browsers. If you are relying on 8-space tabs, makesure you explicitly set <code>tabSize: 8</code> in your options.</p></div>  </body></html>
 |