You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
3.5 KiB

7 months ago
  1. <!doctype html>
  2. <title>CodeMirror: Version 2.2 upgrade guide</title>
  3. <meta charset="utf-8"/>
  4. <link rel=stylesheet href="docs.css">
  5. <div id=nav>
  6. <a href="https://codemirror.net/5"><h1>CodeMirror</h1><img id=logo src="logo.png"></a>
  7. <ul>
  8. <li><a href="../index.html">Home</a>
  9. <li><a href="manual.html">Manual</a>
  10. <li><a href="https://github.com/codemirror/codemirror5">Code</a>
  11. </ul>
  12. <ul>
  13. <li><a class=active href="#">2.2 upgrade guide</a>
  14. </ul>
  15. </div>
  16. <article>
  17. <h2>Upgrading to v2.2</h2>
  18. <p>There are a few things in the 2.2 release that require some care
  19. when upgrading.</p>
  20. <h3>No more default.css</h3>
  21. <p>The default theme is now included
  22. in <a href="../lib/codemirror.css"><code>codemirror.css</code></a>, so
  23. you do not have to included it separately anymore. (It was tiny, so
  24. even if you're not using it, the extra data overhead is negligible.)
  25. <h3>Different key customization</h3>
  26. <p>CodeMirror has moved to a system
  27. where <a href="manual.html#option_keyMap">keymaps</a> are used to
  28. bind behavior to keys. This means <a href="../demo/emacs.html">custom
  29. bindings</a> are now possible.</p>
  30. <p>Three options that influenced key
  31. behavior, <code>tabMode</code>, <code>enterMode</code>,
  32. and <code>smartHome</code>, are no longer supported. Instead, you can
  33. provide custom bindings to influence the way these keys act. This is
  34. done through the
  35. new <a href="manual.html#option_extraKeys"><code>extraKeys</code></a>
  36. option, which can hold an object mapping key names to functionality. A
  37. simple example would be:</p>
  38. <pre> extraKeys: {
  39. "Ctrl-S": function(instance) { saveText(instance.getValue()); },
  40. "Ctrl-/": "undo"
  41. }</pre>
  42. <p>Keys can be mapped either to functions, which will be given the
  43. editor instance as argument, or to strings, which are mapped through
  44. functions through the <code>CodeMirror.commands</code> table, which
  45. contains all the built-in editing commands, and can be inspected and
  46. extended by external code.</p>
  47. <p>By default, the <code>Home</code> key is bound to
  48. the <code>"goLineStartSmart"</code> command, which moves the cursor to
  49. the first non-whitespace character on the line. You can set do this to
  50. make it always go to the very start instead:</p>
  51. <pre> extraKeys: {"Home": "goLineStart"}</pre>
  52. <p>Similarly, <code>Enter</code> is bound
  53. to <code>"newlineAndIndent"</code> by default. You can bind it to
  54. something else to get different behavior. To disable special handling
  55. completely and only get a newline character inserted, you can bind it
  56. to <code>false</code>:</p>
  57. <pre> extraKeys: {"Enter": false}</pre>
  58. <p>The same works for <code>Tab</code>. If you don't want CodeMirror
  59. to handle it, bind it to <code>false</code>. The default behaviour is
  60. to indent the current line more (<code>"indentMore"</code> command),
  61. and indent it less when shift is held (<code>"indentLess"</code>).
  62. There are also <code>"indentAuto"</code> (smart indent)
  63. and <code>"insertTab"</code> commands provided for alternate
  64. behavior. Or you can write your own handler function to do something
  65. different altogether.</p>
  66. <h3>Tabs</h3>
  67. <p>Handling of tabs changed completely. The display width of tabs can
  68. now be set with the <code>tabSize</code> option, and tabs can
  69. be <a href="../demo/visibletabs.html">styled</a> by setting CSS rules
  70. for the <code>cm-tab</code> class.</p>
  71. <p>The default width for tabs is now 4, as opposed to the 8 that is
  72. hard-wired into browsers. If you are relying on 8-space tabs, make
  73. sure you explicitly set <code>tabSize: 8</code> in your options.</p>
  74. </article>