diff options
author | Jose Antonio Marquez Russo | 2012-02-29 15:41:12 -0800 |
---|---|---|
committer | Jose Antonio Marquez Russo | 2012-02-29 15:41:12 -0800 |
commit | 13aca03d4e0d11729d691db0b7f0d2f2a6899cf6 (patch) | |
tree | dbd17232983247a38bb6b2cea480242bdf3f2422 /imports/codemirror/lib/util/foldcode.js | |
parent | b09956e4a9a35c5588cc7cd1f01efb617cbe0884 (diff) | |
parent | 8fee7d6bdb55ba18f396c3523081b18499fa1e30 (diff) | |
download | ninja-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/foldcode.js')
-rw-r--r--[-rwxr-xr-x] | imports/codemirror/lib/util/foldcode.js | 120 |
1 files changed, 120 insertions, 0 deletions
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 | ||
4 | CodeMirror.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 | |||
1 | CodeMirror.braceRangeFinder = function(cm, line) { | 108 | CodeMirror.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 | ||
133 | CodeMirror.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 | ||
27 | CodeMirror.newFoldFunction = function(rangeFinder, markText) { | 147 | CodeMirror.newFoldFunction = function(rangeFinder, markText) { |
28 | var folded = []; | 148 | var folded = []; |