index.html 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>CodeMirror: Diff mode</title>
  6. <link rel="stylesheet" href="../../lib/codemirror.css">
  7. <script src="../../lib/codemirror.js"></script>
  8. <script src="diff.js"></script>
  9. <style>
  10. .CodeMirror {border-top: 1px solid #ddd; border-bottom: 1px solid #ddd;}
  11. span.cm-meta {color: #a0b !important;}
  12. span.cm-error { background-color: black; opacity: 0.4;}
  13. span.cm-error.cm-string { background-color: red; }
  14. span.cm-error.cm-tag { background-color: #2b2; }
  15. </style>
  16. <link rel="stylesheet" href="../../doc/docs.css">
  17. </head>
  18. <body>
  19. <h1>CodeMirror: Diff mode</h1>
  20. <form><textarea id="code" name="code">
  21. diff --git a/index.html b/index.html
  22. index c1d9156..7764744 100644
  23. --- a/index.html
  24. +++ b/index.html
  25. @@ -95,7 +95,8 @@ StringStream.prototype = {
  26. <script>
  27. var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
  28. lineNumbers: true,
  29. - autoMatchBrackets: true
  30. + autoMatchBrackets: true,
  31. + onGutterClick: function(x){console.log(x);}
  32. });
  33. </script>
  34. </body>
  35. diff --git a/lib/codemirror.js b/lib/codemirror.js
  36. index 04646a9..9a39cc7 100644
  37. --- a/lib/codemirror.js
  38. +++ b/lib/codemirror.js
  39. @@ -399,10 +399,16 @@ var CodeMirror = (function() {
  40. }
  41. function onMouseDown(e) {
  42. - var start = posFromMouse(e), last = start;
  43. + var start = posFromMouse(e), last = start, target = e.target();
  44. if (!start) return;
  45. setCursor(start.line, start.ch, false);
  46. if (e.button() != 1) return;
  47. + if (target.parentNode == gutter) {
  48. + if (options.onGutterClick)
  49. + options.onGutterClick(indexOf(gutter.childNodes, target) + showingFrom);
  50. + return;
  51. + }
  52. +
  53. if (!focused) onFocus();
  54. e.stop();
  55. @@ -808,7 +814,7 @@ var CodeMirror = (function() {
  56. for (var i = showingFrom; i < showingTo; ++i) {
  57. var marker = lines[i].gutterMarker;
  58. if (marker) html.push('<div class="' + marker.style + '">' + htmlEscape(marker.text) + '</div>');
  59. - else html.push("<div>" + (options.lineNumbers ? i + 1 : "\u00a0") + "</div>");
  60. + else html.push("<div>" + (options.lineNumbers ? i + options.firstLineNumber : "\u00a0") + "</div>");
  61. }
  62. gutter.style.display = "none"; // TODO test whether this actually helps
  63. gutter.innerHTML = html.join("");
  64. @@ -1371,10 +1377,8 @@ var CodeMirror = (function() {
  65. if (option == "parser") setParser(value);
  66. else if (option === "lineNumbers") setLineNumbers(value);
  67. else if (option === "gutter") setGutter(value);
  68. - else if (option === "readOnly") options.readOnly = value;
  69. - else if (option === "indentUnit") {options.indentUnit = indentUnit = value; setParser(options.parser);}
  70. - else if (/^(?:enterMode|tabMode|indentWithTabs|readOnly|autoMatchBrackets|undoDepth)$/.test(option)) options[option] = value;
  71. - else throw new Error("Can't set option " + option);
  72. + else if (option === "indentUnit") {options.indentUnit = value; setParser(options.parser);}
  73. + else options[option] = value;
  74. },
  75. cursorCoords: cursorCoords,
  76. undo: operation(undo),
  77. @@ -1402,7 +1406,8 @@ var CodeMirror = (function() {
  78. replaceRange: operation(replaceRange),
  79. operation: function(f){return operation(f)();},
  80. - refresh: function(){updateDisplay([{from: 0, to: lines.length}]);}
  81. + refresh: function(){updateDisplay([{from: 0, to: lines.length}]);},
  82. + getInputField: function(){return input;}
  83. };
  84. return instance;
  85. }
  86. @@ -1420,6 +1425,7 @@ var CodeMirror = (function() {
  87. readOnly: false,
  88. onChange: null,
  89. onCursorActivity: null,
  90. + onGutterClick: null,
  91. autoMatchBrackets: false,
  92. workTime: 200,
  93. workDelay: 300,
  94. </textarea></form>
  95. <script>
  96. var editor = CodeMirror.fromTextArea(document.getElementById("code"), {});
  97. </script>
  98. <p><strong>MIME types defined:</strong> <code>text/x-diff</code>.</p>
  99. </body>
  100. </html>