diff options
author | Pierre Frisch | 2011-12-22 07:25:50 -0800 |
---|---|---|
committer | Valerio Virgillito | 2012-01-27 11:18:17 -0800 |
commit | b89a7ee8b956c96a1dcee995ea840feddc5d4b27 (patch) | |
tree | 0f3136ab0ecdbbbed6a83576581af0a53124d6f1 /js/codemirror/mode/diff | |
parent | 2401f05d1f4b94d45e4568b81fc73e67b969d980 (diff) | |
download | ninja-b89a7ee8b956c96a1dcee995ea840feddc5d4b27.tar.gz |
First commit of Ninja to ninja-internal
Signed-off-by: Valerio Virgillito <rmwh84@motorola.com>
Diffstat (limited to 'js/codemirror/mode/diff')
-rw-r--r-- | js/codemirror/mode/diff/diff.css | 3 | ||||
-rw-r--r-- | js/codemirror/mode/diff/diff.js | 13 | ||||
-rw-r--r-- | js/codemirror/mode/diff/index.html | 99 |
3 files changed, 115 insertions, 0 deletions
diff --git a/js/codemirror/mode/diff/diff.css b/js/codemirror/mode/diff/diff.css new file mode 100644 index 00000000..16f8d335 --- /dev/null +++ b/js/codemirror/mode/diff/diff.css | |||
@@ -0,0 +1,3 @@ | |||
1 | .cm-s-default span.cm-rangeinfo {color: #a0b;} | ||
2 | .cm-s-default span.cm-minus {color: #a22;} | ||
3 | .cm-s-default span.cm-plus {color: #2b2;} | ||
diff --git a/js/codemirror/mode/diff/diff.js b/js/codemirror/mode/diff/diff.js new file mode 100644 index 00000000..725bb2c7 --- /dev/null +++ b/js/codemirror/mode/diff/diff.js | |||
@@ -0,0 +1,13 @@ | |||
1 | CodeMirror.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 | |||
13 | CodeMirror.defineMIME("text/x-diff", "diff"); | ||
diff --git a/js/codemirror/mode/diff/index.html b/js/codemirror/mode/diff/index.html new file mode 100644 index 00000000..2748f2fa --- /dev/null +++ b/js/codemirror/mode/diff/index.html | |||
@@ -0,0 +1,99 @@ | |||
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 | |||
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> | ||