From c2805e03c84b6e598556fd06d1ede7aaeea7ce9c Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Tue, 6 Mar 2012 16:17:54 -0800 Subject: Squashed commit FileIO-Build-Candidate into Master Fixing issues with HTML and CSS URLs. Adjusted RegEx logic. Also code a mirror update and undo/redo changes were merged into this request. Signed-off-by: Valerio Virgillito --- imports/codemirror/lib/util/foldcode.js | 120 ++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) mode change 100755 => 100644 imports/codemirror/lib/util/foldcode.js (limited to 'imports/codemirror/lib/util/foldcode.js') diff --git a/imports/codemirror/lib/util/foldcode.js b/imports/codemirror/lib/util/foldcode.js old mode 100755 new mode 100644 index 18957792..50268a8b --- a/imports/codemirror/lib/util/foldcode.js +++ b/imports/codemirror/lib/util/foldcode.js @@ -1,3 +1,110 @@ +// the tagRangeFinder function is +// Copyright (C) 2011 by Daniel Glazman +// released under the MIT license (../../LICENSE) like the rest of CodeMirror +CodeMirror.tagRangeFinder = function(cm, line) { + 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"; + var nameChar = nameStartChar + "\-\.0-9\\u00B7\\u0300-\\u036F\\u203F-\\u2040"; + var xmlNAMERegExp = new RegExp("^[" + nameStartChar + "][" + nameChar + "]*"); + + var lineText = cm.getLine(line); + var found = false; + var tag = null; + var pos = 0; + while (!found) { + pos = lineText.indexOf("<", pos); + if (-1 == pos) // no tag on line + return; + if (pos + 1 < lineText.length && lineText[pos + 1] == "/") { // closing tag + pos++; + continue; + } + // ok we weem to have a start tag + if (!lineText.substr(pos + 1).match(xmlNAMERegExp)) { // not a tag name... + pos++; + continue; + } + var gtPos = lineText.indexOf(">", pos + 1); + if (-1 == gtPos) { // end of start tag not in line + var l = line + 1; + var foundGt = false; + var lastLine = cm.lineCount(); + while (l < lastLine && !foundGt) { + var lt = cm.getLine(l); + var gt = lt.indexOf(">"); + if (-1 != gt) { // found a > + foundGt = true; + var slash = lt.lastIndexOf("/", gt); + if (-1 != slash && slash < gt) { + var str = lineText.substr(slash, gt - slash + 1); + if (!str.match( /\/\s*\>/ )) // yep, that's the end of empty tag + return l+1; + } + } + l++; + } + found = true; + } + else { + var slashPos = lineText.lastIndexOf("/", gtPos); + if (-1 == slashPos) { // cannot be empty tag + found = true; + // don't continue + } + else { // empty tag? + // check if really empty tag + var str = lineText.substr(slashPos, gtPos - slashPos + 1); + if (!str.match( /\/\s*\>/ )) { // finally not empty + found = true; + // don't continue + } + } + } + if (found) { + var subLine = lineText.substr(pos + 1); + tag = subLine.match(xmlNAMERegExp); + if (tag) { + // we have an element name, wooohooo ! + tag = tag[0]; + // do we have the close tag on same line ??? + if (-1 != lineText.indexOf("", pos)) // yep + { + found = false; + } + // we don't, so we have a candidate... + } + else + found = false; + } + if (!found) + pos++; + } + + if (found) { + var startTag = "(\\<\\/" + tag + "\\>)|(\\<" + tag + "\\>)|(\\<" + tag + "\s)|(\\<" + tag + "$)"; + var startTagRegExp = new RegExp(startTag, "g"); + var endTag = ""; + var depth = 1; + var l = line + 1; + var lastLine = cm.lineCount(); + while (l < lastLine) { + lineText = cm.getLine(l); + var match = lineText.match(startTagRegExp); + if (match) { + for (var i = 0; i < match.length; i++) { + if (match[i] == endTag) + depth--; + else + depth++; + if (!depth) + return l+1; + } + } + l++; + } + return; + } +}; + CodeMirror.braceRangeFinder = function(cm, line) { var lineText = cm.getLine(line); var startChar = lineText.lastIndexOf("{"); @@ -23,6 +130,19 @@ CodeMirror.braceRangeFinder = function(cm, line) { return end; }; +CodeMirror.indentRangeFinder = function(cm, line) { + var tabSize = cm.getOption("tabSize"); + var myIndent = cm.getLineHandle(line).indentation(tabSize), last; + for (var i = line + 1, end = cm.lineCount(); i < end; ++i) { + var handle = cm.getLineHandle(i); + if (!/^\s*$/.test(handle.text)) { + if (handle.indentation(tabSize) <= myIndent) break; + last = i; + } + } + if (!last) return null; + return last + 1; +}; CodeMirror.newFoldFunction = function(rangeFinder, markText) { var folded = []; -- cgit v1.2.3