File modules/editor/codemirror/mode/diff/index.html

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