aboutsummaryrefslogtreecommitdiff
path: root/imports/codemirror/lib/util/foldcode.js
diff options
context:
space:
mode:
Diffstat (limited to 'imports/codemirror/lib/util/foldcode.js')
-rw-r--r--imports/codemirror/lib/util/foldcode.js36
1 files changed, 23 insertions, 13 deletions
diff --git a/imports/codemirror/lib/util/foldcode.js b/imports/codemirror/lib/util/foldcode.js
index b700d860..02cfb50a 100644
--- a/imports/codemirror/lib/util/foldcode.js
+++ b/imports/codemirror/lib/util/foldcode.js
@@ -1,9 +1,9 @@
1// the tagRangeFinder function is 1// the tagRangeFinder function is
2// Copyright (C) 2011 by Daniel Glazman <daniel@glazman.org> 2// Copyright (C) 2011 by Daniel Glazman <daniel@glazman.org>
3// released under the MIT license (../../LICENSE) like the rest of CodeMirror 3// released under the MIT license (../../LICENSE) like the rest of CodeMirror
4CodeMirror.tagRangeFinder = function(cm, line) { 4CodeMirror.tagRangeFinder = function(cm, line, hideEnd) {
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"; 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"; 6 var nameChar = nameStartChar + "\-\:\.0-9\\u00B7\\u0300-\\u036F\\u203F-\\u2040";
7 var xmlNAMERegExp = new RegExp("^[" + nameStartChar + "][" + nameChar + "]*"); 7 var xmlNAMERegExp = new RegExp("^[" + nameStartChar + "][" + nameChar + "]*");
8 8
9 var lineText = cm.getLine(line); 9 var lineText = cm.getLine(line);
@@ -36,8 +36,10 @@ CodeMirror.tagRangeFinder = function(cm, line) {
36 var slash = lt.lastIndexOf("/", gt); 36 var slash = lt.lastIndexOf("/", gt);
37 if (-1 != slash && slash < gt) { 37 if (-1 != slash && slash < gt) {
38 var str = lineText.substr(slash, gt - slash + 1); 38 var str = lineText.substr(slash, gt - slash + 1);
39 if (!str.match( /\/\s*\>/ )) // yep, that's the end of empty tag 39 if (!str.match( /\/\s*\>/ )) { // yep, that's the end of empty tag
40 return l+1; 40 if (hideEnd === true) l++;
41 return l;
42 }
41 } 43 }
42 } 44 }
43 l++; 45 l++;
@@ -95,8 +97,10 @@ CodeMirror.tagRangeFinder = function(cm, line) {
95 depth--; 97 depth--;
96 else 98 else
97 depth++; 99 depth++;
98 if (!depth) 100 if (!depth) {
99 return l+1; 101 if (hideEnd === true) l++;
102 return l;
103 }
100 } 104 }
101 } 105 }
102 l++; 106 l++;
@@ -105,11 +109,16 @@ CodeMirror.tagRangeFinder = function(cm, line) {
105 } 109 }
106}; 110};
107 111
108CodeMirror.braceRangeFinder = function(cm, line) { 112CodeMirror.braceRangeFinder = function(cm, line, hideEnd) {
109 var lineText = cm.getLine(line); 113 var lineText = cm.getLine(line), at = lineText.length, startChar, tokenType;
110 var startChar = lineText.lastIndexOf("{"); 114 for (;;) {
111 if (startChar < 0 || lineText.lastIndexOf("}") > startChar) return; 115 var found = lineText.lastIndexOf("{", at);
112 var tokenType = cm.getTokenAt({line: line, ch: startChar}).className; 116 if (found < 0) break;
117 tokenType = cm.getTokenAt({line: line, ch: found}).className;
118 if (!/^(comment|string)/.test(tokenType)) { startChar = found; break; }
119 at = found - 1;
120 }
121 if (startChar == null || lineText.lastIndexOf("}") > startChar) return;
113 var count = 1, lastLine = cm.lineCount(), end; 122 var count = 1, lastLine = cm.lineCount(), end;
114 outer: for (var i = line + 1; i < lastLine; ++i) { 123 outer: for (var i = line + 1; i < lastLine; ++i) {
115 var text = cm.getLine(i), pos = 0; 124 var text = cm.getLine(i), pos = 0;
@@ -127,6 +136,7 @@ CodeMirror.braceRangeFinder = function(cm, line) {
127 } 136 }
128 } 137 }
129 if (end == null || end == line + 1) return; 138 if (end == null || end == line + 1) return;
139 if (hideEnd === true) end++;
130 return end; 140 return end;
131}; 141};
132 142
@@ -144,7 +154,7 @@ CodeMirror.indentRangeFinder = function(cm, line) {
144 return last + 1; 154 return last + 1;
145}; 155};
146 156
147CodeMirror.newFoldFunction = function(rangeFinder, markText) { 157CodeMirror.newFoldFunction = function(rangeFinder, markText, hideEnd) {
148 var folded = []; 158 var folded = [];
149 if (markText == null) markText = '<div style="position: absolute; left: 2px; color:#600">&#x25bc;</div>%N%'; 159 if (markText == null) markText = '<div style="position: absolute; left: 2px; color:#600">&#x25bc;</div>%N%';
150 160
@@ -169,7 +179,7 @@ CodeMirror.newFoldFunction = function(rangeFinder, markText) {
169 folded.splice(known.pos, 1); 179 folded.splice(known.pos, 1);
170 expand(cm, known.region); 180 expand(cm, known.region);
171 } else { 181 } else {
172 var end = rangeFinder(cm, line); 182 var end = rangeFinder(cm, line, hideEnd);
173 if (end == null) return; 183 if (end == null) return;
174 var hidden = []; 184 var hidden = [];
175 for (var i = line + 1; i < end; ++i) { 185 for (var i = line + 1; i < end; ++i) {