1
0

index.html 3.8 KB

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