aboutsummaryrefslogtreecommitdiff
path: root/imports/codemirror/mode/diff
diff options
context:
space:
mode:
authorPushkar Joshi2012-02-24 12:08:49 -0800
committerPushkar Joshi2012-02-24 12:08:49 -0800
commit03ca7a5ed13c25faaa9100bb666e062fd15335e6 (patch)
treec51112223ceb9121cd595a60335eb2795215590f /imports/codemirror/mode/diff
parentfcb12cc09eb3cd3b42bd215877ba18f449275b75 (diff)
parent053fc63a2950c7a5ee4ebf98033b64d474a3c46e (diff)
downloadninja-03ca7a5ed13c25faaa9100bb666e062fd15335e6.tar.gz
Merge branch 'pentool' into brushtool
Conflicts: imports/codemirror/mode/scheme/scheme.js js/tools/BrushTool.js
Diffstat (limited to 'imports/codemirror/mode/diff')
-rwxr-xr-ximports/codemirror/mode/diff/diff.css3
-rwxr-xr-ximports/codemirror/mode/diff/diff.js13
-rwxr-xr-ximports/codemirror/mode/diff/index.html99
3 files changed, 115 insertions, 0 deletions
diff --git a/imports/codemirror/mode/diff/diff.css b/imports/codemirror/mode/diff/diff.css
new file mode 100755
index 00000000..0e96ab21
--- /dev/null
+++ b/imports/codemirror/mode/diff/diff.css
@@ -0,0 +1,3 @@
1span.cm-rangeinfo {color: #a0b;}
2span.cm-minus {color: red;}
3span.cm-plus {color: #2b2;}
diff --git a/imports/codemirror/mode/diff/diff.js b/imports/codemirror/mode/diff/diff.js
new file mode 100755
index 00000000..725bb2c7
--- /dev/null
+++ b/imports/codemirror/mode/diff/diff.js
@@ -0,0 +1,13 @@
1CodeMirror.defineMode("diff", function() {
2 return {
3 token: function(stream) {
4 var ch = stream.next();
5 stream.skipToEnd();
6 if (ch == "+") return "plus";
7 if (ch == "-") return "minus";
8 if (ch == "@") return "rangeinfo";
9 }
10 };
11});
12
13CodeMirror.defineMIME("text/x-diff", "diff");
diff --git a/imports/codemirror/mode/diff/index.html b/imports/codemirror/mode/diff/index.html
new file mode 100755
index 00000000..2540236c
--- /dev/null
+++ b/imports/codemirror/mode/diff/index.html
@@ -0,0 +1,99 @@
1<!doctype html>
2<html>
3 <head>
4 <title>CodeMirror: 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="../../doc/docs.css">
11 </head>
12 <body>
13 <h1>CodeMirror: Diff mode</h1>
14 <form><textarea id="code" name="code">
15diff --git a/index.html b/index.html
16index 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>
29diff --git a/lib/codemirror.js b/lib/codemirror.js
30index 04646a9..9a39cc7 100644
31--- a/lib/codemirror.js
32+++ b/lib/codemirror.js
33@@ -399,10 +399,16 @@ var CodeMirror = (function() {
34 }
35
36 function onMouseDown(e) {
37- var start = posFromMouse(e), last = start;
38+ var start = posFromMouse(e), last = start, target = e.target();
39 if (!start) return;
40 setCursor(start.line, start.ch, false);
41 if (e.button() != 1) return;
42+ if (target.parentNode == gutter) {
43+ if (options.onGutterClick)
44+ options.onGutterClick(indexOf(gutter.childNodes, target) + showingFrom);
45+ return;
46+ }
47+
48 if (!focused) onFocus();
49
50 e.stop();
51@@ -808,7 +814,7 @@ var CodeMirror = (function() {
52 for (var i = showingFrom; i < showingTo; ++i) {
53 var marker = lines[i].gutterMarker;
54 if (marker) html.push('<div class="' + marker.style + '">' + htmlEscape(marker.text) + '</div>');
55- else html.push("<div>" + (options.lineNumbers ? i + 1 : "\u00a0") + "</div>");
56+ else html.push("<div>" + (options.lineNumbers ? i + options.firstLineNumber : "\u00a0") + "</div>");
57 }
58 gutter.style.display = "none"; // TODO test whether this actually helps
59 gutter.innerHTML = html.join("");
60@@ -1371,10 +1377,8 @@ var CodeMirror = (function() {
61 if (option == "parser") setParser(value);
62 else if (option === "lineNumbers") setLineNumbers(value);
63 else if (option === "gutter") setGutter(value);
64- else if (option === "readOnly") options.readOnly = value;
65- else if (option === "indentUnit") {options.indentUnit = indentUnit = value; setParser(options.parser);}
66- else if (/^(?:enterMode|tabMode|indentWithTabs|readOnly|autoMatchBrackets|undoDepth)$/.test(option)) options[option] = value;
67- else throw new Error("Can't set option " + option);
68+ else if (option === "indentUnit") {options.indentUnit = value; setParser(options.parser);}
69+ else options[option] = value;
70 },
71 cursorCoords: cursorCoords,
72 undo: operation(undo),
73@@ -1402,7 +1406,8 @@ var CodeMirror = (function() {
74 replaceRange: operation(replaceRange),
75
76 operation: function(f){return operation(f)();},
77- refresh: function(){updateDisplay([{from: 0, to: lines.length}]);}
78+ refresh: function(){updateDisplay([{from: 0, to: lines.length}]);},
79+ getInputField: function(){return input;}
80 };
81 return instance;
82 }
83@@ -1420,6 +1425,7 @@ var CodeMirror = (function() {
84 readOnly: false,
85 onChange: null,
86 onCursorActivity: null,
87+ onGutterClick: null,
88 autoMatchBrackets: false,
89 workTime: 200,
90 workDelay: 300,
91</textarea></form>
92 <script>
93 var editor = CodeMirror.fromTextArea(document.getElementById("code"), {});
94 </script>
95
96 <p><strong>MIME types defined:</strong> <code>text/x-diff</code>.</p>
97
98 </body>
99</html>