closebrackets.html 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <!doctype html>
  2. <title>CodeMirror: Closebrackets Demo</title>
  3. <meta charset="utf-8"/>
  4. <link rel=stylesheet href="../doc/docs.css">
  5. <link rel="stylesheet" href="../lib/codemirror.css">
  6. <script src="../lib/codemirror.js"></script>
  7. <script src="../addon/edit/closebrackets.js"></script>
  8. <script src="../mode/javascript/javascript.js"></script>
  9. <style type="text/css">
  10. .CodeMirror {border-top: 1px solid #888; border-bottom: 1px solid #888;}
  11. </style>
  12. <div id=nav>
  13. <a href="https://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../doc/logo.png"></a>
  14. <ul>
  15. <li><a href="../index.html">Home</a>
  16. <li><a href="../doc/manual.html">Manual</a>
  17. <li><a href="https://github.com/codemirror/codemirror">Code</a>
  18. </ul>
  19. <ul>
  20. <li><a class=active href="#">Closebrackets</a>
  21. </ul>
  22. </div>
  23. <article>
  24. <h2>Closebrackets Demo</h2>
  25. <form><textarea id="code" name="code">function Grid(width, height) {
  26. this.width = width;
  27. this.height = height;
  28. this.cells = new Array(width * height);
  29. }
  30. Grid.prototype.valueAt = function(point) {
  31. return this.cells[point.y * this.width + point.x];
  32. };
  33. Grid.prototype.setValueAt = function(point, value) {
  34. this.cells[point.y * this.width + point.x] = value;
  35. };
  36. Grid.prototype.isInside = function(point) {
  37. return point.x >= 0 && point.y >= 0 &&
  38. point.x < this.width && point.y < this.height;
  39. };
  40. Grid.prototype.moveValue = function(from, to) {
  41. this.setValueAt(to, this.valueAt(from));
  42. this.setValueAt(from, undefined);
  43. };</textarea></form>
  44. <script type="text/javascript">
  45. var editor = CodeMirror.fromTextArea(document.getElementById("code"), {autoCloseBrackets: true});
  46. </script>
  47. </article>