|
1 | | -CodeMirror.tagRangeFinder = (function() { |
2 | | - 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"; |
3 | | - var nameChar = nameStartChar + "\-\:\.0-9\\u00B7\\u0300-\\u036F\\u203F-\\u2040"; |
4 | | - var xmlTagStart = new RegExp("<(/?)([" + nameStartChar + "][" + nameChar + "]*)", "g"); |
5 | | - |
6 | | - return function(cm, start) { |
7 | | - var line = start.line, ch = start.ch, lineText = cm.getLine(line); |
8 | | - |
9 | | - function nextLine() { |
10 | | - if (line >= cm.lastLine()) return; |
11 | | - ch = 0; |
12 | | - lineText = cm.getLine(++line); |
13 | | - return true; |
14 | | - } |
15 | | - function toTagEnd() { |
16 | | - for (;;) { |
17 | | - var gt = lineText.indexOf(">", ch); |
18 | | - if (gt == -1) { if (nextLine()) continue; else return; } |
19 | | - var lastSlash = lineText.lastIndexOf("/", gt); |
20 | | - var selfClose = lastSlash > -1 && /^\s*$/.test(lineText.slice(lastSlash + 1, gt)); |
21 | | - ch = gt + 1; |
22 | | - return selfClose ? "selfClose" : "regular"; |
23 | | - } |
24 | | - } |
25 | | - function toNextTag() { |
26 | | - for (;;) { |
27 | | - xmlTagStart.lastIndex = ch; |
28 | | - var found = xmlTagStart.exec(lineText); |
29 | | - if (!found) { if (nextLine()) continue; else return; } |
30 | | - ch = found.index + found[0].length; |
31 | | - return found; |
32 | | - } |
33 | | - } |
34 | | - |
35 | | - var stack = [], startCh; |
36 | | - for (;;) { |
37 | | - var openTag = toNextTag(), end; |
38 | | - if (!openTag || line != start.line || !(end = toTagEnd())) return; |
39 | | - if (!openTag[1] && end != "selfClose") { |
40 | | - stack.push(openTag[2]); |
41 | | - startCh = ch; |
42 | | - break; |
43 | | - } |
44 | | - } |
45 | | - |
46 | | - for (;;) { |
47 | | - var next = toNextTag(), end, tagLine = line, tagCh = ch - (next ? next[0].length : 0); |
48 | | - if (!next || !(end = toTagEnd())) return; |
49 | | - if (end == "selfClose") continue; |
50 | | - if (next[1]) { // closing tag |
51 | | - for (var i = stack.length - 1; i >= 0; --i) if (stack[i] == next[2]) { |
52 | | - stack.length = i; |
53 | | - break; |
54 | | - } |
55 | | - if (!stack.length) return { |
56 | | - from: CodeMirror.Pos(start.line, startCh), |
57 | | - to: CodeMirror.Pos(tagLine, tagCh) |
58 | | - }; |
59 | | - } else { // opening tag |
60 | | - stack.push(next[2]); |
61 | | - } |
62 | | - } |
63 | | - }; |
64 | | -})(); |
65 | | - |
66 | | -CodeMirror.braceRangeFinder = function(cm, start) { |
67 | | - var line = start.line, lineText = cm.getLine(line); |
68 | | - var at = lineText.length, startChar, tokenType; |
69 | | - for (;;) { |
70 | | - var found = lineText.lastIndexOf("{", at); |
71 | | - if (found < start.ch) break; |
72 | | - tokenType = cm.getTokenAt(CodeMirror.Pos(line, found + 1)).type; |
73 | | - if (!/^(comment|string)/.test(tokenType)) { startChar = found; break; } |
74 | | - at = found - 1; |
75 | | - } |
76 | | - if (startChar == null || lineText.lastIndexOf("}") > startChar) return; |
77 | | - var count = 1, lastLine = cm.lineCount(), end, endCh; |
78 | | - outer: for (var i = line + 1; i < lastLine; ++i) { |
79 | | - var text = cm.getLine(i), pos = 0; |
80 | | - for (;;) { |
81 | | - var nextOpen = text.indexOf("{", pos), nextClose = text.indexOf("}", pos); |
82 | | - if (nextOpen < 0) nextOpen = text.length; |
83 | | - if (nextClose < 0) nextClose = text.length; |
84 | | - pos = Math.min(nextOpen, nextClose); |
85 | | - if (pos == text.length) break; |
86 | | - if (cm.getTokenAt(CodeMirror.Pos(i, pos + 1)).type == tokenType) { |
87 | | - if (pos == nextOpen) ++count; |
88 | | - else if (!--count) { end = i; endCh = pos; break outer; } |
89 | | - } |
90 | | - ++pos; |
91 | | - } |
92 | | - } |
93 | | - if (end == null || end == line + 1) return; |
94 | | - return {from: CodeMirror.Pos(line, startChar + 1), |
95 | | - to: CodeMirror.Pos(end, endCh)}; |
96 | | -}; |
97 | | - |
98 | | -CodeMirror.indentRangeFinder = function(cm, start) { |
99 | | - var tabSize = cm.getOption("tabSize"), firstLine = cm.getLine(start.line); |
100 | | - var myIndent = CodeMirror.countColumn(firstLine, null, tabSize); |
101 | | - for (var i = start.line + 1, end = cm.lineCount(); i < end; ++i) { |
102 | | - var curLine = cm.getLine(i); |
103 | | - if (CodeMirror.countColumn(curLine, null, tabSize) < myIndent && |
104 | | - CodeMirror.countColumn(cm.getLine(i-1), null, tabSize) > myIndent) |
105 | | - return {from: CodeMirror.Pos(start.line, firstLine.length), |
106 | | - to: CodeMirror.Pos(i, curLine.length)}; |
107 | | - } |
108 | | -}; |
109 | | - |
110 | 1 | CodeMirror.newFoldFunction = function(rangeFinder, widget) { |
111 | 2 | if (widget == null) widget = "\u2194"; |
112 | 3 | if (typeof widget == "string") { |
|
0 commit comments