Skip to content

Commit

Permalink
[webui] Update CodeMirror JS editor to version 2.22
Browse files Browse the repository at this point in the history
Should fix a whole range of issues...
  • Loading branch information
saschpe committed Mar 16, 2012
1 parent 8db8280 commit 5b4a95f
Show file tree
Hide file tree
Showing 15 changed files with 595 additions and 234 deletions.
246 changes: 160 additions & 86 deletions src/webui/public/javascripts/cm2/codemirror.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/webui/public/javascripts/cm2/mode/clike.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ CodeMirror.defineMode("clike", function(config, parserConfig) {
escaped = !escaped && next == "\\";
}
if (end || !(escaped || multiLineStrings))
state.tokenize = tokenBase;
state.tokenize = null;
return "string";
};
}
Expand All @@ -68,7 +68,7 @@ CodeMirror.defineMode("clike", function(config, parserConfig) {
var maybeEnd = false, ch;
while (ch = stream.next()) {
if (ch == "/" && maybeEnd) {
state.tokenize = tokenBase;
state.tokenize = null;
break;
}
maybeEnd = (ch == "*");
Expand Down
2 changes: 1 addition & 1 deletion src/webui/public/javascripts/cm2/mode/clojure.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ CodeMirror.defineMode("clojure", function (config, mode) {
return {
indentStack: null,
indentation: 0,
mode: false,
mode: false
};
},

Expand Down
203 changes: 203 additions & 0 deletions src/webui/public/javascripts/cm2/mode/ecl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
CodeMirror.defineMode("ecl", function(config) {

function words(str) {
var obj = {}, words = str.split(" ");
for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
return obj;
}

function metaHook(stream, state) {
if (!state.startOfLine) return false;
stream.skipToEnd();
return "meta";
}

function tokenAtString(stream, state) {
var next;
while ((next = stream.next()) != null) {
if (next == '"' && !stream.eat('"')) {
state.tokenize = null;
break;
}
}
return "string";
}

var indentUnit = config.indentUnit;
var keyword = words("abs acos allnodes ascii asin asstring atan atan2 ave case choose choosen choosesets clustersize combine correlation cos cosh count covariance cron dataset dedup define denormalize distribute distributed distribution ebcdic enth error evaluate event eventextra eventname exists exp failcode failmessage fetch fromunicode getisvalid global graph group hash hash32 hash64 hashcrc hashmd5 having if index intformat isvalid iterate join keyunicode length library limit ln local log loop map matched matchlength matchposition matchtext matchunicode max merge mergejoin min nolocal nonempty normalize parse pipe power preload process project pull random range rank ranked realformat recordof regexfind regexreplace regroup rejected rollup round roundup row rowdiff sample set sin sinh sizeof soapcall sort sorted sqrt stepped stored sum table tan tanh thisnode topn tounicode transfer trim truncate typeof ungroup unicodeorder variance which workunit xmldecode xmlencode xmltext xmlunicode");
var variable = words("apply assert build buildindex evaluate fail keydiff keypatch loadxml nothor notify output parallel sequential soapcall wait");
var variable_2 = words("__compressed__ all and any as atmost before beginc++ best between case const counter csv descend encrypt end endc++ endmacro except exclusive expire export extend false few first flat from full function group header heading hole ifblock import in interface joined keep keyed last left limit load local locale lookup macro many maxcount maxlength min skew module named nocase noroot noscan nosort not of only opt or outer overwrite packed partition penalty physicallength pipe quote record relationship repeat return right scan self separator service shared skew skip sql store terminator thor threshold token transform trim true type unicodeorder unsorted validate virtual whole wild within xml xpath");
var variable_3 = words("ascii big_endian boolean data decimal ebcdic integer pattern qstring real record rule set of string token udecimal unicode unsigned varstring varunicode");
var builtin = words("checkpoint deprecated failcode failmessage failure global independent onwarning persist priority recovery stored success wait when");
var blockKeywords = words("catch class do else finally for if switch try while");
var atoms = words("true false null");
var hooks = {"#": metaHook};
var multiLineStrings;
var isOperatorChar = /[+\-*&%=<>!?|\/]/;

var curPunc;

function tokenBase(stream, state) {
var ch = stream.next();
if (hooks[ch]) {
var result = hooks[ch](stream, state);
if (result !== false) return result;
}
if (ch == '"' || ch == "'") {
state.tokenize = tokenString(ch);
return state.tokenize(stream, state);
}
if (/[\[\]{}\(\),;\:\.]/.test(ch)) {
curPunc = ch;
return null
}
if (/\d/.test(ch)) {
stream.eatWhile(/[\w\.]/);
return "number";
}
if (ch == "/") {
if (stream.eat("*")) {
state.tokenize = tokenComment;
return tokenComment(stream, state);
}
if (stream.eat("/")) {
stream.skipToEnd();
return "comment";
}
}
if (isOperatorChar.test(ch)) {
stream.eatWhile(isOperatorChar);
return "operator";
}
stream.eatWhile(/[\w\$_]/);
var cur = stream.current().toLowerCase();
if (keyword.propertyIsEnumerable(cur)) {
if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
return "keyword";
} else if (variable.propertyIsEnumerable(cur)) {
if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
return "variable";
} else if (variable_2.propertyIsEnumerable(cur)) {
if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
return "variable-2";
} else if (variable_3.propertyIsEnumerable(cur)) {
if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
return "variable-3";
} else if (builtin.propertyIsEnumerable(cur)) {
if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
return "builtin";
} else { //Data types are of from KEYWORD##
var i = cur.length - 1;
while(i >= 0 && (!isNaN(cur[i]) || cur[i] == '_'))
--i;

if (i > 0) {
var cur2 = cur.substr(0, i + 1);
if (variable_3.propertyIsEnumerable(cur2)) {
if (blockKeywords.propertyIsEnumerable(cur2)) curPunc = "newstatement";
return "variable-3";
}
}
}
if (atoms.propertyIsEnumerable(cur)) return "atom";
return "word";
}

function tokenString(quote) {
return function(stream, state) {
var escaped = false, next, end = false;
while ((next = stream.next()) != null) {
if (next == quote && !escaped) {end = true; break;}
escaped = !escaped && next == "\\";
}
if (end || !(escaped || multiLineStrings))
state.tokenize = tokenBase;
return "string";
};
}

function tokenComment(stream, state) {
var maybeEnd = false, ch;
while (ch = stream.next()) {
if (ch == "/" && maybeEnd) {
state.tokenize = tokenBase;
break;
}
maybeEnd = (ch == "*");
}
return "comment";
}

function Context(indented, column, type, align, prev) {
this.indented = indented;
this.column = column;
this.type = type;
this.align = align;
this.prev = prev;
}
function pushContext(state, col, type) {
return state.context = new Context(state.indented, col, type, null, state.context);
}
function popContext(state) {
var t = state.context.type;
if (t == ")" || t == "]" || t == "}")
state.indented = state.context.indented;
return state.context = state.context.prev;
}

// Interface

return {
startState: function(basecolumn) {
return {
tokenize: null,
context: new Context((basecolumn || 0) - indentUnit, 0, "top", false),
indented: 0,
startOfLine: true
};
},

token: function(stream, state) {
var ctx = state.context;
if (stream.sol()) {
if (ctx.align == null) ctx.align = false;
state.indented = stream.indentation();
state.startOfLine = true;
}
if (stream.eatSpace()) return null;
curPunc = null;
var style = (state.tokenize || tokenBase)(stream, state);
if (style == "comment" || style == "meta") return style;
if (ctx.align == null) ctx.align = true;

if ((curPunc == ";" || curPunc == ":") && ctx.type == "statement") popContext(state);
else if (curPunc == "{") pushContext(state, stream.column(), "}");
else if (curPunc == "[") pushContext(state, stream.column(), "]");
else if (curPunc == "(") pushContext(state, stream.column(), ")");
else if (curPunc == "}") {
while (ctx.type == "statement") ctx = popContext(state);
if (ctx.type == "}") ctx = popContext(state);
while (ctx.type == "statement") ctx = popContext(state);
}
else if (curPunc == ctx.type) popContext(state);
else if (ctx.type == "}" || ctx.type == "top" || (ctx.type == "statement" && curPunc == "newstatement"))
pushContext(state, stream.column(), "statement");
state.startOfLine = false;
return style;
},

indent: function(state, textAfter) {
if (state.tokenize != tokenBase && state.tokenize != null) return 0;
var ctx = state.context, firstChar = textAfter && textAfter.charAt(0);
if (ctx.type == "statement" && firstChar == "}") ctx = ctx.prev;
var closing = firstChar == ctx.type;
if (ctx.type == "statement") return ctx.indented + (firstChar == "{" ? 0 : indentUnit);
else if (ctx.align) return ctx.column + (closing ? 0 : 1);
else return ctx.indented + (closing ? 0 : indentUnit);
},

electricChars: "{}"
};
});

CodeMirror.defineMIME("text/x-ecl");
2 changes: 1 addition & 1 deletion src/webui/public/javascripts/cm2/mode/gfm.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ CodeMirror.defineMode("gfm", function(config, parserConfig) {
"c++": "text/x-c++src",
java: "text/x-java",
csharp: "text/x-csharp",
"c#": "text/x-csharp",
"c#": "text/x-csharp"
};

// make this lazy so that we don't need to load GFM last
Expand Down
42 changes: 20 additions & 22 deletions src/webui/public/javascripts/cm2/mode/go.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ CodeMirror.defineMode("go", function(config, parserConfig) {
var keywords = {
"break":true, "case":true, "chan":true, "const":true, "continue":true,
"default":true, "defer":true, "else":true, "fallthrough":true, "for":true,
"func":true, "go":true, "goto":true, "if":true, "import":true, "interface":true,
"map":true, "package":true, "range":true, "return":true, "select":true,
"struct":true, "switch":true, "type":true, "var":true, "bool":true, "byte":true,
"complex64":true, "complex128":true, "float32":true, "float64":true,
"int8":true, "int16":true, "int32":true, "int64":true, "string":true,
"uint8":true, "uint16":true, "uint32":true, "uint64":true, "int":true,
"uint":true, "uintptr":true
"func":true, "go":true, "goto":true, "if":true, "import":true,
"interface":true, "map":true, "package":true, "range":true, "return":true,
"select":true, "struct":true, "switch":true, "type":true, "var":true,
"bool":true, "byte":true, "complex64":true, "complex128":true,
"float32":true, "float64":true, "int8":true, "int16":true, "int32":true,
"int64":true, "string":true, "uint8":true, "uint16":true, "uint32":true,
"uint64":true, "int":true, "uint":true, "uintptr":true
};

var atoms = {
"true":true, "false":true, "iota":true, "nil":true, "append":true,
"cap":true, "close":true, "complex":true, "copy":true, "imag":true, "len":true,
"make":true, "new":true, "panic":true, "print":true, "println":true,
"real":true, "recover":true
"cap":true, "close":true, "complex":true, "copy":true, "imag":true,
"len":true, "make":true, "new":true, "panic":true, "print":true,
"println":true, "real":true, "recover":true
};

var blockKeywords = {
Expand Down Expand Up @@ -66,7 +66,7 @@ CodeMirror.defineMode("go", function(config, parserConfig) {
stream.eatWhile(/[\w\$_]/);
var cur = stream.current();
if (keywords.propertyIsEnumerable(cur)) {
if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
if (cur == "case" || cur == "default") curPunc = "case";
return "keyword";
}
if (atoms.propertyIsEnumerable(cur)) return "atom";
Expand Down Expand Up @@ -133,6 +133,7 @@ CodeMirror.defineMode("go", function(config, parserConfig) {
if (ctx.align == null) ctx.align = false;
state.indented = stream.indentation();
state.startOfLine = true;
if (ctx.type == "case") ctx.type = "}";
}
if (stream.eatSpace()) return null;
curPunc = null;
Expand All @@ -143,29 +144,26 @@ CodeMirror.defineMode("go", function(config, parserConfig) {
if (curPunc == "{") pushContext(state, stream.column(), "}");
else if (curPunc == "[") pushContext(state, stream.column(), "]");
else if (curPunc == "(") pushContext(state, stream.column(), ")");
else if (curPunc == "}") {
while (ctx.type == "statement") ctx = popContext(state);
if (ctx.type == "}") ctx = popContext(state);
while (ctx.type == "statement") ctx = popContext(state);
}
else if (curPunc == "case") ctx.type = "case"
else if (curPunc == "}" && ctx.type == "}") ctx = popContext(state);
else if (curPunc == ctx.type) popContext(state);
else if (ctx.type == "}" || ctx.type == "top" || (ctx.type == "statement" && curPunc == "newstatement"))
pushContext(state, stream.column(), "statement");
state.startOfLine = false;
return style;
},

indent: function(state, textAfter) {
if (state.tokenize != tokenBase && state.tokenize != null) return 0;
var ctx = state.context, firstChar = textAfter && textAfter.charAt(0);
if (ctx.type == "statement" && firstChar == "}") ctx = ctx.prev;
if (ctx.type == "case" && /^(?:case|default)\b/.test(textAfter)) {
state.context.type = "}";
return ctx.indented;
}
var closing = firstChar == ctx.type;
if (ctx.type == "statement") return ctx.indented;
else if (ctx.align) return ctx.column + (closing ? 0 : 1);
if (ctx.align) return ctx.column + (closing ? 0 : 1);
else return ctx.indented + (closing ? 0 : indentUnit);
},

electricChars: "{}"
electricChars: "{}:"
};
});

Expand Down
7 changes: 5 additions & 2 deletions src/webui/public/javascripts/cm2/mode/less.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ CodeMirror.defineMode("less", function(config) {
return tokenSComment(stream, state);
}else{
stream.eatWhile(/[\a-zA-Z0-9\-_.]/);
if(stream.peek() == ")" || stream.peek() == "/")return ret("string", "string");//let url(/images/logo.png) without quotes return as string
return ret("number", "unit");
}
}
Expand All @@ -53,7 +54,7 @@ CodeMirror.defineMode("less", function(config) {
else if (/[;{}:\[\]()]/.test(ch)) { //added () char for lesscss original was [;{}:\[\]]
if(ch == ":"){
stream.eatWhile(/[active|hover|link|visited]/);
if( stream.current().match(/[active|hover|link|visited]/)){
if( stream.current().match(/active|hover|link|visited/)){
return ret("tag", "tag");
}else{
return ret(null, ch);
Expand Down Expand Up @@ -85,13 +86,15 @@ CodeMirror.defineMode("less", function(config) {
return ret(null, ch);
}
else {
stream.eatWhile(/[\w\\\-_.%{]/);
stream.eatWhile(/[\w\\\-_.%]/);
if( stream.eat("(") ){ // lesscss
return ret(null, ch);
}else if( stream.current().match(/\-\d|\-.\d/) ){ // lesscss match e.g.: -5px -0.4 etc...
return ret("number", "unit");
}else if( inTagsArray(stream.current()) ){ // lesscss match html tags
return ret("tag", "tag");
}else if( (stream.peek() == ")" || stream.peek() == "/") && stream.current().indexOf('.') !== -1){
return ret("string", "string");//let url(logo.png) without quotes and froward slash return as string
}else{
return ret("variable", "variable");
}
Expand Down

0 comments on commit 5b4a95f

Please sign in to comment.