aboutsummaryrefslogtreecommitdiff
path: root/imports/codemirror/lib/util
diff options
context:
space:
mode:
authorJose Antonio Marquez Russo2012-02-29 15:41:12 -0800
committerJose Antonio Marquez Russo2012-02-29 15:41:12 -0800
commit13aca03d4e0d11729d691db0b7f0d2f2a6899cf6 (patch)
treedbd17232983247a38bb6b2cea480242bdf3f2422 /imports/codemirror/lib/util
parentb09956e4a9a35c5588cc7cd1f01efb617cbe0884 (diff)
parent8fee7d6bdb55ba18f396c3523081b18499fa1e30 (diff)
downloadninja-13aca03d4e0d11729d691db0b7f0d2f2a6899cf6.tar.gz
Merge pull request #24 from ananyasen/FileIO
undo/redo per document , codemirror 2.22 update
Diffstat (limited to 'imports/codemirror/lib/util')
-rw-r--r--[-rwxr-xr-x]imports/codemirror/lib/util/dialog.css0
-rw-r--r--[-rwxr-xr-x]imports/codemirror/lib/util/dialog.js0
-rw-r--r--[-rwxr-xr-x]imports/codemirror/lib/util/foldcode.js120
-rw-r--r--[-rwxr-xr-x]imports/codemirror/lib/util/formatting.js9
-rw-r--r--[-rwxr-xr-x]imports/codemirror/lib/util/javascript-hint.js67
-rw-r--r--imports/codemirror/lib/util/match-highlighter.js44
-rw-r--r--[-rwxr-xr-x]imports/codemirror/lib/util/overlay.js0
-rw-r--r--[-rwxr-xr-x]imports/codemirror/lib/util/runmode.js38
-rw-r--r--[-rwxr-xr-x]imports/codemirror/lib/util/search.js0
-rw-r--r--[-rwxr-xr-x]imports/codemirror/lib/util/searchcursor.js0
-rw-r--r--[-rwxr-xr-x]imports/codemirror/lib/util/simple-hint.css0
-rw-r--r--[-rwxr-xr-x]imports/codemirror/lib/util/simple-hint.js0
12 files changed, 258 insertions, 20 deletions
diff --git a/imports/codemirror/lib/util/dialog.css b/imports/codemirror/lib/util/dialog.css
index 4cb467ef..4cb467ef 100755..100644
--- a/imports/codemirror/lib/util/dialog.css
+++ b/imports/codemirror/lib/util/dialog.css
diff --git a/imports/codemirror/lib/util/dialog.js b/imports/codemirror/lib/util/dialog.js
index 8950bf0c..8950bf0c 100755..100644
--- a/imports/codemirror/lib/util/dialog.js
+++ b/imports/codemirror/lib/util/dialog.js
diff --git a/imports/codemirror/lib/util/foldcode.js b/imports/codemirror/lib/util/foldcode.js
index 18957792..50268a8b 100755..100644
--- a/imports/codemirror/lib/util/foldcode.js
+++ b/imports/codemirror/lib/util/foldcode.js
@@ -1,3 +1,110 @@
1// the tagRangeFinder function is
2// Copyright (C) 2011 by Daniel Glazman <daniel@glazman.org>
3// released under the MIT license (../../LICENSE) like the rest of CodeMirror
4CodeMirror.tagRangeFinder = function(cm, line) {
5 var nameStartChar = "A-Z_a-z\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD";
6 var nameChar = nameStartChar + "\-\.0-9\\u00B7\\u0300-\\u036F\\u203F-\\u2040";
7 var xmlNAMERegExp = new RegExp("^[" + nameStartChar + "][" + nameChar + "]*");
8
9 var lineText = cm.getLine(line);
10 var found = false;
11 var tag = null;
12 var pos = 0;
13 while (!found) {
14 pos = lineText.indexOf("<", pos);
15 if (-1 == pos) // no tag on line
16 return;
17 if (pos + 1 < lineText.length && lineText[pos + 1] == "/") { // closing tag
18 pos++;
19 continue;
20 }
21 // ok we weem to have a start tag
22 if (!lineText.substr(pos + 1).match(xmlNAMERegExp)) { // not a tag name...
23 pos++;
24 continue;
25 }
26 var gtPos = lineText.indexOf(">", pos + 1);
27 if (-1 == gtPos) { // end of start tag not in line
28 var l = line + 1;
29 var foundGt = false;
30 var lastLine = cm.lineCount();
31 while (l < lastLine && !foundGt) {
32 var lt = cm.getLine(l);
33 var gt = lt.indexOf(">");
34 if (-1 != gt) { // found a >
35 foundGt = true;
36 var slash = lt.lastIndexOf("/", gt);
37 if (-1 != slash && slash < gt) {
38 var str = lineText.substr(slash, gt - slash + 1);
39 if (!str.match( /\/\s*\>/ )) // yep, that's the end of empty tag
40 return l+1;
41 }
42 }
43 l++;
44 }
45 found = true;
46 }
47 else {
48 var slashPos = lineText.lastIndexOf("/", gtPos);
49 if (-1 == slashPos) { // cannot be empty tag
50 found = true;
51 // don't continue
52 }
53 else { // empty tag?
54 // check if really empty tag
55 var str = lineText.substr(slashPos, gtPos - slashPos + 1);
56 if (!str.match( /\/\s*\>/ )) { // finally not empty
57 found = true;
58 // don't continue
59 }
60 }
61 }
62 if (found) {
63 var subLine = lineText.substr(pos + 1);
64 tag = subLine.match(xmlNAMERegExp);
65 if (tag) {
66 // we have an element name, wooohooo !
67 tag = tag[0];
68 // do we have the close tag on same line ???
69 if (-1 != lineText.indexOf("</" + tag + ">", pos)) // yep
70 {
71 found = false;
72 }
73 // we don't, so we have a candidate...
74 }
75 else
76 found = false;
77 }
78 if (!found)
79 pos++;
80 }
81
82 if (found) {
83 var startTag = "(\\<\\/" + tag + "\\>)|(\\<" + tag + "\\>)|(\\<" + tag + "\s)|(\\<" + tag + "$)";
84 var startTagRegExp = new RegExp(startTag, "g");
85 var endTag = "</" + tag + ">";
86 var depth = 1;
87 var l = line + 1;
88 var lastLine = cm.lineCount();
89 while (l < lastLine) {
90 lineText = cm.getLine(l);
91 var match = lineText.match(startTagRegExp);
92 if (match) {
93 for (var i = 0; i < match.length; i++) {
94 if (match[i] == endTag)
95 depth--;
96 else
97 depth++;
98 if (!depth)
99 return l+1;
100 }
101 }
102 l++;
103 }
104 return;
105 }
106};
107
1CodeMirror.braceRangeFinder = function(cm, line) { 108CodeMirror.braceRangeFinder = function(cm, line) {
2 var lineText = cm.getLine(line); 109 var lineText = cm.getLine(line);
3 var startChar = lineText.lastIndexOf("{"); 110 var startChar = lineText.lastIndexOf("{");
@@ -23,6 +130,19 @@ CodeMirror.braceRangeFinder = function(cm, line) {
23 return end; 130 return end;
24}; 131};
25 132
133CodeMirror.indentRangeFinder = function(cm, line) {
134 var tabSize = cm.getOption("tabSize");
135 var myIndent = cm.getLineHandle(line).indentation(tabSize), last;
136 for (var i = line + 1, end = cm.lineCount(); i < end; ++i) {
137 var handle = cm.getLineHandle(i);
138 if (!/^\s*$/.test(handle.text)) {
139 if (handle.indentation(tabSize) <= myIndent) break;
140 last = i;
141 }
142 }
143 if (!last) return null;
144 return last + 1;
145};
26 146
27CodeMirror.newFoldFunction = function(rangeFinder, markText) { 147CodeMirror.newFoldFunction = function(rangeFinder, markText) {
28 var folded = []; 148 var folded = [];
diff --git a/imports/codemirror/lib/util/formatting.js b/imports/codemirror/lib/util/formatting.js
index 986bcb8f..15de0355 100755..100644
--- a/imports/codemirror/lib/util/formatting.js
+++ b/imports/codemirror/lib/util/formatting.js
@@ -4,7 +4,10 @@ if (!CodeMirror.modeExtensions) CodeMirror.modeExtensions = {};
4 4
5// Returns the extension of the editor's current mode 5// Returns the extension of the editor's current mode
6CodeMirror.defineExtension("getModeExt", function () { 6CodeMirror.defineExtension("getModeExt", function () {
7 return CodeMirror.modeExtensions[this.getOption("mode")]; 7 var mname = CodeMirror.resolveMode(this.getOption("mode")).name;
8 var ext = CodeMirror.modeExtensions[mname];
9 if (!ext) throw new Error("No extensions found for mode " + mname);
10 return ext;
8}); 11});
9 12
10// If the current mode is 'htmlmixed', returns the extension of a mode located at 13// If the current mode is 'htmlmixed', returns the extension of a mode located at
@@ -50,7 +53,7 @@ CodeMirror.defineExtension("autoIndentRange", function (from, to) {
50 var cmInstance = this; 53 var cmInstance = this;
51 this.operation(function () { 54 this.operation(function () {
52 for (var i = from.line; i <= to.line; i++) { 55 for (var i = from.line; i <= to.line; i++) {
53 cmInstance.indentLine(i); 56 cmInstance.indentLine(i, "smart");
54 } 57 }
55 }); 58 });
56}); 59});
@@ -70,7 +73,7 @@ CodeMirror.defineExtension("autoFormatRange", function (from, to) {
70 var startLine = cmInstance.posFromIndex(absStart).line; 73 var startLine = cmInstance.posFromIndex(absStart).line;
71 var endLine = cmInstance.posFromIndex(absStart + res.length).line; 74 var endLine = cmInstance.posFromIndex(absStart + res.length).line;
72 for (var i = startLine; i <= endLine; i++) { 75 for (var i = startLine; i <= endLine; i++) {
73 cmInstance.indentLine(i); 76 cmInstance.indentLine(i, "smart");
74 } 77 }
75 }); 78 });
76}); 79});
diff --git a/imports/codemirror/lib/util/javascript-hint.js b/imports/codemirror/lib/util/javascript-hint.js
index 4e88a7e4..2b904a51 100755..100644
--- a/imports/codemirror/lib/util/javascript-hint.js
+++ b/imports/codemirror/lib/util/javascript-hint.js
@@ -15,37 +15,81 @@
15 } 15 }
16 return arr.indexOf(item) != -1; 16 return arr.indexOf(item) != -1;
17 } 17 }
18 18
19 CodeMirror.javascriptHint = function(editor) { 19 function scriptHint(editor, keywords, getToken) {
20 // Find the token at the cursor 20 // Find the token at the cursor
21 var cur = editor.getCursor(), token = editor.getTokenAt(cur), tprop = token; 21 var cur = editor.getCursor(), token = getToken(editor, cur), tprop = token;
22 // If it's not a 'word-style' token, ignore the token. 22 // If it's not a 'word-style' token, ignore the token.
23 if (!/^[\w$_]*$/.test(token.string)) { 23 if (!/^[\w$_]*$/.test(token.string)) {
24 token = tprop = {start: cur.ch, end: cur.ch, string: "", state: token.state, 24 token = tprop = {start: cur.ch, end: cur.ch, string: "", state: token.state,
25 className: token.string == "." ? "property" : null}; 25 className: token.string == "." ? "property" : null};
26 } 26 }
27 // I