1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-28 17:49:41 +02:00

CodeMirror dependency upgraded to v5.32.0

For handling Markdown and Code section types
This commit is contained in:
Harvey Kandola 2017-12-18 13:10:51 +00:00
parent 3337db6b27
commit 0336f84a83
351 changed files with 3408 additions and 1945 deletions

28
gui/public/codemirror/mode/r/r.js vendored Executable file → Normal file
View file

@ -108,13 +108,23 @@ CodeMirror.defineMode("r", function(config) {
};
}
var ALIGN_YES = 1, ALIGN_NO = 2, BRACELESS = 4
function push(state, type, stream) {
state.ctx = {type: type,
indent: state.indent,
align: null,
flags: 0,
column: stream.column(),
prev: state.ctx};
}
function setFlag(state, flag) {
var ctx = state.ctx
state.ctx = {type: ctx.type,
indent: ctx.indent,
flags: ctx.flags | flag,
column: ctx.column,
prev: ctx.prev}
}
function pop(state) {
state.indent = state.ctx.indent;
state.ctx = state.ctx.prev;
@ -125,22 +135,22 @@ CodeMirror.defineMode("r", function(config) {
return {tokenize: tokenBase,
ctx: {type: "top",
indent: -config.indentUnit,
align: false},
flags: ALIGN_NO},
indent: 0,
afterIdent: false};
},
token: function(stream, state) {
if (stream.sol()) {
if (state.ctx.align == null) state.ctx.align = false;
if ((state.ctx.flags & 3) == 0) state.ctx.flags |= ALIGN_NO
if (state.ctx.flags & BRACELESS) pop(state)
state.indent = stream.indentation();
}
if (stream.eatSpace()) return null;
var style = state.tokenize(stream, state);
if (style != "comment" && state.ctx.align == null) state.ctx.align = true;
if (style != "comment" && (state.ctx.flags & ALIGN_NO) == 0) setFlag(state, ALIGN_YES)
var ctype = state.ctx.type;
if ((curPunc == ";" || curPunc == "{" || curPunc == "}") && ctype == "block") pop(state);
if ((curPunc == ";" || curPunc == "{" || curPunc == "}") && state.ctx.type == "block") pop(state);
if (curPunc == "{") push(state, "}", stream);
else if (curPunc == "(") {
push(state, ")", stream);
@ -148,7 +158,8 @@ CodeMirror.defineMode("r", function(config) {
}
else if (curPunc == "[") push(state, "]", stream);
else if (curPunc == "block") push(state, "block", stream);
else if (curPunc == ctype) pop(state);
else if (curPunc == state.ctx.type) pop(state);
else if (state.ctx.type == "block" && style != "comment") setFlag(state, BRACELESS)
state.afterIdent = style == "variable" || style == "keyword";
return style;
},
@ -157,8 +168,9 @@ CodeMirror.defineMode("r", function(config) {
if (state.tokenize != tokenBase) return 0;
var firstChar = textAfter && textAfter.charAt(0), ctx = state.ctx,
closing = firstChar == ctx.type;
if (ctx.flags & BRACELESS) ctx = ctx.prev
if (ctx.type == "block") return ctx.indent + (firstChar == "{" ? 0 : config.indentUnit);
else if (ctx.align) return ctx.column + (closing ? 0 : 1);
else if (ctx.flags & ALIGN_YES) return ctx.column + (closing ? 0 : 1);
else return ctx.indent + (closing ? 0 : config.indentUnit);
},