summaryrefslogtreecommitdiff
path: root/codemirror_ui/lib/CodeMirror-2.3/lib/util
diff options
context:
space:
mode:
Diffstat (limited to 'codemirror_ui/lib/CodeMirror-2.3/lib/util')
-rw-r--r--codemirror_ui/lib/CodeMirror-2.3/lib/util/closetag.js146
-rw-r--r--codemirror_ui/lib/CodeMirror-2.3/lib/util/dialog.css23
-rw-r--r--codemirror_ui/lib/CodeMirror-2.3/lib/util/dialog.js63
-rw-r--r--codemirror_ui/lib/CodeMirror-2.3/lib/util/foldcode.js196
-rw-r--r--codemirror_ui/lib/CodeMirror-2.3/lib/util/formatting.js297
-rw-r--r--codemirror_ui/lib/CodeMirror-2.3/lib/util/javascript-hint.js134
-rw-r--r--codemirror_ui/lib/CodeMirror-2.3/lib/util/loadmode.js51
-rw-r--r--codemirror_ui/lib/CodeMirror-2.3/lib/util/match-highlighter.js44
-rw-r--r--codemirror_ui/lib/CodeMirror-2.3/lib/util/multiplex.js72
-rw-r--r--codemirror_ui/lib/CodeMirror-2.3/lib/util/overlay.js52
-rw-r--r--codemirror_ui/lib/CodeMirror-2.3/lib/util/pig-hint.js123
-rw-r--r--codemirror_ui/lib/CodeMirror-2.3/lib/util/runmode.js49
-rw-r--r--codemirror_ui/lib/CodeMirror-2.3/lib/util/search.js118
-rw-r--r--codemirror_ui/lib/CodeMirror-2.3/lib/util/searchcursor.js117
-rw-r--r--codemirror_ui/lib/CodeMirror-2.3/lib/util/simple-hint.css16
-rw-r--r--codemirror_ui/lib/CodeMirror-2.3/lib/util/simple-hint.js72
16 files changed, 1573 insertions, 0 deletions
diff --git a/codemirror_ui/lib/CodeMirror-2.3/lib/util/closetag.js b/codemirror_ui/lib/CodeMirror-2.3/lib/util/closetag.js
new file mode 100644
index 0000000..20a43b9
--- /dev/null
+++ b/codemirror_ui/lib/CodeMirror-2.3/lib/util/closetag.js
@@ -0,0 +1,146 @@
+/**
+ * Tag-closer extension for CodeMirror.
+ *
+ * This extension adds a "closeTag" utility function that can be used with key bindings to
+ * insert a matching end tag after the ">" character of a start tag has been typed. It can
+ * also complete "</" if a matching start tag is found. It will correctly ignore signal
+ * characters for empty tags, comments, CDATA, etc.
+ *
+ * The function depends on internal parser state to identify tags. It is compatible with the
+ * following CodeMirror modes and will ignore all others:
+ * - htmlmixed
+ * - xml
+ *
+ * See demos/closetag.html for a usage example.
+ *
+ * @author Nathan Williams <nathan@nlwillia.net>
+ * Contributed under the same license terms as CodeMirror.
+ */
+(function() {
+ /** Option that allows tag closing behavior to be toggled. Default is true. */
+ CodeMirror.defaults['closeTagEnabled'] = true;
+
+ /** Array of tag names to add indentation after the start tag for. Default is the list of block-level html tags. */
+ CodeMirror.defaults['closeTagIndent'] = ['applet', 'blockquote', 'body', 'button', 'div', 'dl', 'fieldset', 'form', 'frameset', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'html', 'iframe', 'layer', 'legend', 'object', 'ol', 'p', 'select', 'table', 'ul'];
+
+ /**
+ * Call during key processing to close tags. Handles the key event if the tag is closed, otherwise throws CodeMirror.Pass.
+ * - cm: The editor instance.
+ * - ch: The character being processed.
+ * - indent: Optional. Omit or pass true to use the default indentation tag list defined in the 'closeTagIndent' option.
+ * Pass false to disable indentation. Pass an array to override the default list of tag names.
+ */
+ CodeMirror.defineExtension("closeTag", function(cm, ch, indent) {
+ if (!cm.getOption('closeTagEnabled')) {
+ throw CodeMirror.Pass;
+ }
+
+ var mode = cm.getOption('mode');
+
+ if (mode == 'text/html') {
+
+ /*
+ * Relevant structure of token:
+ *
+ * htmlmixed
+ * className
+ * state
+ * htmlState
+ * type
+ * context
+ * tagName
+ * mode
+ *
+ * xml
+ * className
+ * state
+ * tagName
+ * type
+ */
+
+ var pos = cm.getCursor();
+ var tok = cm.getTokenAt(pos);
+ var state = tok.state;
+
+ if (state.mode && state.mode != 'html') {
+ throw CodeMirror.Pass; // With htmlmixed, we only care about the html sub-mode.
+ }
+
+ if (ch == '>') {
+ var type = state.htmlState ? state.htmlState.type : state.type; // htmlmixed : xml
+
+ if (tok.className == 'tag' && type == 'closeTag') {
+ throw CodeMirror.Pass; // Don't process the '>' at the end of an end-tag.
+ }
+
+ cm.replaceSelection('>'); // Mode state won't update until we finish the tag.
+ pos = {line: pos.line, ch: pos.ch + 1};
+ cm.setCursor(pos);
+
+ tok = cm.getTokenAt(cm.getCursor());
+ state = tok.state;
+ type = state.htmlState ? state.htmlState.type : state.type; // htmlmixed : xml
+
+ if (tok.className == 'tag' && type != 'selfcloseTag') {
+ var tagName = state.htmlState ? state.htmlState.context.tagName : state.tagName; // htmlmixed : xml
+ if (tagName.length > 0) {
+ insertEndTag(cm, indent, pos, tagName);
+ }
+ return;
+ }
+
+ // Undo the '>' insert and allow cm to handle the key instead.
+ cm.setSelection({line: pos.line, ch: pos.ch - 1}, pos);
+ cm.replaceSelection("");
+
+ } else if (ch == '/') {
+ if (tok.className == 'tag' && tok.string == '<') {
+ var tagName = state.htmlState ? (state.htmlState.context ? state.htmlState.context.tagName : '') : state.context.tagName; // htmlmixed : xml # extra htmlmized check is for '</' edge case
+ if (tagName.length > 0) {
+ completeEndTag(cm, pos, tagName);
+ return;
+ }
+ }
+ }
+
+ }
+
+ throw CodeMirror.Pass; // Bubble if not handled
+ });
+
+ function insertEndTag(cm, indent, pos, tagName) {
+ if (shouldIndent(cm, indent, tagName)) {
+ cm.replaceSelection('\n\n</' + tagName + '>', 'end');
+ cm.indentLine(pos.line + 1);
+ cm.indentLine(pos.line + 2);
+ cm.setCursor({line: pos.line + 1, ch: cm.getLine(pos.line + 1).length});
+ } else {
+ cm.replaceSelection('</' + tagName + '>');
+ cm.setCursor(pos);
+ }
+ }
+
+ function shouldIndent(cm, indent, tagName) {
+ if (typeof indent == 'undefined' || indent == null || indent == true) {
+ indent = cm.getOption('closeTagIndent');
+ }
+ if (!indent) {
+ indent = [];
+ }
+ return indexOf(indent, tagName.toLowerCase()) != -1;
+ }
+
+ // C&P from codemirror.js...would be nice if this were visible to utilities.
+ function indexOf(collection, elt) {
+ if (collection.indexOf) return collection.indexOf(elt);
+ for (var i = 0, e = collection.length; i < e; ++i)
+ if (collection[i] == elt) return i;
+ return -1;
+ }
+
+ function completeEndTag(cm, pos, tagName) {
+ cm.replaceSelection('/' + tagName + '>');
+ cm.setCursor({line: pos.line, ch: pos.ch + tagName.length + 2 });
+ }
+
+})();
diff --git a/codemirror_ui/lib/CodeMirror-2.3/lib/util/dialog.css b/codemirror_ui/lib/CodeMirror-2.3/lib/util/dialog.css
new file mode 100644
index 0000000..4cb467e
--- /dev/null
+++ b/codemirror_ui/lib/CodeMirror-2.3/lib/util/dialog.css
@@ -0,0 +1,23 @@
+.CodeMirror-dialog {
+ position: relative;
+}
+
+.CodeMirror-dialog > div {
+ position: absolute;
+ top: 0; left: 0; right: 0;
+ background: white;
+ border-bottom: 1px solid #eee;
+ z-index: 15;
+ padding: .1em .8em;
+ overflow: hidden;
+ color: #333;
+}
+
+.CodeMirror-dialog input {
+ border: none;
+ outline: none;
+ background: transparent;
+ width: 20em;
+ color: inherit;
+ font-family: monospace;
+}
diff --git a/codemirror_ui/lib/CodeMirror-2.3/lib/util/dialog.js b/codemirror_ui/lib/CodeMirror-2.3/lib/util/dialog.js
new file mode 100644
index 0000000..8950bf0
--- /dev/null
+++ b/codemirror_ui/lib/CodeMirror-2.3/lib/util/dialog.js
@@ -0,0 +1,63 @@
+// Open simple dialogs on top of an editor. Relies on dialog.css.
+
+(function() {
+ function dialogDiv(cm, template) {
+ var wrap = cm.getWrapperElement();
+ var dialog = wrap.insertBefore(document.createElement("div"), wrap.firstChild);
+ dialog.className = "CodeMirror-dialog";
+ dialog.innerHTML = '<div>' + template + '</div>';
+ return dialog;
+ }
+
+ CodeMirror.defineExtension("openDialog", function(template, callback) {
+ var dialog = dialogDiv(this, template);
+ var closed = false, me = this;
+ function close() {
+ if (closed) return;
+ closed = true;
+ dialog.parentNode.removeChild(dialog);
+ }
+ var inp = dialog.getElementsByTagName("input")[0];
+ if (inp) {
+ CodeMirror.connect(inp, "keydown", function(e) {
+ if (e.keyCode == 13 || e.keyCode == 27) {
+ CodeMirror.e_stop(e);
+ close();
+ me.focus();
+ if (e.keyCode == 13) callback(inp.value);
+ }
+ });
+ inp.focus();
+ CodeMirror.connect(inp, "blur", close);
+ }
+ return close;
+ });
+
+ CodeMirror.defineExtension("openConfirm", function(template, callbacks) {
+ var dialog = dialogDiv(this, template);
+ var buttons = dialog.getElementsByTagName("button");
+ var closed = false, me = this, blurring = 1;
+ function close() {
+ if (closed) return;
+ closed = true;
+ dialog.parentNode.removeChild(dialog);
+ me.focus();
+ }
+ buttons[0].focus();
+ for (var i = 0; i < buttons.length; ++i) {
+ var b = buttons[i];
+ (function(callback) {
+ CodeMirror.connect(b, "click", function(e) {
+ CodeMirror.e_preventDefault(e);
+ close();
+ if (callback) callback(me);
+ });
+ })(callbacks[i]);
+ CodeMirror.connect(b, "blur", function() {
+ --blurring;
+ setTimeout(function() { if (blurring <= 0) close(); }, 200);
+ });
+ CodeMirror.connect(b, "focus", function() { ++blurring; });
+ }
+ });
+})(); \ No newline at end of file
diff --git a/codemirror_ui/lib/CodeMirror-2.3/lib/util/foldcode.js b/codemirror_ui/lib/CodeMirror-2.3/lib/util/foldcode.js
new file mode 100644
index 0000000..02cfb50
--- /dev/null
+++ b/codemirror_ui/lib/CodeMirror-2.3/lib/util/foldcode.js
@@ -0,0 +1,196 @@
+// the tagRangeFinder function is
+// Copyright (C) 2011 by Daniel Glazman <daniel@glazman.org>
+// released under the MIT license (../../LICENSE) like the rest of CodeMirror
+CodeMirror.tagRangeFinder = function(cm, line, hideEnd) {
+ 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
+ if (hideEnd === true) l++;
+ return l;
+ }
+ }
+ }
+ 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("</" + tag + ">", 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 = "</" + tag + ">";
+ 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) {
+ if (hideEnd === true) l++;
+ return l;
+ }
+ }
+ }
+ l++;
+ }
+ return;
+ }
+};
+
+CodeMirror.braceRangeFinder = function(cm, line, hideEnd) {
+ var lineText = cm.getLine(line), at = lineText.length, startChar, tokenType;
+ for (;;) {
+ var found = lineText.lastIndexOf("{", at);
+ if (found < 0) break;
+ tokenType = cm.getTokenAt({line: line, ch: found}).className;
+ if (!/^(comment|string)/.test(tokenType)) { startChar = found; break; }
+ at = found - 1;
+ }
+ if (startChar == null || lineText.lastIndexOf("}") > startChar) return;
+ var count = 1, lastLine = cm.lineCount(), end;
+ outer: for (var i = line + 1; i < lastLine; ++i) {
+ var text = cm.getLine(i), pos = 0;
+ for (;;) {
+ var nextOpen = text.indexOf("{", pos), nextClose = text.indexOf("}", pos);
+ if (nextOpen < 0) nextOpen = text.length;
+ if (nextClose < 0) nextClose = text.length;
+ pos = Math.min(nextOpen, nextClose);
+ if (pos == text.length) break;
+ if (cm.getTokenAt({line: i, ch: pos + 1}).className == tokenType) {
+ if (pos == nextOpen) ++count;
+ else if (!--count) { end = i; break outer; }
+ }
+ ++pos;
+ }
+ }
+ if (end == null || end == line + 1) return;
+ if (hideEnd === true) end++;
+ 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, hideEnd) {
+ var folded = [];
+ if (markText == null) markText = '<div style="position: absolute; left: 2px; color:#600">&#x25bc;</div>%N%';
+
+ function isFolded(cm, n) {
+ for (var i = 0; i < folded.length; ++i) {
+ var start = cm.lineInfo(folded[i].start);
+ if (!start) folded.splice(i--, 1);
+ else if (start.line == n) return {pos: i, region: folded[i]};
+ }
+ }
+
+ function expand(cm, region) {
+ cm.clearMarker(region.start);
+ for (var i = 0; i < region.hidden.length; ++i)
+ cm.showLine(region.hidden[i]);
+ }
+
+ return function(cm, line) {
+ cm.operation(function() {
+ var known = isFolded(cm, line);
+ if (known) {
+ folded.splice(known.pos, 1);
+ expand(cm, known.region);
+ } else {
+ var end = rangeFinder(cm, line, hideEnd);
+ if (end == null) return;
+ var hidden = [];
+ for (var i = line + 1; i < end; ++i) {
+ var handle = cm.hideLine(i);
+ if (handle) hidden.push(handle);
+ }
+ var first = cm.setMarker(line, markText);
+ var region = {start: first, hidden: hidden};
+ cm.onDeleteLine(first, function() { expand(cm, region); });
+ folded.push(region);
+ }
+ });
+ };
+};
diff --git a/codemirror_ui/lib/CodeMirror-2.3/lib/util/formatting.js b/codemirror_ui/lib/CodeMirror-2.3/lib/util/formatting.js
new file mode 100644
index 0000000..3a1a987
--- /dev/null
+++ b/codemirror_ui/lib/CodeMirror-2.3/lib/util/formatting.js
@@ -0,0 +1,297 @@
+// ============== Formatting extensions ============================
+// A common storage for all mode-specific formatting features
+if (!CodeMirror.modeExtensions) CodeMirror.modeExtensions = {};
+
+// Returns the extension of the editor's current mode
+CodeMirror.defineExtension("getModeExt", function () {
+ var mname = CodeMirror.resolveMode(this.getOption("mode")).name;
+ var ext = CodeMirror.modeExtensions[mname];
+ if (!ext) throw new Error("No extensions found for mode " + mname);
+ return ext;
+});
+
+// If the current mode is 'htmlmixed', returns the extension of a mode located at
+// the specified position (can be htmlmixed, css or javascript). Otherwise, simply
+// returns the extension of the editor's current mode.
+CodeMirror.defineExtension("getModeExtAtPos", function (pos) {
+ var token = this.getTokenAt(pos);
+ if (token && token.state && token.state.mode)
+ return CodeMirror.modeExtensions[token.state.mode == "html" ? "htmlmixed" : token.state.mode];
+ else
+ return this.getModeExt();
+});
+
+// Comment/uncomment the specified range
+CodeMirror.defineExtension("commentRange", function (isComment, from, to) {
+ var curMode = this.getModeExtAtPos(this.getCursor());
+ if (isComment) { // Comment range
+ var commentedText = this.getRange(from, to);
+ this.replaceRange(curMode.commentStart + this.getRange(from, to) + curMode.commentEnd
+ , from, to);
+ if (from.line == to.line && from.ch == to.ch) { // An empty comment inserted - put cursor inside
+ this.setCursor(from.line, from.ch + curMode.commentStart.length);
+ }
+ }
+ else { // Uncomment range
+ var selText = this.getRange(from, to);
+ var startIndex = selText.indexOf(curMode.commentStart);
+ var endIndex = selText.lastIndexOf(curMode.commentEnd);
+ if (startIndex > -1 && endIndex > -1 && endIndex > startIndex) {
+ // Take string till comment start
+ selText = selText.substr(0, startIndex)
+ // From comment start till comment end
+ + selText.substring(startIndex + curMode.commentStart.length, endIndex)
+ // From comment end till string end
+ + selText.substr(endIndex + curMode.commentEnd.length);
+ }
+ this.replaceRange(selText, from, to);
+ }
+});
+
+// Applies automatic mode-aware indentation to the specified range
+CodeMirror.defineExtension("autoIndentRange", function (from, to) {
+ var cmInstance = this;
+ this.operation(function () {
+ for (var i = from.line; i <= to.line; i++) {
+ cmInstance.indentLine(i, "smart");
+ }
+ });
+});
+
+// Applies automatic formatting to the specified range
+CodeMirror.defineExtension("autoFormatRange", function (from, to) {
+ var absStart = this.indexFromPos(from);
+ var absEnd = this.indexFromPos(to);
+ // Insert additional line breaks where necessary according to the
+ // mode's syntax
+ var res = this.getModeExt().autoFormatLineBreaks(this.getValue(), absStart, absEnd);
+ var cmInstance = this;
+
+ // Replace and auto-indent the range
+ this.operation(function () {
+ cmInstance.replaceRange(res, from, to);
+ var startLine = cmInstance.posFromIndex(absStart).line;
+ var endLine = cmInstance.posFromIndex(absStart + res.length).line;
+ for (var i = startLine; i <= endLine; i++) {
+ cmInstance.indentLine(i, "smart");
+ }
+ });
+});
+
+// Define extensions for a few modes
+
+CodeMirror.modeExtensions["css"] = {
+ commentStart: "/*",
+ commentEnd: "*/",
+ wordWrapChars: [";", "\\{", "\\}"],
+ autoFormatLineBreaks: function (text, startPos, endPos) {
+ text = text.substring(startPos, endPos);
+ return text.replace(new RegExp("(;|\\{|\\})([^\r\n])", "g"), "$1\n$2");
+ }
+};
+
+CodeMirror.modeExtensions["javascript"] = {
+ commentStart: "/*",
+ commentEnd: "*/",
+ wordWrapChars: [";", "\\{", "\\}"],
+
+ getNonBreakableBlocks: function (text) {
+ var nonBreakableRegexes = [
+ new RegExp("for\\s*?\\(([\\s\\S]*?)\\)"),
+ new RegExp("'([\\s\\S]*?)('|$)"),
+ new RegExp("\"([\\s\\S]*?)(\"|$)"),
+ new RegExp("//.*([\r\n]|$)")
+ ];
+ var nonBreakableBlocks = new Array();
+ for (var i = 0; i < nonBreakableRegexes.length; i++) {
+ var curPos = 0;
+ while (curPos < text.length) {
+ var m = text.substr(curPos).match(nonBreakableRegexes[i]);
+ if (m != null) {
+ nonBreakableBlocks.push({
+ start: curPos + m.index,
+ end: curPos + m.index + m[0].length
+ });
+ curPos += m.index + Math.max(1, m[0].length);
+ }
+ else { // No more matches
+ break;
+ }
+ }
+ }
+ nonBreakableBlocks.sort(function (a, b) {
+ return a.start - b.start;
+ });
+
+ return nonBreakableBlocks;
+ },
+
+ autoFormatLineBreaks: function (text, startPos, endPos) {
+ text = text.substring(startPos, endPos);
+ var curPos = 0;
+ var reLinesSplitter = new RegExp("(;|\\{|\\})([^\r\n])", "g");
+ var nonBreakableBlocks = this.getNonBreakableBlocks(text);
+ if (nonBreakableBlocks != null) {
+ var res = "";
+ for (var i = 0; i < nonBreakableBlocks.length; i++) {
+ if (nonBreakableBlocks[i].start > curPos) { // Break lines till the block
+ res += text.substring(curPos, nonBreakableBlocks[i].start).replace(reLinesSplitter, "$1\n$2");
+ curPos = nonBreakableBlocks[i].start;
+ }
+ if (nonBreakableBlocks[i].start <= curPos
+ && nonBreakableBlocks[i].end >= curPos) { // Skip non-breakable block
+ res += text.substring(curPos, nonBreakableBlocks[i].end);
+ curPos = nonBreakableBlocks[i].end;
+ }
+ }
+ if (curPos < text.length - 1) {
+ res += text.substr(curPos).replace(reLinesSplitter, "$1\n$2");
+ }
+ return res;
+ }
+ else {
+ return text.replace(reLinesSplitter, "$1\n$2");
+ }
+ }
+};
+
+CodeMirror.modeExtensions["xml"] = {
+ commentStart: "<!--",
+ commentEnd: "-->",
+ wordWrapChars: [">"],
+
+ autoFormatLineBreaks: function (text, startPos, endPos) {
+ text = text.substring(startPos, endPos);
+ var lines = text.split("\n");
+ var reProcessedPortion = new RegExp("(^\\s*?<|^[^<]*?)(.+)(>\\s*?$|[^>]*?$)");
+ var reOpenBrackets = new RegExp("<", "g");
+ var reCloseBrackets = new RegExp("(>)([^\r\n])", "g");
+ for (var i = 0; i < lines.length; i++) {
+ var mToProcess = lines[i].match(reProcessedPortion);
+ if (mToProcess != null && mToProcess.length > 3) { // The line starts with whitespaces and ends with whitespaces
+ lines[i] = mToProcess[1]
+ + mToProcess[2].replace(reOpenBrackets, "\n$&").replace(reCloseBrackets, "$1\n$2")
+ + mToProcess[3];
+ continue;
+ }
+ }
+
+ return lines.join("\n");
+ }
+};
+
+CodeMirror.modeExtensions["htmlmixed"] = {
+ commentStart: "<!--",
+ commentEnd: "-->",
+ wordWrapChars: [">", ";", "\\{", "\\}"],
+
+ getModeInfos: function (text, absPos) {
+ var modeInfos = new Array();
+ modeInfos[0] =
+ {
+ pos: 0,
+ modeExt: CodeMirror.modeExtensions["xml"],
+ modeName: "xml"
+ };
+
+ var modeMatchers = new Array();
+ modeMatchers[0] =
+ {
+ regex: new RegExp("<style[^>]*>([\\s\\S]*?)(</style[^>]*>|$)", "i"),
+ modeExt: CodeMirror.modeExtensions["css"],
+ modeName: "css"
+ };
+ modeMatchers[1] =
+ {
+ regex: new RegExp("<script[^>]*>([\\s\\S]*?)(</script[^>]*>|$)", "i"),
+ modeExt: CodeMirror.modeExtensions["javascript"],
+ modeName: "javascript"
+ };
+
+ var lastCharPos = (typeof (absPos) !== "undefined" ? absPos : text.length - 1);
+ // Detect modes for the entire text
+ for (var i = 0; i < modeMatchers.length; i++) {
+ var curPos = 0;
+ while (curPos <= lastCharPos) {
+ var m = text.substr(curPos).match(modeMatchers[i].regex);
+ if (m != null) {
+ if (m.length > 1 && m[1].length > 0) {
+ // Push block begin pos
+ var blockBegin = curPos + m.index + m[0].indexOf(m[1]);
+ modeInfos.push(
+ {
+ pos: blockBegin,
+ modeExt: modeMatchers[i].modeExt,
+ modeName: modeMatchers[i].modeName
+ });
+ // Push block end pos
+ modeInfos.push(
+ {
+ pos: blockBegin + m[1].length,
+ modeExt: modeInfos[0].modeExt,
+ modeName: modeInfos[0].modeName
+ });
+ curPos += m.index + m[0].length;
+ continue;
+ }
+ else {
+ curPos += m.index + Math.max(m[0].length, 1);
+ }
+ }
+ else { // No more matches
+ break;
+ }
+ }
+ }
+ // Sort mode infos
+ modeInfos.sort(function sortModeInfo(a, b) {
+ return a.pos - b.pos;
+ });
+
+ return modeInfos;
+ },
+
+ autoFormatLineBreaks: function (text, startPos, endPos) {
+ var modeInfos = this.getModeInfos(text);
+ var reBlockStartsWithNewline = new RegExp("^\\s*?\n");
+ var reBlockEndsWithNewline = new RegExp("\n\\s*?$");
+ var res = "";
+ // Use modes info to break lines correspondingly
+ if (modeInfos.length > 1) { // Deal with multi-mode text
+ for (var i = 1; i <= modeInfos.length; i++) {
+ var selStart = modeInfos[i - 1].pos;
+ var selEnd = (i < modeInfos.length ? modeInfos[i].pos : endPos);
+
+ if (selStart >= endPos) { // The block starts later than the needed fragment
+ break;
+ }
+ if (selStart < startPos) {
+ if (selEnd <= startPos) { // The block starts earlier than the needed fragment
+ continue;
+ }
+ selStart = startPos;
+ }
+ if (selEnd > endPos) {
+ selEnd = endPos;
+ }
+ var textPortion = text.substring(selStart, selEnd);
+ if (modeInfos[i - 1].modeName != "xml") { // Starting a CSS or JavaScript block
+ if (!reBlockStartsWithNewline.test(textPortion)
+ && selStart > 0) { // The block does not start with a line break
+ textPortion = "\n" + textPortion;
+ }
+ if (!reBlockEndsWithNewline.test(textPortion)
+ && selEnd < text.length - 1) { // The block does not end with a line break
+ textPortion += "\n";
+ }
+ }
+ res += modeInfos[i - 1].modeExt.autoFormatLineBreaks(textPortion);
+ }
+ }
+ else { // Single-mode text
+ res = modeInfos[0].modeExt.autoFormatLineBreaks(text.substring(startPos, endPos));
+ }
+
+ return res;
+ }
+};
diff --git a/codemirror_ui/lib/CodeMirror-2.3/lib/util/javascript-hint.js b/codemirror_ui/lib/CodeMirror-2.3/lib/util/javascript-hint.js
new file mode 100644
index 0000000..2117e5a
--- /dev/null
+++ b/codemirror_ui/lib/CodeMirror-2.3/lib/util/javascript-hint.js
@@ -0,0 +1,134 @@
+(function () {
+ function forEach(arr, f) {
+ for (var i = 0, e = arr.length; i < e; ++i) f(arr[i]);
+ }
+
+ function arrayContains(arr, item) {
+ if (!Array.prototype.indexOf) {
+ var i = arr.length;
+ while (i--) {
+ if (arr[i] === item) {
+ return true;
+ }
+ }
+ return false;
+ }
+ return arr.indexOf(item) != -1;
+ }
+
+ function scriptHint(editor, keywords, getToken) {
+ // Find the token at the cursor
+ var cur = editor.getCursor(), token = getToken(editor, cur), tprop = token;
+ // If it's not a 'word-style' token, ignore the token.
+ if (!/^[\w$_]*$/.test(token.string)) {
+ token = tprop = {start: cur.ch, end: cur.ch, string: "", state: token.state,
+ className: token.string == "." ? "property" : null};
+ }
+ // If it is a property, find out what it is a property of.
+ while (tprop.className == "property") {
+ tprop = getToken(editor, {line: cur.line, ch: tprop.start});
+ if (tprop.string != ".") return;
+ tprop = getToken(editor, {line: cur.line, ch: tprop.start});
+ if (tprop.string == ')') {
+ var level = 1;
+ do {
+ tprop = getToken(editor, {line: cur.line, ch: tprop.start});
+ switch (tprop.string) {
+ case ')': level++; break;
+ case '(': level--; break;
+ default: break;
+ }
+ } while (level > 0)
+ tprop = getToken(editor, {line: cur.line, ch: tprop.start});
+ if (tprop.className == 'variable')
+ tprop.className = 'function';
+ else return; // no clue
+ }
+ if (!context) var context = [];
+ context.push(tprop);
+ }
+ return {list: getCompletions(token, context, keywords),
+ from: {line: cur.line, ch: token.start},
+ to: {line: cur.line, ch: token.end}};
+ }
+
+ CodeMirror.javascriptHint = function(editor) {
+ return scriptHint(editor, javascriptKeywords,
+ function (e, cur) {return e.getTokenAt(cur);});
+ }
+
+ function getCoffeeScriptToken(editor, cur) {
+ // This getToken, it is for coffeescript, imitates the behavior of
+ // getTokenAt method in javascript.js, that is, returning "property"
+ // type and treat "." as indepenent token.
+ var token = editor.getTokenAt(cur);
+ if (cur.ch == token.start + 1 && token.string.charAt(0) == '.') {
+ token.end = token.start;
+ token.string = '.';
+ token.className = "property";
+ }
+ else if (/^\.[\w$_]*$/.test(token.string)) {
+ token.className = "property";
+ token.start++;
+ token.string = token.string.replace(/\./, '');
+ }
+ return token;
+ }
+
+ CodeMirror.coffeescriptHint = function(editor) {
+ return scriptHint(editor, coffeescriptKeywords, getCoffeeScriptToken);
+ }
+
+ var stringProps = ("charAt charCodeAt indexOf lastIndexOf substring substr slice trim trimLeft trimRight " +
+ "toUpperCase toLowerCase split concat match replace search").split(" ");
+ var arrayProps = ("length concat join splice push pop shift unshift slice reverse sort indexOf " +
+ "lastIndexOf every some filter forEach map reduce reduceRight ").split(" ");
+ var funcProps = "prototype apply call bind".split(" ");
+ var javascriptKeywords = ("break case catch continue debugger default delete do else false finally for function " +
+ "if in instanceof new null return switch throw true try typeof var void while with").split(" ");
+ var coffeescriptKeywords = ("and break catch class continue delete do else extends false finally for " +
+ "if in instanceof isnt new no not null of off on or return switch then throw true try typeof until void while with yes").split(" ");
+
+ function getCompletions(token, context, keywords) {
+ var found = [], start = token.string;
+ function maybeAdd(str) {
+ if (str.indexOf(start) == 0 && !arrayContains(found, str)) found.push(str);
+ }
+ function gatherCompletions(obj) {
+ if (typeof obj == "string") forEach(stringProps, maybeAdd);
+ else if (obj instanceof Array) forEach(arrayProps, maybeAdd);
+ else if (obj instanceof Function) forEach(funcProps, maybeAdd);
+ for (var name in obj) maybeAdd(name);
+ }
+
+ if (context) {
+ // If this is a property, see if it belongs to some object we can
+ // find in the current environment.
+ var obj = context.pop(), base;
+ if (obj.className == "variable")
+ base = window[obj.string];
+ else if (obj.className == "string")
+ base = "";
+ else if (obj.className == "atom")
+ base = 1;
+ else if (obj.className == "function") {
+ if (window.jQuery != null && (obj.string == '$' || obj.string == 'jQuery') &&
+ (typeof window.jQuery == 'function'))
+ base = window.jQuery();
+ else if (window._ != null && (obj.string == '_') && (typeof window._ == 'function'))
+ base = window._();
+ }
+ while (base != null && context.length)
+ base = base[context.pop().string];
+ if (base != null) gatherCompletions(base);
+ }
+ else {
+ // If not, just look in the window object and any local scope
+ // (reading into JS mode internals to get at the local variables)
+ for (var v = token.state.localVars; v; v = v.next) maybeAdd(v.name);
+ gatherCompletions(window);
+ forEach(keywords, maybeAdd);
+ }
+ return found;
+ }
+})();
diff --git a/codemirror_ui/lib/CodeMirror-2.3/lib/util/loadmode.js b/codemirror_ui/lib/CodeMirror-2.3/lib/util/loadmode.js
new file mode 100644
index 0000000..48d5a7a
--- /dev/null
+++ b/codemirror_ui/lib/CodeMirror-2.3/lib/util/loadmode.js
@@ -0,0 +1,51 @@
+(function() {
+ if (!CodeMirror.modeURL) CodeMirror.modeURL = "../mode/%N/%N.js";
+
+ var loading = {};
+ function splitCallback(cont, n) {
+ var countDown = n;
+ return function() { if (--countDown == 0) cont(); }
+ }
+ function ensureDeps(mode, cont) {
+ var deps = CodeMirror.modes[mode].dependencies;
+ if (!deps) return cont();
+ var missing = [];
+ for (var i = 0; i < deps.length; ++i) {
+ if (!CodeMirror.modes.hasOwnProperty(deps[i]))
+ missing.push(deps[i]);
+ }
+ if (!missing.length) return cont();
+ var split = splitCallback(cont, missing.length);
+ for (var i = 0; i < missing.length; ++i)
+ CodeMirror.requireMode(missing[i], split);
+ }
+
+ CodeMirror.requireMode = function(mode, cont) {
+ if (typeof mode != "string") mode = mode.name;
+ if (CodeMirror.modes.hasOwnProperty(mode)) return ensureDeps(mode, cont);
+ if (loading.hasOwnProperty(mode)) return loading[mode].push(cont);
+
+ var script = document.createElement("script");
+ script.src = CodeMirror.modeURL.replace(/%N/g, mode);
+ var others = document.getElementsByTagName("script")[0];
+ others.parentNode.insertBefore(script, others);
+ var list = loading[mode] = [cont];
+ var count = 0, poll = setInterval(function() {
+ if (++count > 100) return clearInterval(poll);
+ if (CodeMirror.modes.hasOwnProperty(mode)) {
+ clearInterval(poll);
+ loading[mode] = null;
+ ensureDeps(mode, function() {
+ for (var i = 0; i < list.length; ++i) list[i]();
+ });
+ }
+ }, 200);
+ };
+
+ CodeMirror.autoLoadMode = function(instance, mode) {
+ if (!CodeMirror.modes.hasOwnProperty(mode))
+ CodeMirror.requireMode(mode, function() {
+ instance.setOption("mode", instance.getOption("mode"));
+ });
+ };
+}());
diff --git a/codemirror_ui/lib/CodeMirror-2.3/lib/util/match-highlighter.js b/codemirror_ui/lib/CodeMirror-2.3/lib/util/match-highlighter.js
new file mode 100644
index 0000000..59098ff
--- /dev/null
+++ b/codemirror_ui/lib/CodeMirror-2.3/lib/util/match-highlighter.js
@@ -0,0 +1,44 @@
+// Define match-highlighter commands. Depends on searchcursor.js
+// Use by attaching the following function call to the onCursorActivity event:
+ //myCodeMirror.matchHighlight(minChars);
+// And including a special span.CodeMirror-matchhighlight css class (also optionally a separate one for .CodeMirror-focused -- see demo matchhighlighter.html)
+
+(function() {
+ var DEFAULT_MIN_CHARS = 2;
+
+ function MatchHighlightState() {
+ this.marked = [];
+ }
+ function getMatchHighlightState(cm) {
+ return cm._matchHighlightState || (cm._matchHighlightState = new MatchHighlightState());
+ }
+
+ function clearMarks(cm) {
+ var state = getMatchHighlightState(cm);
+ for (var i = 0; i < state.marked.length; ++i)
+ state.marked[i].clear();
+ state.marked = [];
+ }
+
+ function markDocument(cm, className, minChars) {
+ clearMarks(cm);
+ minChars = (typeof minChars !== 'undefined' ? minChars : DEFAULT_MIN_CHARS);
+ if (cm.somethingSelected() && cm.getSelection().replace(/^\s+|\s+$/g, "").length >= minChars) {
+ var state = getMatchHighlightState(cm);
+ var query = cm.getSelection();
+ cm.operation(function() {
+ if (cm.lineCount() < 2000) { // This is too expensive on big documents.
+ for (var cursor = cm.getSearchCursor(query); cursor.findNext();) {
+ //Only apply matchhighlight to the matches other than the one actually selected
+ if (!(cursor.from().line === cm.getCursor(true).line && cursor.from().ch === cm.getCursor(true).ch))
+ state.marked.push(cm.markText(cursor.from(), cursor.to(), className));
+ }
+ }
+ });
+ }
+ }
+
+ CodeMirror.defineExtension("matchHighlight", function(className, minChars) {
+ markDocument(this, className, minChars);
+ });
+})();
diff --git a/codemirror_ui/lib/CodeMirror-2.3/lib/util/multiplex.js b/codemirror_ui/lib/CodeMirror-2.3/lib/util/multiplex.js
new file mode 100644
index 0000000..822ee62
--- /dev/null
+++ b/codemirror_ui/lib/CodeMirror-2.3/lib/util/multiplex.js
@@ -0,0 +1,72 @@
+CodeMirror.multiplexingMode = function(outer /*, others */) {
+ // Others should be {open, close, mode [, delimStyle]} objects
+ var others = Array.prototype.slice.call(arguments, 1);
+ var n_others = others.length;
+
+ return {
+ startState: function() {
+ return {
+ outer: CodeMirror.startState(outer),
+ innerActive: null,
+ inner: null
+ };
+ },
+
+ copyState: function(state) {
+ return {
+ outer: CodeMirror.copyState(outer, state.outer),
+ innerActive: state.innerActive,
+ inner: state.innerActive && CodeMirror.copyState(state.innerActive.mode, state.inner)
+ };
+ },
+
+ token: function(stream, state) {
+ if (!state.innerActive) {
+ for (var i = 0; i < n_others; ++i) {
+ var other = others[i];
+ if (stream.match(other.open)) {
+ state.innerActive = other;
+ state.inner = CodeMirror.startState(other.mode);
+ return other.delimStyle;
+ }
+ }
+ var outerToken = outer.token(stream, state.outer);
+ var cur = stream.current();
+ for (var i = 0; i < n_others; ++i) {
+ var other = others[i], found = cur.indexOf(other.open);
+ if (found > -1) {
+ stream.backUp(cur.length - found);
+ cur = cur.slice(0, found);
+ }
+ }
+ return outerToken;
+ } else {
+ var curInner = state.innerActive;
+ if (stream.match(curInner.close)) {
+ state.innerActive = state.inner = null;
+ return curInner.delimStyle;
+ }
+ var innerToken = curInner.mode.token(stream, state.inner);
+ var cur = stream.current(), found = cur.indexOf(curInner.close);
+ if (found > -1) stream.backUp(cur.length - found);
+ return innerToken;
+ }
+ },
+
+ indent: function(state, textAfter) {
+ var mode = state.innerActive || outer;
+ if (!mode.indent) return CodeMirror.Pass;
+ return mode.indent(state.innerActive ? state.inner : state.outer, textAfter);
+ },
+
+ compareStates: function(a, b) {
+ if (a.innerActive != b.innerActive) return false;
+ var mode = a.innerActive || outer;
+ if (!mode.compareStates) return CodeMirror.Pass;
+ return mode.compareStates(a.innerActive ? a.inner : a.outer,
+ b.innerActive ? b.inner : b.outer);
+ },
+
+ electricChars: outer.electricChars
+ };
+};
diff --git a/codemirror_ui/lib/CodeMirror-2.3/lib/util/overlay.js b/codemirror_ui/lib/CodeMirror-2.3/lib/util/overlay.js
new file mode 100644
index 0000000..1d5df6c
--- /dev/null
+++ b/codemirror_ui/lib/CodeMirror-2.3/lib/util/overlay.js
@@ -0,0 +1,52 @@
+// Utility function that allows modes to be combined. The mode given
+// as the base argument takes care of most of the normal mode
+// functionality, but a second (typically simple) mode is used, which
+// can override the style of text. Both modes get to parse all of the
+// text, but when both assign a non-null style to a piece of code, the
+// overlay wins, unless the combine argument was true, in which case
+// the styles are combined.
+
+// overlayParser is the old, deprecated name
+CodeMirror.overlayMode = CodeMirror.overlayParser = function(base, overlay, combine) {
+ return {
+ startState: function() {
+ return {
+ base: CodeMirror.startState(base),
+ overlay: CodeMirror.startState(overlay),
+ basePos: 0, baseCur: null,
+ overlayPos: 0, overlayCur: null
+ };
+ },
+ copyState: function(state) {
+ return {
+ base: CodeMirror.copyState(base, state.base),
+ overlay: CodeMirror.copyState(overlay, state.overlay),
+ basePos: state.basePos, baseCur: null,
+ overlayPos: state.overlayPos, overlayCur: null
+ };
+ },
+
+ token: function(stream, state) {
+ if (stream.start == state.basePos) {
+ state.baseCur = base.token(stream, state.base);
+ state.basePos = stream.pos;
+ }
+ if (stream.start == state.overlayPos) {
+ stream.pos = stream.start;
+ state.overlayCur = overlay.token(stream, state.overlay);
+ state.overlayPos = stream.pos;
+ }
+ stream.pos = Math.min(state.basePos, state.overlayPos);
+ if (stream.eol()) state.basePos = state.overlayPos = 0;
+
+ if (state.overlayCur == null) return state.baseCur;
+ if (state.baseCur != null && combine) return state.baseCur + " " + state.overlayCur;
+ else return state.overlayCur;
+ },
+
+ indent: base.indent && function(state, textAfter) {
+ return base.indent(state.base, textAfter);
+ },
+ electricChars: base.electricChars
+ };
+};
diff --git a/codemirror_ui/lib/CodeMirror-2.3/lib/util/pig-hint.js b/codemirror_ui/lib/CodeMirror-2.3/lib/util/pig-hint.js
new file mode 100644
index 0000000..233b72b
--- /dev/null
+++ b/codemirror_ui/lib/CodeMirror-2.3/lib/util/pig-hint.js
@@ -0,0 +1,123 @@
+(function () {
+ function forEach(arr, f) {
+ for (var i = 0, e = arr.length; i < e; ++i) f(arr[i]);
+ }
+
+ function arrayContains(arr, item) {
+ if (!Array.prototype.indexOf) {
+ var i = arr.length;
+ while (i--) {
+ if (arr[i] === item) {
+ return true;
+ }
+ }
+ return false;
+ }
+ return arr.indexOf(item) != -1;
+ }
+
+ function scriptHint(editor, keywords, getToken) {
+ // Find the token at the cursor
+ var cur = editor.getCursor(), token = getToken(editor, cur), tprop = token;
+ // If it's not a 'word-style' token, ignore the token.
+
+ if (!/^[\w$_]*$/.test(token.string)) {
+ token = tprop = {start: cur.ch, end: cur.ch, string: "", state: token.state,
+ className: token.string == ":" ? "pig-type" : null};
+ }
+
+ if (!context) var context = [];
+ context.push(tprop);
+
+ completionList = getCompletions(token, context);
+ completionList = completionList.sort();
+ //prevent autocomplete for last word, instead show dropdown with one word
+ if(completionList.length == 1) {
+ completionList.push(" ");
+ }
+
+ return {list: completionList,
+ from: {line: cur.line, ch: token.start},
+ to: {line: cur.line, ch: token.end}};
+ }
+
+ CodeMirror.pigHint = function(editor) {
+ return scriptHint(editor, pigKeywordsU, function (e, cur) {return e.getTokenAt(cur);});
+ }
+
+ function toTitleCase(str) {
+ return str.replace(/(?:^|\s)\w/g, function(match) {
+ return match.toUpperCase();
+ });
+ }
+
+ var pigKeywords = "VOID IMPORT RETURNS DEFINE LOAD FILTER FOREACH ORDER CUBE DISTINCT COGROUP "
+ + "JOIN CROSS UNION SPLIT INTO IF OTHERWISE ALL AS BY USING INNER OUTER ONSCHEMA PARALLEL "
+ + "PARTITION GROUP AND OR NOT GENERATE FLATTEN ASC DESC IS STREAM THROUGH STORE MAPREDUCE "
+ + "SHIP CACHE INPUT OUTPUT STDERROR STDIN STDOUT LIMIT SAMPLE LEFT RIGHT FULL EQ GT LT GTE LTE "
+ + "NEQ MATCHES TRUE FALSE";
+ var pigKeywordsU = pigKeywords.split(" ");
+ var pigKeywordsL = pigKeywords.toLowerCase().split(" ");
+
+ var pigTypes = "BOOLEAN INT LONG FLOAT DOUBLE CHARARRAY BYTEARRAY BAG TUPLE MAP";
+ var pigTypesU = pigTypes.split(" ");
+ var pigTypesL = pigTypes.toLowerCase().split(" ");
+
+ var pigBuiltins = "ABS ACOS ARITY ASIN ATAN AVG BAGSIZE BINSTORAGE BLOOM BUILDBLOOM CBRT CEIL "
+ + "CONCAT COR COS COSH COUNT COUNT_STAR COV CONSTANTSIZE CUBEDIMENSIONS DIFF DISTINCT DOUBLEABS "
+ + "DOUBLEAVG DOUBLEBASE DOUBLEMAX DOUBLEMIN DOUBLEROUND DOUBLESUM EXP FLOOR FLOATABS FLOATAVG "
+ + "FLOATMAX FLOATMIN FLOATROUND FLOATSUM GENERICINVOKER INDEXOF INTABS INTAVG INTMAX INTMIN "
+ + "INTSUM INVOKEFORDOUBLE INVOKEFORFLOAT INVOKEFORINT INVOKEFORLONG INVOKEFORSTRING INVOKER "
+ + "ISEMPTY JSONLOADER JSONMETADATA JSONSTORAGE LAST_INDEX_OF LCFIRST LOG LOG10 LOWER LONGABS "
+ + "LONGAVG LONGMAX LONGMIN LONGSUM MAX MIN MAPSIZE MONITOREDUDF NONDETERMINISTIC OUTPUTSCHEMA "
+ + "PIGSTORAGE PIGSTREAMING RANDOM REGEX_EXTRACT REGEX_EXTRACT_ALL REPLACE ROUND SIN SINH SIZE "
+ + "SQRT STRSPLIT SUBSTRING SUM STRINGCONCAT STRINGMAX STRINGMIN STRINGSIZE TAN TANH TOBAG "
+ + "TOKENIZE TOMAP TOP TOTUPLE TRIM TEXTLOADER TUPLESIZE UCFIRST UPPER UTF8STORAGECONVERTER";
+ var pigBuiltinsU = pigBuiltins.split(" ").join("() ").split(" ");
+ var pigBuiltinsL = pigBuiltins.toLowerCase().split(" ").join("() ").split(" ");
+ var pigBuiltinsC = ("BagSize BinStorage Bloom BuildBloom ConstantSize CubeDimensions DoubleAbs "
+ + "DoubleAvg DoubleBase DoubleMax DoubleMin DoubleRound DoubleSum FloatAbs FloatAvg FloatMax "
+ + "FloatMin FloatRound FloatSum GenericInvoker IntAbs IntAvg IntMax IntMin IntSum "
+ + "InvokeForDouble InvokeForFloat InvokeForInt InvokeForLong InvokeForString Invoker "
+ + "IsEmpty JsonLoader JsonMetadata JsonStorage LongAbs LongAvg LongMax LongMin LongSum MapSize "
+ + "MonitoredUDF Nondeterministic OutputSchema PigStorage PigStreaming StringConcat StringMax "
+ + "StringMin StringSize TextLoader TupleSize Utf8StorageConverter").split(" ").join("() ").split(" ");
+
+ function getCompletions(token, context) {
+ var found = [], start = token.string;
+ function maybeAdd(str) {
+ if (str.indexOf(start) == 0 && !arrayContains(found, str)) found.push(str);
+ }
+
+ function gatherCompletions(obj) {
+ if(obj == ":") {
+ forEach(pigTypesL, maybeAdd);
+ }
+ else {
+ forEach(pigBuiltinsU, maybeAdd);
+ forEach(pigBuiltinsL, maybeAdd);
+ forEach(pigBuiltinsC, maybeAdd);
+ forEach(pigTypesU, maybeAdd);
+ forEach(pigTypesL, maybeAdd);
+ forEach(pigKeywordsU, maybeAdd);
+ forEach(pigKeywordsL, maybeAdd);
+ }
+ }
+
+ if (context) {
+ // If this is a property, see if it belongs to some object we can
+ // find in the current environment.
+ var obj = context.pop(), base;
+
+ if (obj.className == "pig-word")
+ base = obj.string;
+ else if(obj.className == "pig-type")
+ base = ":" + obj.string;
+
+ while (base != null && context.length)
+ base = base[context.pop().string];
+ if (base != null) gatherCompletions(base);
+ }
+ return found;
+ }
+})();
diff --git a/codemirror_ui/lib/CodeMirror-2.3/lib/util/runmode.js b/codemirror_ui/lib/CodeMirror-2.3/lib/util/runmode.js
new file mode 100644
index 0000000..fc58d85
--- /dev/null
+++ b/codemirror_ui/lib/CodeMirror-2.3/lib/util/runmode.js
@@ -0,0 +1,49 @@
+CodeMirror.runMode = function(string, modespec, callback, options) {
+ var mode = CodeMirror.getMode(CodeMirror.defaults, modespec);
+ var isNode = callback.nodeType == 1;
+ var tabSize = (options && options.tabSize) || CodeMirror.defaults.tabSize;
+ if (isNode) {
+ var node = callback, accum = [], col = 0;
+ callback = function(text, style) {
+ if (text == "\n") {
+ accum.push("<br>");
+ col = 0;
+ return;
+ }
+ var escaped = "";
+ // HTML-escape and replace tabs
+ for (var pos = 0;;) {
+ var idx = text.indexOf("\t", pos);
+ if (idx == -1) {
+ escaped += CodeMirror.htmlEscape(text.slice(pos));
+ col += text.length - pos;
+ break;
+ } else {
+ col += idx - pos;
+ escaped += CodeMirror.htmlEscape(text.slice(pos, idx));
+ var size = tabSize - col % tabSize;
+ col += size;
+ for (var i = 0; i < size; ++i) escaped += " ";
+ pos = idx + 1;
+ }
+ }
+
+ if (style)
+ accum.push("<span class=\"cm-" + CodeMirror.htmlEscape(style) + "\">" + escaped + "</span>");
+ else
+ accum.push(escaped);
+ }
+ }
+ var lines = CodeMirror.splitLines(string), state = CodeMirror.startState(mode);
+ for (var i = 0, e = lines.length; i < e; ++i) {
+ if (i) callback("\n");
+ var stream = new CodeMirror.StringStream(lines[i]);
+ while (!stream.eol()) {
+ var style = mode.token(stream, state);
+ callback(stream.current(), style, i, stream.start);
+ stream.start = stream.pos;
+ }
+ }
+ if (isNode)
+ node.innerHTML = accum.join("");
+};
diff --git a/codemirror_ui/lib/CodeMirror-2.3/lib/util/search.js b/codemirror_ui/lib/CodeMirror-2.3/lib/util/search.js
new file mode 100644
index 0000000..c5a2bcc
--- /dev/null
+++ b/codemirror_ui/lib/CodeMirror-2.3/lib/util/search.js
@@ -0,0 +1,118 @@
+// Define search commands. Depends on dialog.js or another
+// implementation of the openDialog method.
+
+// Replace works a little oddly -- it will do the replace on the next
+// Ctrl-G (or whatever is bound to findNext) press. You prevent a
+// replace by making sure the match is no longer selected when hitting
+// Ctrl-G.
+
+(function() {
+ function SearchState() {
+ this.posFrom = this.posTo = this.query = null;
+ this.marked = [];
+ }
+ function getSearchState(cm) {
+ return cm._searchState || (cm._searchState = new SearchState());
+ }
+ function getSearchCursor(cm, query, pos) {
+ // Heuristic: if the query string is all lowercase, do a case insensitive search.
+ return cm.getSearchCursor(query, pos, typeof query == "string" && query == query.toLowerCase());
+ }
+ function dialog(cm, text, shortText, f) {
+ if (cm.openDialog) cm.openDialog(text, f);
+ else f(prompt(shortText, ""));
+ }
+ function confirmDialog(cm, text, shortText, fs) {
+ if (cm.openConfirm) cm.openConfirm(text, fs);
+ else if (confirm(shortText)) fs[0]();
+ }
+ function parseQuery(query) {
+ var isRE = query.match(/^\/(.*)\/([a-z]*)$/);
+ return isRE ? new RegExp(isRE[1], isRE[2].indexOf("i") == -1 ? "" : "i") : query;
+ }
+ var queryDialog =
+ 'Search: <input type="text" style="width: 10em"/> <span style="color: #888">(Use /re/ syntax for regexp search)</span>';
+ function doSearch(cm, rev) {
+ var state = getSearchState(cm);
+ if (state.query) return findNext(cm, rev);
+ dialog(cm, queryDialog, "Search for:", function(query) {
+ cm.operation(function() {
+ if (!query || state.query) return;
+ state.query = parseQuery(query);
+ if (cm.lineCount() < 2000) { // This is too expensive on big documents.
+ for (var cursor = getSearchCursor(cm, query); cursor.findNext();)
+ state.marked.push(cm.markText(cursor.from(), cursor.to(), "CodeMirror-searching"));
+ }
+ state.posFrom = state.posTo = cm.getCursor();
+ findNext(cm, rev);
+ });
+ });
+ }
+ function findNext(cm, rev) {cm.operation(function() {
+ var state = getSearchState(cm);
+ var cursor = getSearchCursor(cm, state.query, rev ? state.posFrom : state.posTo);
+ if (!cursor.find(rev)) {
+ cursor = getSearchCursor(cm, state.query, rev ? {line: cm.lineCount() - 1} : {line: 0, ch: 0});
+ if (!cursor.find(rev)) return;
+ }
+ cm.setSelection(cursor.from(), cursor.to());
+ state.posFrom = cursor.from(); state.posTo = cursor.to();
+ })}
+ function clearSearch(cm) {cm.operation(function() {
+ var state = getSearchState(cm);
+ if (!state.query) return;
+ state.query = null;
+ for (var i = 0; i < state.marked.length; ++i) state.marked[i].clear();
+ state.marked.length = 0;
+ })}
+
+ var replaceQueryDialog =
+ 'Replace: <input type="text" style="width: 10em"/> <span style="color: #888">(Use /re/ syntax for regexp search)</span>';
+ var replacementQueryDialog = 'With: <input type="text" style="width: 10em"/>';
+ var doReplaceConfirm = "Replace? <button>Yes</button> <button>No</button> <button>Stop</button>";
+ function replace(cm, all) {
+ dialog(cm, replaceQueryDialog, "Replace:", function(query) {
+ if (!query) return;
+ query = parseQuery(query);
+ dialog(cm, replacementQueryDialog, "Replace with:", function(text) {
+ if (all) {
+ cm.compoundChange(function() { cm.operation(function() {
+ for (var cursor = getSearchCursor(cm, query); cursor.findNext();) {
+ if (typeof query != "string") {
+ var match = cm.getRange(cursor.from(), cursor.to()).match(query);
+ cursor.replace(text.replace(/\$(\d)/, function(w, i) {return match[i];}));
+ } else cursor.replace(text);
+ }
+ })});
+ } else {
+ clearSearch(cm);
+ var cursor = getSearchCursor(cm, query, cm.getCursor());
+ function advance() {
+ var start = cursor.from(), match;
+ if (!(match = cursor.findNext())) {
+ cursor = getSearchCursor(cm, query);
+ if (!(match = cursor.findNext()) ||
+ (start && cursor.from().line == start.line && cursor.from().ch == start.ch)) return;
+ }
+ cm.setSelection(cursor.from(), cursor.to());
+ confirmDialog(cm, doReplaceConfirm, "Replace?",
+ [function() {doReplace(match);}, advance]);
+ }
+ function doReplace(match) {
+ cursor.replace(typeof query == "string" ? text :
+ text.replace(/\$(\d)/, function(w, i) {return match[i];}));
+ advance();
+ }
+ advance();
+ }
+ });
+ });
+ }
+
+ CodeMirror.commands.find = function(cm) {clearSearch(cm); doSearch(cm);};
+ CodeMirror.commands.findNext = doSearch;
+ CodeMirror.commands.findPrev = function(cm) {doSearch(cm, true);};
+ CodeMirror.commands.clearSearch = clearSearch;
+ CodeMirror.commands.replace = replace;
+ CodeMirror.commands.replaceAll = function(cm) {replace(cm, true);};
+})();
diff --git a/codemirror_ui/lib/CodeMirror-2.3/lib/util/searchcursor.js b/codemirror_ui/lib/CodeMirror-2.3/lib/util/searchcursor.js
new file mode 100644
index 0000000..ec3f73c
--- /dev/null
+++ b/codemirror_ui/lib/CodeMirror-2.3/lib/util/searchcursor.js
@@ -0,0 +1,117 @@
+(function(){
+ function SearchCursor(cm, query, pos, caseFold) {
+ this.atOccurrence = false; this.cm = cm;
+ if (caseFold == null && typeof query == "string") caseFold = false;
+
+ pos = pos ? cm.clipPos(pos) : {line: 0, ch: 0};
+ this.pos = {from: pos, to: pos};
+
+ // The matches method is filled in based on the type of query.
+ // It takes a position and a direction, and returns an object
+ // describing the next occurrence of the query, or null if no
+ // more matches were found.
+ if (typeof query != "string") // Regexp match
+ this.matches = function(reverse, pos) {
+ if (reverse) {
+ var line = cm.getLine(pos.line).slice(0, pos.ch), match = line.match(query), start = 0;
+ while (match) {
+ var ind = line.indexOf(match[0]);
+ start += ind;
+ line = line.slice(ind + 1);
+ var newmatch = line.match(query);
+ if (newmatch) match = newmatch;
+ else break;
+ start++;
+ }
+ }
+ else {
+ var line = cm.getLine(pos.line).slice(pos.ch), match = line.match(query),
+ start = match && pos.ch + line.indexOf(match[0]);
+ }
+ if (match)
+ return {from: {line: pos.line, ch: start},
+ to: {line: pos.line, ch: start + match[0].length},
+ match: match};
+ };
+ else { // String query
+ if (caseFold) query = query.toLowerCase();
+ var fold = caseFold ? function(str){return str.toLowerCase();} : function(str){return str;};
+ var target = query.split("\n");
+ // Different methods for single-line and multi-line queries
+ if (target.length == 1)
+ this.matches = function(reverse, pos) {
+ var line = fold(cm.getLine(pos.line)), len = query.length, match;
+ if (reverse ? (pos.ch >= len && (match = line.lastIndexOf(query, pos.ch - len)) != -1)
+ : (match = line.indexOf(query, pos.ch)) != -1)
+ return {from: {line: pos.line, ch: match},
+ to: {line: pos.line, ch: match + len}};
+ };
+ else
+ this.matches = function(reverse, pos) {
+ var ln = pos.line, idx = (reverse ? target.length - 1 : 0), match = target[idx], line = fold(cm.getLine(ln));
+ var offsetA = (reverse ? line.indexOf(match) + match.length : line.lastIndexOf(match));
+ if (reverse ? offsetA >= pos.ch || offsetA != match.length
+ : offsetA <= pos.ch || offsetA != line.length - match.length)
+ return;
+ for (;;) {
+ if (reverse ? !ln : ln == cm.lineCount() - 1) return;
+ line = fold(cm.getLine(ln += reverse ? -1 : 1));
+ match = target[reverse ? --idx : ++idx];
+ if (idx > 0 && idx < target.length - 1) {
+ if (line != match) return;
+ else continue;
+ }
+ var offsetB = (reverse ? line.lastIndexOf(match) : line.indexOf(match) + match.length);
+ if (reverse ? offsetB != line.length - match.length : offsetB != match.length)
+ return;
+ var start = {line: pos.line, ch: offsetA}, end = {line: ln, ch: offsetB};
+ return {from: reverse ? end : start, to: reverse ? start : end};
+ }
+ };
+ }
+ }
+
+ SearchCursor.prototype = {
+ findNext: function() {return this.find(false);},
+ findPrevious: function() {return this.find(true);},
+
+ find: function(reverse) {
+ var self = this, pos = this.cm.clipPos(reverse ? this.pos.from : this.pos.to);
+ function savePosAndFail(line) {
+ var pos = {line: line, ch: 0};
+ self.pos = {from: pos, to: pos};
+ self.atOccurrence = false;
+ return false;
+ }
+
+ for (;;) {
+ if (this.pos = this.matches(reverse, pos)) {
+ this.atOccurrence = true;
+ return this.pos.match || true;
+ }
+ if (reverse) {
+ if (!pos.line) return savePosAndFail(0);
+ pos = {line: pos.line-1, ch: this.cm.getLine(pos.line-1).length};
+ }
+ else {
+ var maxLine = this.cm.lineCount();
+ if (pos.line == maxLine - 1) return savePosAndFail(maxLine);
+ pos = {line: pos.line+1, ch: 0};
+ }
+ }
+ },
+
+ from: function() {if (this.atOccurrence) return this.pos.from;},
+ to: function() {if (this.atOccurrence) return this.pos.to;},
+
+ replace: function(newText) {
+ var self = this;
+ if (this.atOccurrence)
+ self.pos.to = this.cm.replaceRange(newText, self.pos.from, self.pos.to);
+ }
+ };
+
+ CodeMirror.defineExtension("getSearchCursor", function(query, pos, caseFold) {
+ return new SearchCursor(this, query, pos, caseFold);
+ });
+})();
diff --git a/codemirror_ui/lib/CodeMirror-2.3/lib/util/simple-hint.css b/codemirror_ui/lib/CodeMirror-2.3/lib/util/simple-hint.css
new file mode 100644
index 0000000..4387cb9
--- /dev/null
+++ b/codemirror_ui/lib/CodeMirror-2.3/lib/util/simple-hint.css
@@ -0,0 +1,16 @@
+.CodeMirror-completions {
+ position: absolute;
+ z-index: 10;
+ overflow: hidden;
+ -webkit-box-shadow: 2px 3px 5px rgba(0,0,0,.2);
+ -moz-box-shadow: 2px 3px 5px rgba(0,0,0,.2);
+ box-shadow: 2px 3px 5px rgba(0,0,0,.2);
+}
+.CodeMirror-completions select {
+ background: #fafafa;
+ outline: none;
+ border: none;
+ padding: 0;
+ margin: 0;
+ font-family: monospace;
+}
diff --git a/codemirror_ui/lib/CodeMirror-2.3/lib/util/simple-hint.js b/codemirror_ui/lib/CodeMirror-2.3/lib/util/simple-hint.js
new file mode 100644
index 0000000..7decd58
--- /dev/null
+++ b/codemirror_ui/lib/CodeMirror-2.3/lib/util/simple-hint.js
@@ -0,0 +1,72 @@
+(function() {
+ CodeMirror.simpleHint = function(editor, getHints) {
+ // We want a single cursor position.
+ if (editor.somethingSelected()) return;
+ var result = getHints(editor);
+ if (!result || !result.list.length) return;
+ var completions = result.list;
+ function insert(str) {
+ editor.replaceRange(str, result.from, result.to);
+ }
+ // When there is only one completion, use it directly.
+ if (completions.length == 1) {insert(completions[0]); return true;}
+
+ // Build the select widget
+ var complete = document.createElement("div");
+ complete.className = "CodeMirror-completions";
+ var sel = complete.appendChild(document.createElement("select"));
+ // Opera doesn't move the selection when pressing up/down in a
+ // multi-select, but it does properly support the size property on
+ // single-selects, so no multi-select is necessary.
+ if (!window.opera) sel.multiple = true;
+ for (var i = 0; i < completions.length; ++i) {
+ var opt = sel.appendChild(document.createElement("option"));
+ opt.appendChild(document.createTextNode(completions[i]));
+ }
+ sel.firstChild.selected = true;
+ sel.size = Math.min(10, completions.length);
+ var pos = editor.cursorCoords();
+ complete.style.left = pos.x + "px";
+ complete.style.top = pos.yBot + "px";
+ document.body.appendChild(complete);
+ // If we're at the edge of the screen, then we want the menu to appear on the left of the cursor.
+ var winW = window.innerWidth || Math.max(document.body.offsetWidth, document.documentElement.offsetWidth);
+ if(winW - pos.x < sel.clientWidth)
+ complete.style.left = (pos.x - sel.clientWidth) + "px";
+ // Hack to hide the scrollbar.
+ if (completions.length <= 10)
+ complete.style.width = (sel.clientWidth - 1) + "px";
+
+ var done = false;
+ function close() {
+ if (done) return;
+ done = true;
+ complete.parentNode.removeChild(complete);
+ }
+ function pick() {
+ insert(completions[sel.selectedIndex]);
+ close();
+ setTimeout(function(){editor.focus();}, 50);
+ }
+ CodeMirror.connect(sel, "blur", close);
+ CodeMirror.connect(sel, "keydown", function(event) {
+ var code = event.keyCode;
+ // Enter
+ if (code == 13) {CodeMirror.e_stop(event); pick();}
+ // Escape
+ else if (code == 27) {CodeMirror.e_stop(event); close(); editor.focus();}
+ else if (code != 38 && code != 40) {
+ close(); editor.focus();
+ // Pass the event to the CodeMirror instance so that it can handle things like backspace properly.
+ editor.triggerOnKeyDown(event);
+ setTimeout(function(){CodeMirror.simpleHint(editor, getHints);}, 50);
+ }
+ });
+ CodeMirror.connect(sel, "dblclick", pick);
+
+ sel.focus();
+ // Opera sometimes ignores focusing a freshly created node
+ if (window.opera) setTimeout(function(){if (!done) sel.focus();}, 100);
+ return true;
+ };
+})();