diff options
author | Valerio Virgillito | 2012-02-15 16:09:47 -0800 |
---|---|---|
committer | Valerio Virgillito | 2012-02-15 16:09:47 -0800 |
commit | d366c0bd1af6471511217ed574083e15059519b5 (patch) | |
tree | c8c9f9af761457e3c5f4c6774fb0fbba851df0c4 /imports/codemirror/lib/util | |
parent | 997ce3fb65f27b3d6f331f63b5dc22d3c7fb8f1e (diff) | |
parent | b85bfb54aaca3ccca3c1ef09115de925cd67f4e9 (diff) | |
download | ninja-d366c0bd1af6471511217ed574083e15059519b5.tar.gz |
Merge branch 'refs/heads/integration'
Diffstat (limited to 'imports/codemirror/lib/util')
-rwxr-xr-x | imports/codemirror/lib/util/dialog.css | 23 | ||||
-rwxr-xr-x | imports/codemirror/lib/util/dialog.js | 63 | ||||
-rwxr-xr-x | imports/codemirror/lib/util/foldcode.js | 66 | ||||
-rwxr-xr-x | imports/codemirror/lib/util/formatting.js | 291 | ||||
-rwxr-xr-x | imports/codemirror/lib/util/javascript-hint.js | 83 | ||||
-rwxr-xr-x | imports/codemirror/lib/util/overlay.js | 51 | ||||
-rwxr-xr-x | imports/codemirror/lib/util/runmode.js | 27 | ||||
-rwxr-xr-x | imports/codemirror/lib/util/search.js | 114 | ||||
-rwxr-xr-x | imports/codemirror/lib/util/searchcursor.js | 117 | ||||
-rwxr-xr-x | imports/codemirror/lib/util/simple-hint.css | 16 | ||||
-rwxr-xr-x | imports/codemirror/lib/util/simple-hint.js | 66 |
11 files changed, 917 insertions, 0 deletions
diff --git a/imports/codemirror/lib/util/dialog.css b/imports/codemirror/lib/util/dialog.css new file mode 100755 index 00000000..4cb467ef --- /dev/null +++ b/imports/codemirror/lib/util/dialog.css | |||
@@ -0,0 +1,23 @@ | |||
1 | .CodeMirror-dialog { | ||
2 | position: relative; | ||
3 | } | ||
4 | |||
5 | .CodeMirror-dialog > div { | ||
6 | position: absolute; | ||
7 | top: 0; left: 0; right: 0; | ||
8 | background: white; | ||
9 | border-bottom: 1px solid #eee; | ||
10 | z-index: 15; | ||
11 | padding: .1em .8em; | ||
12 | overflow: hidden; | ||
13 | color: #333; | ||
14 | } | ||
15 | |||
16 | .CodeMirror-dialog input { | ||
17 | border: none; | ||
18 | outline: none; | ||
19 | background: transparent; | ||
20 | width: 20em; | ||
21 | color: inherit; | ||
22 | font-family: monospace; | ||
23 | } | ||
diff --git a/imports/codemirror/lib/util/dialog.js b/imports/codemirror/lib/util/dialog.js new file mode 100755 index 00000000..8950bf0c --- /dev/null +++ b/imports/codemirror/lib/util/dialog.js | |||
@@ -0,0 +1,63 @@ | |||
1 | // Open simple dialogs on top of an editor. Relies on dialog.css. | ||
2 | |||
3 | (function() { | ||
4 | function dialogDiv(cm, template) { | ||
5 | var wrap = cm.getWrapperElement(); | ||
6 | var dialog = wrap.insertBefore(document.createElement("div"), wrap.firstChild); | ||
7 | dialog.className = "CodeMirror-dialog"; | ||
8 | dialog.innerHTML = '<div>' + template + '</div>'; | ||
9 | return dialog; | ||
10 | } | ||
11 | |||
12 | CodeMirror.defineExtension("openDialog", function(template, callback) { | ||
13 | var dialog = dialogDiv(this, template); | ||
14 | var closed = false, me = this; | ||
15 | function close() { | ||
16 | if (closed) return; | ||
17 | closed = true; | ||
18 | dialog.parentNode.removeChild(dialog); | ||
19 | } | ||
20 | var inp = dialog.getElementsByTagName("input")[0]; | ||
21 | if (inp) { | ||
22 | CodeMirror.connect(inp, "keydown", function(e) { | ||
23 | if (e.keyCode == 13 || e.keyCode == 27) { | ||
24 | CodeMirror.e_stop(e); | ||
25 | close(); | ||
26 | me.focus(); | ||
27 | if (e.keyCode == 13) callback(inp.value); | ||
28 | } | ||
29 | }); | ||
30 | inp.focus(); | ||
31 | CodeMirror.connect(inp, "blur", close); | ||
32 | } | ||
33 | return close; | ||
34 | }); | ||
35 | |||
36 | CodeMirror.defineExtension("openConfirm", function(template, callbacks) { | ||
37 | var dialog = dialogDiv(this, template); | ||
38 | var buttons = dialog.getElementsByTagName("button"); | ||
39 | var closed = false, me = this, blurring = 1; | ||
40 | function close() { | ||
41 | if (closed) return; | ||
42 | closed = true; | ||
43 | dialog.parentNode.removeChild(dialog); | ||
44 | me.focus(); | ||
45 | } | ||
46 | buttons[0].focus(); | ||
47 | for (var i = 0; i < buttons.length; ++i) { | ||
48 | var b = buttons[i]; | ||
49 | (function(callback) { | ||
50 | CodeMirror.connect(b, "click", function(e) { | ||
51 | CodeMirror.e_preventDefault(e); | ||
52 | close(); | ||
53 | if (callback) callback(me); | ||
54 | }); | ||
55 | })(callbacks[i]); | ||
56 | CodeMirror.connect(b, "blur", function() { | ||
57 | --blurring; | ||
58 | setTimeout(function() { if (blurring <= 0) close(); }, 200); | ||
59 | }); | ||
60 | CodeMirror.connect(b, "focus", function() { ++blurring; }); | ||
61 | } | ||
62 | }); | ||
63 | })(); \ No newline at end of file | ||
diff --git a/imports/codemirror/lib/util/foldcode.js b/imports/codemirror/lib/util/foldcode.js new file mode 100755 index 00000000..18957792 --- /dev/null +++ b/imports/codemirror/lib/util/foldcode.js | |||
@@ -0,0 +1,66 @@ | |||
1 | CodeMirror.braceRangeFinder = function(cm, line) { | ||
2 | var lineText = cm.getLine(line); | ||
3 | var startChar = lineText.lastIndexOf("{"); | ||
4 | if (startChar < 0 || lineText.lastIndexOf("}") > startChar) return; | ||
5 | var tokenType = cm.getTokenAt({line: line, ch: startChar}).className; | ||
6 | var count = 1, lastLine = cm.lineCount(), end; | ||
7 | outer: for (var i = line + 1; i < lastLine; ++i) { | ||
8 | var text = cm.getLine(i), pos = 0; | ||
9 | for (;;) { | ||
10 | var nextOpen = text.indexOf("{", pos), nextClose = text.indexOf("}", pos); | ||
11 | if (nextOpen < 0) nextOpen = text.length; | ||
12 | if (nextClose < 0) nextClose = text.length; | ||
13 | pos = Math.min(nextOpen, nextClose); | ||
14 | if (pos == text.length) break; | ||
15 | if (cm.getTokenAt({line: i, ch: pos + 1}).className == tokenType) { | ||
16 | if (pos == nextOpen) ++count; | ||
17 | else if (!--count) { end = i; break outer; } | ||
18 | } | ||
19 | ++pos; | ||
20 | } | ||
21 | } | ||
22 | if (end == null || end == line + 1) return; | ||
23 | return end; | ||
24 | }; | ||
25 | |||
26 | |||
27 | CodeMirror.newFoldFunction = function(rangeFinder, markText) { | ||
28 | var folded = []; | ||
29 | if (markText == null) markText = '<div style="position: absolute; left: 2px; color:#600">▼</div>%N%'; | ||
30 | |||
31 | function isFolded(cm, n) { | ||
32 | for (var i = 0; i < folded.length; ++i) { | ||
33 | var start = cm.lineInfo(folded[i].start); | ||
34 | if (!start) folded.splice(i--, 1); | ||
35 | else if (start.line == n) return {pos: i, region: folded[i]}; | ||
36 | } | ||
37 | } | ||
38 | |||
39 | function expand(cm, region) { | ||
40 | cm.clearMarker(region.start); | ||
41 | for (var i = 0; i < region.hidden.length; ++i) | ||
42 | cm.showLine(region.hidden[i]); | ||
43 | } | ||
44 | |||
45 | return function(cm, line) { | ||
46 | cm.operation(function() { | ||
47 | var known = isFolded(cm, line); | ||
48 | if (known) { | ||
49 | folded.splice(known.pos, 1); | ||
50 | expand(cm, known.region); | ||
51 | } else { | ||
52 | var end = rangeFinder(cm, line); | ||
53 | if (end == null) return; | ||
54 | var hidden = []; | ||
55 | for (var i = line + 1; i < end; ++i) { | ||
56 | var handle = cm.hideLine(i); | ||
57 | if (handle) hidden.push(handle); | ||
58 | } | ||
59 | var first = cm.setMarker(line, markText); | ||
60 | var region = {start: first, hidden: hidden}; | ||
61 | cm.onDeleteLine(first, function() { expand(cm, region); }); | ||
62 | folded.push(region); | ||
63 | } | ||
64 | }); | ||
65 | }; | ||
66 | }; | ||
diff --git a/imports/codemirror/lib/util/formatting.js b/imports/codemirror/lib/util/formatting.js new file mode 100755 index 00000000..986bcb8f --- /dev/null +++ b/imports/codemirror/lib/util/formatting.js | |||
@@ -0,0 +1,291 @@ | |||
1 | // ============== Formatting extensions ============================ | ||
2 | // A common storage for all mode-specific formatting features | ||
3 | if (!CodeMirror.modeExtensions) CodeMirror.modeExtensions = {}; | ||
4 | |||
5 | // Returns the extension of the editor's current mode | ||
6 | CodeMirror.defineExtension("getModeExt", function () { | ||
7 | return CodeMirror.modeExtensions[this.getOption("mode")]; | ||
8 | }); | ||
9 | |||
10 | // If the current mode is 'htmlmixed', returns the extension of a mode located at | ||
11 | // the specified position (can be htmlmixed, css or javascript). Otherwise, simply | ||
12 | // returns the extension of the editor's current mode. | ||
13 | CodeMirror.defineExtension("getModeExtAtPos", function (pos) { | ||
14 | var token = this.getTokenAt(pos); | ||
15 | if (token && token.state && token.state.mode) | ||
16 | return CodeMirror.modeExtensions[token.state.mode == "html" ? "htmlmixed" : token.state.mode]; | ||
17 | else | ||
18 | return this.getModeExt(); | ||
19 | }); | ||
20 | |||
21 | // Comment/uncomment the specified range | ||
22 | CodeMirror.defineExtension("commentRange", function (isComment, from, to) { | ||
23 | var curMode = this.getModeExtAtPos(this.getCursor()); | ||
24 | if (isComment) { // Comment range | ||
25 | var commentedText = this.getRange(from, to); | ||
26 | this.replaceRange(curMode.commentStart + this.getRange(from, to) + curMode.commentEnd | ||
27 | , from, to); | ||
28 | if (from.line == to.line && from.ch == to.ch) { // An empty comment inserted - put cursor inside | ||
29 | this.setCursor(from.line, from.ch + curMode.commentStart.length); | ||
30 | } | ||
31 | } | ||
32 | else { // Uncomment range | ||
33 | var selText = this.getRange(from, to); | ||
34 | var startIndex = selText.indexOf(curMode.commentStart); | ||
35 | var endIndex = selText.lastIndexOf(curMode.commentEnd); | ||
36 | if (startIndex > -1 && endIndex > -1 && endIndex > startIndex) { | ||
37 | // Take string till comment start | ||
38 | selText = selText.substr(0, startIndex) | ||
39 | // From comment start till comment end | ||
40 | + selText.substring(startIndex + curMode.commentStart.length, endIndex) | ||
41 | // From comment end till string end | ||
42 | + selText.substr(endIndex + curMode.commentEnd.length); | ||
43 | } | ||
44 | this.replaceRange(selText, from, to); | ||
45 | } | ||
46 | }); | ||
47 | |||
48 | // Applies automatic mode-aware indentation to the specified range | ||
49 | CodeMirror.defineExtension("autoIndentRange", function (from, to) { | ||
50 |