index.html 4.3 KB

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