Update CodeMirror to version 5.15.3

This commit is contained in:
Cheng-Han, Wu 2016-06-01 14:37:28 +08:00
parent 16d5e3ea80
commit fb70833bc5
41 changed files with 834 additions and 310 deletions

View file

@ -109,7 +109,7 @@
var ranges = cm.listSelections();
var opening = pos % 2 == 0;
var type, next;
var type;
for (var i = 0; i < ranges.length; i++) {
var range = ranges[i], cur = range.head, curType;
var next = cm.getRange(cur, Pos(cur.line, cur.ch + 1));

View file

@ -13,7 +13,7 @@
CodeMirror.registerHelper("fold", "brace", function(cm, start) {
var line = start.line, lineText = cm.getLine(line);
var startCh, tokenType;
var tokenType;
function findOpening(openCh) {
for (var at = start.ch, pass = 0;;) {
@ -72,15 +72,15 @@ CodeMirror.registerHelper("fold", "import", function(cm, start) {
}
}
var start = start.line, has = hasImport(start), prev;
if (!has || hasImport(start - 1) || ((prev = hasImport(start - 2)) && prev.end.line == start - 1))
var startLine = start.line, has = hasImport(startLine), prev;
if (!has || hasImport(startLine - 1) || ((prev = hasImport(startLine - 2)) && prev.end.line == startLine - 1))
return null;
for (var end = has.end;;) {
var next = hasImport(end.line + 1);
if (next == null) break;
end = next.end;
}
return {from: cm.clipPos(CodeMirror.Pos(start, has.startCh + 1)), to: end};
return {from: cm.clipPos(CodeMirror.Pos(startLine, has.startCh + 1)), to: end};
});
CodeMirror.registerHelper("fold", "include", function(cm, start) {
@ -91,14 +91,14 @@ CodeMirror.registerHelper("fold", "include", function(cm, start) {
if (start.type == "meta" && start.string.slice(0, 8) == "#include") return start.start + 8;
}
var start = start.line, has = hasInclude(start);
if (has == null || hasInclude(start - 1) != null) return null;
for (var end = start;;) {
var startLine = start.line, has = hasInclude(startLine);
if (has == null || hasInclude(startLine - 1) != null) return null;
for (var end = startLine;;) {
var next = hasInclude(end + 1);
if (next == null) break;
++end;
}
return {from: CodeMirror.Pos(start, has + 1),
return {from: CodeMirror.Pos(startLine, has + 1),
to: cm.clipPos(CodeMirror.Pos(end))};
});

View file

@ -140,9 +140,9 @@
var openTag = toNextTag(iter), end;
if (!openTag || iter.line != start.line || !(end = toTagEnd(iter))) return;
if (!openTag[1] && end != "selfClose") {
var start = Pos(iter.line, iter.ch);
var close = findMatchingClose(iter, openTag[2]);
return close && {from: start, to: close.from};
var startPos = Pos(iter.line, iter.ch);
var endPos = findMatchingClose(iter, openTag[2]);
return endPos && {from: startPos, to: endPos.from};
}
}
});

View file

@ -16,6 +16,7 @@
background: white;
font-size: 90%;
font-family: monospace;
max-width: 19em;
max-height: 20em;
overflow-y: auto;
@ -25,8 +26,6 @@
margin: 0;
padding: 0 4px;
border-radius: 2px;
max-width: 19em;
overflow: hidden;
white-space: pre;
color: black;
cursor: pointer;

View file

@ -108,15 +108,11 @@
},
update: function(first) {
if (this.tick == null) return;
if (!this.options.hint.async) {
this.finishUpdate(this.options.hint(this.cm, this.options), first);
} else {
var myTick = ++this.tick, self = this;
this.options.hint(this.cm, function(data) {
if (self.tick == myTick) self.finishUpdate(data, first);
}, this.options);
}
if (this.tick == null) return
var self = this, myTick = ++this.tick
fetchHints(this.options.hint, this.cm, this.options, function(data) {
if (self.tick == myTick) self.finishUpdate(data, first)
})
},
finishUpdate: function(data, first) {
@ -233,6 +229,7 @@
var winH = window.innerHeight || Math.max(document.body.offsetHeight, document.documentElement.offsetHeight);
(completion.options.container || document.body).appendChild(hints);
var box = hints.getBoundingClientRect(), overlapY = box.bottom - winH;
var scrolls = hints.scrollHeight > hints.clientHeight + 1
if (overlapY > 0) {
var height = box.bottom - box.top, curTop = pos.top - (pos.bottom - box.top);
if (curTop - height > 0) { // Fits above cursor
@ -257,6 +254,8 @@
}
hints.style.left = (left = pos.left - overlapX) + "px";
}
if (scrolls) for (var node = hints.firstChild; node; node = node.nextSibling)
node.style.paddingRight = cm.display.nativeBarWidth + "px"
cm.addKeyMap(this.keyMap = buildKeyMap(completion, {
moveFocus: function(n, avoidWrap) { widget.changeActive(widget.selectedHint + n, avoidWrap); },
@ -362,40 +361,31 @@
return result
}
function fetchHints(hint, cm, options, callback) {
if (hint.async) {
hint(cm, callback, options)
} else {
var result = hint(cm, options)
if (result && result.then) result.then(callback)
else callback(result)
}
}
function resolveAutoHints(cm, pos) {
var helpers = cm.getHelpers(pos, "hint"), words
if (helpers.length) {
var async = false, resolved
for (var i = 0; i < helpers.length; i++) if (helpers[i].async) async = true
if (async) {
resolved = function(cm, callback, options) {
var app = applicableHelpers(cm, helpers)
function run(i, result) {
var resolved = function(cm, callback, options) {
var app = applicableHelpers(cm, helpers);
function run(i) {
if (i == app.length) return callback(null)
var helper = app[i]
if (helper.async) {
helper(cm, function(result) {
if (result) callback(result)
fetchHints(app[i], cm, options, function(result) {
if (result && result.list.length > 0) callback(result)
else run(i + 1)
}, options)
} else {
var result = helper(cm, options)
if (result) callback(result)
else run(i + 1)
}
})
}
run(0)
}
resolved.async = true
} else {
resolved = function(cm, options) {
var app = applicableHelpers(cm, helpers)
for (var i = 0; i < app.length; i++) {
var cur = app[i](cm, options)
if (cur && cur.list.length) return cur
}
}
}
resolved.supportsSelection = true
return resolved
} else if (words = cm.getHelper(cm.getCursor(), "hintWords")) {

View file

@ -241,7 +241,7 @@
var defaultTableName = options && options.defaultTable;
var disableKeywords = options && options.disableKeywords;
defaultTable = defaultTableName && getTable(defaultTableName);
keywords = keywords || getKeywords(editor);
keywords = getKeywords(editor);
if (defaultTableName && !defaultTable)
defaultTable = findTableByAlias(defaultTableName, editor);

View file

@ -4,10 +4,10 @@
}
.CodeMirror-lint-tooltip {
background-color: infobackground;
background-color: #ffd;
border: 1px solid black;
border-radius: 4px 4px 4px 4px;
color: infotext;
color: black;
font-family: monospace;
font-size: 10pt;
overflow: hidden;

View file

@ -204,7 +204,8 @@
var annotations = [];
for (var i = 0; i < spans.length; ++i) {
annotations.push(spans[i].__annotation);
var ann = spans[i].__annotation;
if (ann) annotations.push(ann);
}
if (annotations.length) popupTooltips(annotations, e);
}

View file

@ -59,10 +59,10 @@
CodeMirror.on(this.node, "DOMMouseScroll", onWheel);
}
Bar.prototype.setPos = function(pos) {
Bar.prototype.setPos = function(pos, force) {
if (pos < 0) pos = 0;
if (pos > this.total - this.screen) pos = this.total - this.screen;
if (pos == this.pos) return false;
if (!force && pos == this.pos) return false;
this.pos = pos;
this.inner.style[this.orientation == "horizontal" ? "left" : "top"] =
(pos * (this.size / this.total)) + "px";
@ -76,9 +76,12 @@
var minButtonSize = 10;
Bar.prototype.update = function(scrollSize, clientSize, barSize) {
var sizeChanged = this.screen != clientSize || this.total != scrollSize || this.size != barSize
if (sizeChanged) {
this.screen = clientSize;
this.total = scrollSize;
this.size = barSize;
}
var buttonSize = this.screen * (this.size / this.total);
if (buttonSize < minButtonSize) {
@ -87,7 +90,7 @@
}
this.inner.style[this.orientation == "horizontal" ? "width" : "height"] =
buttonSize + "px";
this.setPos(this.pos);
this.setPos(this.pos, sizeChanged);
};
function SimpleScrollbars(cls, place, scroll) {

View file

@ -29,24 +29,20 @@
})(function(CodeMirror) {
"use strict";
var DEFAULT_MIN_CHARS = 2;
var DEFAULT_TOKEN_STYLE = "matchhighlight";
var DEFAULT_DELAY = 100;
var DEFAULT_WORDS_ONLY = false;
var defaults = {
style: "matchhighlight",
minChars: 2,
delay: 100,
wordsOnly: false,
annotateScrollbar: false,
showToken: false,
trim: true
}
function State(options) {
if (typeof options == "object") {
this.minChars = options.minChars;
this.style = options.style;
this.showToken = options.showToken;
this.delay = options.delay;
this.wordsOnly = options.wordsOnly;
this.annotateScrollbar = options.annotateScrollbar;
}
if (this.style == null) this.style = DEFAULT_TOKEN_STYLE;
if (this.minChars == null) this.minChars = DEFAULT_MIN_CHARS;
if (this.delay == null) this.delay = DEFAULT_DELAY;
if (this.wordsOnly == null) this.wordsOnly = DEFAULT_WORDS_ONLY;
this.options = {}
for (var name in defaults)
this.options[name] = (options && options.hasOwnProperty(name) ? options : defaults)[name]
this.overlay = this.timeout = null;
this.matchesonscroll = null;
}
@ -68,13 +64,13 @@
function cursorActivity(cm) {
var state = cm.state.matchHighlighter;
clearTimeout(state.timeout);
state.timeout = setTimeout(function() {highlightMatches(cm);}, state.delay);
state.timeout = setTimeout(function() {highlightMatches(cm);}, state.options.delay);
}
function addOverlay(cm, query, hasBoundary, style) {
var state = cm.state.matchHighlighter;
cm.addOverlay(state.overlay = makeOverlay(query, hasBoundary, style));
if (state.annotateScrollbar) {
if (state.options.annotateScrollbar && cm.showMatchesOnScrollbar) {
var searchFor = hasBoundary ? new RegExp("\\b" + query + "\\b") : query;
state.matchesonscroll = cm.showMatchesOnScrollbar(searchFor, true,
{className: "CodeMirror-selection-highlight-scrollbar"});
@ -86,7 +82,7 @@
if (state.overlay) {
cm.removeOverlay(state.overlay);
state.overlay = null;
if (state.annotateScrollbar) {
if (state.matchesonscroll) {
state.matchesonscroll.clear();
state.matchesonscroll = null;
}
@ -97,21 +93,22 @@
cm.operation(function() {
var state = cm.state.matchHighlighter;
removeOverlay(cm);
if (!cm.somethingSelected() && state.showToken) {
var re = state.showToken === true ? /[\w$]/ : state.showToken;
if (!cm.somethingSelected() && state.options.showToken) {
var re = state.options.showToken === true ? /[\w$]/ : state.options.showToken;
var cur = cm.getCursor(), line = cm.getLine(cur.line), start = cur.ch, end = start;
while (start && re.test(line.charAt(start - 1))) --start;
while (end < line.length && re.test(line.charAt(end))) ++end;
if (start < end)
addOverlay(cm, line.slice(start, end), re, state.style);
addOverlay(cm, line.slice(start, end), re, state.options.style);
return;
}
var from = cm.getCursor("from"), to = cm.getCursor("to");
if (from.line != to.line) return;
if (state.wordsOnly && !isWord(cm, from, to)) return;
var selection = cm.getRange(from, to).replace(/^\s+|\s+$/g, "");
if (selection.length >= state.minChars)
addOverlay(cm, selection, false, state.style);
if (state.options.wordsOnly && !isWord(cm, from, to)) return;
var selection = cm.getRange(from, to)
if (state.options.trim) selection = selection.replace(/^\s+|\s+$/g, "")
if (selection.length >= state.options.minChars)
addOverlay(cm, selection, false, state.options.style);
});
}

File diff suppressed because one or more lines are too long

View file

@ -124,6 +124,7 @@
}
cm.setSelections(newSelection);
});
cm.execCommand("indentAuto");
}
cmds[map[ctrl + "Enter"] = "insertLineAfter"] = function(cm) { return insertLine(cm, false); };
@ -419,27 +420,6 @@
map[cK + ctrl + "Backspace"] = "delLineLeft";
cmds[map["Backspace"] = "smartBackspace"] = function(cm) {
if (cm.somethingSelected()) return CodeMirror.Pass;
var cursor = cm.getCursor();
var toStartOfLine = cm.getRange({line: cursor.line, ch: 0}, cursor);
var column = CodeMirror.countColumn(toStartOfLine, null, cm.getOption("tabSize"));
var indentUnit = cm.getOption("indentUnit");
if (toStartOfLine && !/\S/.test(toStartOfLine) && column % indentUnit == 0) {
var prevIndent = new Pos(cursor.line,
CodeMirror.findColumn(toStartOfLine, column - indentUnit, indentUnit));
// If no smart delete is happening (due to tab sizing) just do a regular delete
if (prevIndent.ch == cursor.ch) return CodeMirror.Pass;
return cm.replaceRange("", prevIndent, cursor, "+delete");
} else {
return CodeMirror.Pass;
}
};
cmds[map[cK + ctrl + "K"] = "delLineRight"] = function(cm) {
cm.operation(function() {
var ranges = cm.listSelections();

View file

@ -3782,17 +3782,10 @@
}
}
function makePrompt(prefix, desc) {
var raw = '';
if (prefix) {
raw += '<span style="font-family: monospace">' + prefix + '</span>';
}
raw += '<input type="text"/> ' +
'<span style="color: #888">';
if (desc) {
raw += '<span style="color: #888">';
raw += desc;
raw += '</span>';
}
var raw = '<span style="font-family: monospace; white-space: pre">' +
(prefix || "") + '<input type="text"></span>';
if (desc)
raw += ' <span style="color: #888">' + desc + '</span>';
return raw;
}
var searchPromptDesc = '(Javascript regexp)';

View file

@ -52,7 +52,7 @@
}
.cm-fat-cursor .CodeMirror-cursor {
width: auto;
border: 0;
border: 0 !important;
background: #7e7;
}
.cm-fat-cursor div.CodeMirror-cursors {

View file

@ -1096,9 +1096,9 @@
if (!cm.state.focused) { cm.display.input.focus(); onFocus(cm); }
}
// This will be set to an array of strings when copying, so that,
// when pasting, we know what kind of selections the copied text
// was made out of.
// This will be set to a {lineWise: bool, text: [string]} object, so
// that, when pasting, we know what kind of selections the copied
// text was made out of.
var lastCopied = null;
function applyTextInput(cm, inserted, deleted, sel, origin) {
@ -1107,14 +1107,14 @@
if (!sel) sel = doc.sel;
var paste = cm.state.pasteIncoming || origin == "paste";
var textLines = doc.splitLines(inserted), multiPaste = null;
var textLines = doc.splitLines(inserted), multiPaste = null
// When pasing N lines into N selections, insert one line per selection
if (paste && sel.ranges.length > 1) {
if (lastCopied && lastCopied.join("\n") == inserted) {
if (sel.ranges.length % lastCopied.length == 0) {
if (lastCopied && lastCopied.text.join("\n") == inserted) {
if (sel.ranges.length % lastCopied.text.length == 0) {
multiPaste = [];
for (var i = 0; i < lastCopied.length; i++)
multiPaste.push(doc.splitLines(lastCopied[i]));
for (var i = 0; i < lastCopied.text.length; i++)
multiPaste.push(doc.splitLines(lastCopied.text[i]));
}
} else if (textLines.length == sel.ranges.length) {
multiPaste = map(textLines, function(l) { return [l]; });
@ -1130,6 +1130,8 @@
from = Pos(from.line, from.ch - deleted);
else if (cm.state.overwrite && !paste) // Handle overwrite
to = Pos(to.line, Math.min(getLine(doc, to.line).text.length, to.ch + lst(textLines).length));
else if (lastCopied && lastCopied.lineWise && lastCopied.text.join("\n") == inserted)
from = to = Pos(from.line, 0)
}
var updateInput = cm.curOp.updateInput;
var changeEvent = {from: from, to: to, text: multiPaste ? multiPaste[i % multiPaste.length] : textLines,
@ -1262,18 +1264,18 @@
function prepareCopyCut(e) {
if (signalDOMEvent(cm, e)) return
if (cm.somethingSelected()) {
lastCopied = cm.getSelections();
lastCopied = {lineWise: false, text: cm.getSelections()};
if (input.inaccurateSelection) {
input.prevInput = "";
input.inaccurateSelection = false;
te.value = lastCopied.join("\n");
te.value = lastCopied.text.join("\n");
selectInput(te);
}
} else if (!cm.options.lineWiseCopyCut) {
return;
} else {
var ranges = copyableRanges(cm);
lastCopied = ranges.text;
lastCopied = {lineWise: true, text: ranges.text};
if (e.type == "cut") {
cm.setSelections(ranges.ranges, null, sel_dontScroll);
} else {
@ -1623,13 +1625,13 @@
function onCopyCut(e) {
if (signalDOMEvent(cm, e)) return
if (cm.somethingSelected()) {
lastCopied = cm.getSelections();
lastCopied = {lineWise: false, text: cm.getSelections()};
if (e.type == "cut") cm.replaceSelection("", null, "cut");
} else if (!cm.options.lineWiseCopyCut) {
return;
} else {
var ranges = copyableRanges(cm);
lastCopied = ranges.text;
lastCopied = {lineWise: true, text: ranges.text};
if (e.type == "cut") {
cm.operation(function() {
cm.setSelections(ranges.ranges, 0, sel_dontScroll);
@ -1641,12 +1643,12 @@
if (e.clipboardData && !ios) {
e.preventDefault();
e.clipboardData.clearData();
e.clipboardData.setData("text/plain", lastCopied.join("\n"));
e.clipboardData.setData("text/plain", lastCopied.text.join("\n"));
} else {
// Old-fashioned briefly-focus-a-textarea hack
var kludge = hiddenTextarea(), te = kludge.firstChild;
cm.display.lineSpace.insertBefore(kludge, cm.display.lineSpace.firstChild);
te.value = lastCopied.join("\n");
te.value = lastCopied.text.join("\n");
var hadFocus = document.activeElement;
selectInput(te);
setTimeout(function() {
@ -1665,9 +1667,9 @@
return result;
},
showSelection: function(info) {
showSelection: function(info, takeFocus) {
if (!info || !this.cm.display.view.length) return;
if (info.focus) this.showPrimarySelection();
if (info.focus || takeFocus) this.showPrimarySelection();
this.showMultipleSelections(info);
},
@ -3113,7 +3115,7 @@
}
if (op.updatedDisplay || op.selectionChanged)
op.preparedSelection = display.input.prepareSelection();
op.preparedSelection = display.input.prepareSelection(op.focus);
}
function endOperation_W2(op) {
@ -3126,8 +3128,9 @@
cm.display.maxLineChanged = false;
}
var takeFocus = op.focus && op.focus == activeElt() && (!document.hasFocus || document.hasFocus())
if (op.preparedSelection)
cm.display.input.showSelection(op.preparedSelection);
cm.display.input.showSelection(op.preparedSelection, takeFocus);
if (op.updatedDisplay || op.startHeight != cm.doc.height)
updateScrollbars(cm, op.barMeasure);
if (op.updatedDisplay)
@ -3137,8 +3140,7 @@
if (cm.state.focused && op.updateInput)
cm.display.input.reset(op.typing);
if (op.focus && op.focus == activeElt() && (!document.hasFocus || document.hasFocus()))
ensureFocus(op.cm);
if (takeFocus) ensureFocus(op.cm);
}
function endOperation_finish(op) {
@ -3918,6 +3920,7 @@
if (signalDOMEvent(cm, e) || eventInWidget(cm.display, e)) return;
e.dataTransfer.setData("Text", cm.getSelection());
e.dataTransfer.effectAllowed = "copyMove"
// Use dummy image instead of default browsers image.
// Recent Safari (~6.0.2) have a tendency to segfault when this happens, so we don't do it there.
@ -5403,7 +5406,7 @@
for (var i = newBreaks.length - 1; i >= 0; i--)
replaceRange(cm.doc, val, newBreaks[i], Pos(newBreaks[i].line, newBreaks[i].ch + val.length))
});
option("specialChars", /[\t\u0000-\u0019\u00ad\u200b-\u200f\u2028\u2029\ufeff]/g, function(cm, val, old) {
option("specialChars", /[\u0000-\u001f\u007f\u00ad\u200b-\u200f\u2028\u2029\ufeff]/g, function(cm, val, old) {
cm.state.specialChars = new RegExp(val.source + (val.test("\t") ? "" : "|\t"), "g");
if (old != CodeMirror.Init) cm.refresh();
});
@ -5732,7 +5735,7 @@
for (var i = 0; i < ranges.length; i++) {
var pos = ranges[i].from();
var col = countColumn(cm.getLine(pos.line), pos.ch, tabSize);
spaces.push(new Array(tabSize - col % tabSize + 1).join(" "));
spaces.push(spaceStr(tabSize - col % tabSize));
}
cm.replaceSelections(spaces);
},
@ -5775,6 +5778,7 @@
ensureCursorVisible(cm);
});
},
openLine: function(cm) {cm.replaceSelection("\n", "start")},
toggleOverwrite: function(cm) {cm.toggleOverwrite();}
};
@ -5809,7 +5813,8 @@
"Ctrl-F": "goCharRight", "Ctrl-B": "goCharLeft", "Ctrl-P": "goLineUp", "Ctrl-N": "goLineDown",
"Alt-F": "goWordRight", "Alt-B": "goWordLeft", "Ctrl-A": "goLineStart", "Ctrl-E": "goLineEnd",
"Ctrl-V": "goPageDown", "Shift-Ctrl-V": "goPageUp", "Ctrl-D": "delCharAfter", "Ctrl-H": "delCharBefore",
"Alt-D": "delWordAfter", "Alt-Backspace": "delWordBefore", "Ctrl-K": "killLine", "Ctrl-T": "transposeChars"
"Alt-D": "delWordAfter", "Alt-Backspace": "delWordBefore", "Ctrl-K": "killLine", "Ctrl-T": "transposeChars",
"Ctrl-O": "openLine"
};
keyMap.macDefault = {
"Cmd-A": "selectAll", "Cmd-D": "deleteLine", "Cmd-Z": "undo", "Shift-Cmd-Z": "redo", "Cmd-Y": "redo",
@ -6571,8 +6576,8 @@
var fromCmp = cmp(found.from, from) || extraLeft(sp.marker) - extraLeft(marker);
var toCmp = cmp(found.to, to) || extraRight(sp.marker) - extraRight(marker);
if (fromCmp >= 0 && toCmp <= 0 || fromCmp <= 0 && toCmp >= 0) continue;
if (fromCmp <= 0 && (cmp(found.to, from) > 0 || (sp.marker.inclusiveRight && marker.inclusiveLeft)) ||
fromCmp >= 0 && (cmp(found.from, to) < 0 || (sp.marker.inclusiveLeft && marker.inclusiveRight)))
if (fromCmp <= 0 && (sp.marker.inclusiveRight && marker.inclusiveLeft ? cmp(found.to, from) >= 0 : cmp(found.to, from) > 0) ||
fromCmp >= 0 && (sp.marker.inclusiveRight && marker.inclusiveLeft ? cmp(found.from, to) <= 0 : cmp(found.from, to) < 0))
return true;
}
}
@ -6974,8 +6979,11 @@
}
// See issue #2901
if (webkit && /\bcm-tab\b/.test(builder.content.lastChild.className))
if (webkit) {
var last = builder.content.lastChild
if (/\bcm-tab\b/.test(last.className) || (last.querySelector && last.querySelector(".cm-tab")))
builder.content.className = "cm-tab-wrap-hack";
}
signal(cm, "renderLine", cm, lineView.line, builder.pre);
if (builder.pre.className)
@ -7327,13 +7335,16 @@
if (at <= sz) {
child.insertInner(at, lines, height);
if (child.lines && child.lines.length > 50) {
while (child.lines.length > 50) {
var spilled = child.lines.splice(child.lines.length - 25, 25);
var newleaf = new LeafChunk(spilled);
child.height -= newleaf.height;
this.children.splice(i + 1, 0, newleaf);
newleaf.parent = this;
// To avoid memory thrashing when child.lines is huge (e.g. first view of a large file), it's never spliced.
// Instead, small slices are taken. They're taken in order because sequential memory accesses are fastest.
var remaining = child.lines.length % 25 + 25
for (var pos = remaining; pos < child.lines.length;) {
var leaf = new LeafChunk(child.lines.slice(pos, pos += 25));
child.height -= leaf.height;
this.children.splice(++i, 0, leaf);
leaf.parent = this;
}
child.lines = child.lines.slice(0, remaining);
this.maybeSpill();
}
break;
@ -7638,9 +7649,9 @@
var spans = line.markedSpans;
if (spans) for (var i = 0; i < spans.length; i++) {
var span = spans[i];
if (!(span.to != null && lineNo == from.line && from.ch > span.to ||
if (!(span.to != null && lineNo == from.line && from.ch >= span.to ||
span.from == null && lineNo != from.line ||
span.from != null && lineNo == to.line && span.from > to.ch) &&
span.from != null && lineNo == to.line && span.from >= to.ch) &&
(!filter || filter(span.marker)))
found.push(span.marker.parent || span.marker);
}
@ -8904,7 +8915,7 @@
// THE END
CodeMirror.version = "5.13.5";
CodeMirror.version = "5.15.3";
return CodeMirror;
});

View file

@ -11,21 +11,19 @@
})(function(CodeMirror) {
"use strict";
function Context(indented, column, type, align, prev) {
function Context(indented, column, type, info, align, prev) {
this.indented = indented;
this.column = column;
this.type = type;
this.info = info;
this.align = align;
this.prev = prev;
}
function isStatement(type) {
return type == "statement" || type == "switchstatement" || type == "namespace";
}
function pushContext(state, col, type) {
function pushContext(state, col, type, info) {
var indent = state.indented;
if (state.context && isStatement(state.context.type) && !isStatement(type))
if (state.context && state.context.type != "statement" && type != "statement")
indent = state.context.indented;
return state.context = new Context(indent, col, type, null, state.context);
return state.context = new Context(indent, col, type, info, null, state.context);
}
function popContext(state) {
var t = state.context.type;
@ -34,15 +32,16 @@ function popContext(state) {
return state.context = state.context.prev;
}
function typeBefore(stream, state) {
function typeBefore(stream, state, pos) {
if (state.prevToken == "variable" || state.prevToken == "variable-3") return true;
if (/\S(?:[^- ]>|[*\]])\s*$|\*$/.test(stream.string.slice(0, stream.start))) return true;
if (/\S(?:[^- ]>|[*\]])\s*$|\*$/.test(stream.string.slice(0, pos))) return true;
if (state.typeAtEndOfLine && stream.column() == stream.indentation()) return true;
}
function isTopScope(context) {
for (;;) {
if (!context || context.type == "top") return true;
if (context.type == "}" && context.prev.type != "namespace") return false;
if (context.type == "}" && context.prev.info != "namespace") return false;
context = context.prev;
}
}
@ -147,13 +146,18 @@ CodeMirror.defineMode("clike", function(config, parserConfig) {
return "comment";
}
function maybeEOL(stream, state) {
if (parserConfig.typeFirstDefinitions && stream.eol() && isTopScope(state.context))
state.typeAtEndOfLine = typeBefore(stream, state, stream.pos)
}
// Interface
return {
startState: function(basecolumn) {
return {
tokenize: null,
context: new Context((basecolumn || 0) - indentUnit, 0, "top", false),
context: new Context((basecolumn || 0) - indentUnit, 0, "top", null, false),
indented: 0,
startOfLine: true,
prevToken: null
@ -167,36 +171,31 @@ CodeMirror.defineMode("clike", function(config, parserConfig) {
state.indented = stream.indentation();
state.startOfLine = true;
}
if (stream.eatSpace()) return null;
if (stream.eatSpace()) { maybeEOL(stream, state); return null; }
curPunc = isDefKeyword = null;
var style = (state.tokenize || tokenBase)(stream, state);
if (style == "comment" || style == "meta") return style;
if (ctx.align == null) ctx.align = true;
if (endStatement.test(curPunc)) while (isStatement(state.context.type)) popContext(state);
if (endStatement.test(curPunc)) while (state.context.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 (isStatement(ctx.type)) ctx = popContext(state);
while (ctx.type == "statement") ctx = popContext(state);
if (ctx.type == "}") ctx = popContext(state);
while (isStatement(ctx.type)) ctx = popContext(state);
while (ctx.type == "statement") ctx = popContext(state);
}
else if (curPunc == ctx.type) popContext(state);
else if (indentStatements &&
(((ctx.type == "}" || ctx.type == "top") && curPunc != ";") ||
(isStatement(ctx.type) && curPunc == "newstatement"))) {
var type = "statement";
if (curPunc == "newstatement" && indentSwitch && stream.current() == "switch")
type = "switchstatement";
else if (style == "keyword" && stream.current() == "namespace")
type = "namespace";
pushContext(state, stream.column(), type);
(ctx.type == "statement" && curPunc == "newstatement"))) {
pushContext(state, stream.column(), "statement", stream.current());
}
if (style == "variable" &&
((state.prevToken == "def" ||
(parserConfig.typeFirstDefinitions && typeBefore(stream, state) &&
(parserConfig.typeFirstDefinitions && typeBefore(stream, state, stream.start) &&
isTopScope(state.context) && stream.match(/^\s*\(/, false)))))
style = "def";
@ -209,24 +208,28 @@ CodeMirror.defineMode("clike", function(config, parserConfig) {
state.startOfLine = false;
state.prevToken = isDefKeyword ? "def" : style || curPunc;
maybeEOL(stream, state);
return style;
},
indent: function(state, textAfter) {
if (state.tokenize != tokenBase && state.tokenize != null) return CodeMirror.Pass;
if (state.tokenize != tokenBase && state.tokenize != null || state.typeAtEndOfLine) return CodeMirror.Pass;
var ctx = state.context, firstChar = textAfter && textAfter.charAt(0);
if (isStatement(ctx.type) && firstChar == "}") ctx = ctx.prev;
if (ctx.type == "statement" && firstChar == "}") ctx = ctx.prev;
if (parserConfig.dontIndentStatements)
while (ctx.type == "statement" && parserConfig.dontIndentStatements.test(ctx.info))
ctx = ctx.prev
if (hooks.indent) {
var hook = hooks.indent(state, ctx, textAfter);
if (typeof hook == "number") return hook
}
var closing = firstChar == ctx.type;
var switchBlock = ctx.prev && ctx.prev.type == "switchstatement";
var switchBlock = ctx.prev && ctx.prev.info == "switch";
if (parserConfig.allmanIndentation && /[{(]/.test(firstChar)) {
while (ctx.type != "top" && ctx.type != "}") ctx = ctx.prev
return ctx.indented
}
if (isStatement(ctx.type))
if (ctx.type == "statement")
return ctx.indented + (firstChar == "{" ? 0 : statementIndentUnit);
if (ctx.align && (!dontAlignCalls || ctx.type != ")"))
return ctx.column + (closing ? 0 : 1);
@ -386,6 +389,7 @@ CodeMirror.defineMode("clike", function(config, parserConfig) {
defKeywords: words("class namespace struct enum union"),
typeFirstDefinitions: true,
atoms: words("true false null"),
dontIndentStatements: /^template$/,
hooks: {
"#": cppHook,
"*": pointerHook,
@ -429,6 +433,7 @@ CodeMirror.defineMode("clike", function(config, parserConfig) {
typeFirstDefinitions: true,
atoms: words("true false null"),
endStatement: /^[;:]$/,
number: /^(?:0x[a-f\d_]+|0b[01_]+|(?:[\d_]+\.?\d*|\.\d+)(?:e[-+]?[\d_]+)?)(u|ll?|l|f)?/i,
hooks: {
"@": function(stream) {
stream.eatWhile(/[\w\$_]/);
@ -531,7 +536,7 @@ CodeMirror.defineMode("clike", function(config, parserConfig) {
"=": function(stream, state) {
var cx = state.context
if (cx.type == "}" && cx.align && stream.eat(">")) {
state.context = new Context(cx.indented, cx.column, cx.type, null, cx.prev)
state.context = new Context(cx.indented, cx.column, cx.type, cx.info, null, cx.prev)
return "operator"
} else {
return false

View file

@ -25,6 +25,10 @@
"[keyword struct] [def bar]{}",
"[variable-3 int] [variable-3 *][def baz]() {}");
MT("def_new_line",
"::[variable std]::[variable SomeTerribleType][operator <][variable T][operator >]",
"[def SomeLongMethodNameThatDoesntFitIntoOneLine]([keyword const] [variable MyType][operator &] [variable param]) {}")
MT("double_block",
"[keyword for] (;;)",
" [keyword for] (;;)",

File diff suppressed because one or more lines are too long

View file

@ -484,9 +484,9 @@ CodeMirror.defineMode("css", function(config, parserConfig) {
"font-variant-alternates", "font-variant-caps", "font-variant-east-asian",
"font-variant-ligatures", "font-variant-numeric", "font-variant-position",
"font-weight", "grid", "grid-area", "grid-auto-columns", "grid-auto-flow",
"grid-auto-position", "grid-auto-rows", "grid-column", "grid-column-end",
"grid-column-start", "grid-row", "grid-row-end", "grid-row-start",
"grid-template", "grid-template-areas", "grid-template-columns",
"grid-auto-rows", "grid-column", "grid-column-end", "grid-column-gap",
"grid-column-start", "grid-gap", "grid-row", "grid-row-end", "grid-row-gap",
"grid-row-start", "grid-template", "grid-template-areas", "grid-template-columns",
"grid-template-rows", "hanging-punctuation", "height", "hyphens",
"icon", "image-orientation", "image-rendering", "image-resolution",
"inline-box-align", "justify-content", "left", "letter-spacing",
@ -601,7 +601,7 @@ CodeMirror.defineMode("css", function(config, parserConfig) {
"compact", "condensed", "contain", "content",
"content-box", "context-menu", "continuous", "copy", "counter", "counters", "cover", "crop",
"cross", "crosshair", "currentcolor", "cursive", "cyclic", "darken", "dashed", "decimal",
"decimal-leading-zero", "default", "default-button", "destination-atop",
"decimal-leading-zero", "default", "default-button", "dense", "destination-atop",
"destination-in", "destination-out", "destination-over", "devanagari", "difference",
"disc", "discard", "disclosure-closed", "disclosure-open", "document",
"dot-dash", "dot-dot-dash",
@ -615,13 +615,13 @@ CodeMirror.defineMode("css", function(config, parserConfig) {
"ethiopic-halehame-ti-er", "ethiopic-halehame-ti-et", "ethiopic-halehame-tig",
"ethiopic-numeric", "ew-resize", "exclusion", "expanded", "extends", "extra-condensed",
"extra-expanded", "fantasy", "fast", "fill", "fixed", "flat", "flex", "flex-end", "flex-start", "footnotes",
"forwards", "from", "geometricPrecision", "georgian", "graytext", "groove",
"forwards", "from", "geometricPrecision", "georgian", "graytext", "grid", "groove",
"gujarati", "gurmukhi", "hand", "hangul", "hangul-consonant", "hard-light", "hebrew",
"help", "hidden", "hide", "higher", "highlight", "highlighttext",
"hiragana", "hiragana-iroha", "horizontal", "hsl", "hsla", "hue", "icon", "ignore",
"inactiveborder", "inactivecaption", "inactivecaptiontext", "infinite",
"infobackground", "infotext", "inherit", "initial", "inline", "inline-axis",
"inline-block", "inline-flex", "inline-table", "inset", "inside", "intrinsic", "invert",
"inline-block", "inline-flex", "inline-grid", "inline-table", "inset", "inside", "intrinsic", "invert",
"italic", "japanese-formal", "japanese-informal", "justify", "kannada",
"katakana", "katakana-iroha", "keep-all", "khmer",
"korean-hangul-formal", "korean-hanja-formal", "korean-hanja-informal",

View file

@ -94,7 +94,7 @@
if (bracesMode !== null && (state.braced || peek === "{")) {
if (state.localState === null)
state.localState = bracesMode.startState();
state.localState = CodeMirror.startState(bracesMode);
var token = bracesMode.token(stream, state.localState),
text = stream.current();

View file

@ -77,5 +77,5 @@
});
</script>
<p><strong>MIME types defined:</strong> <code>text/x-Fortran</code>.</p>
<p><strong>MIME types defined:</strong> <code>text/x-fortran</code>.</p>
</article>

View file

@ -98,8 +98,8 @@
return {
// default to html mode
startState: function() {
var htmlState = htmlMode.startState();
var rubyState = rubyMode.startState();
var htmlState = CodeMirror.startState(htmlMode);
var rubyState = CodeMirror.startState(rubyMode);
return {
htmlState: htmlState,
rubyState: rubyState,

View file

@ -51,9 +51,10 @@ This is an example of EJS (embedded javascript)
});
</script>
<p>Mode for html embedded scripts like JSP and ASP.NET. Depends on HtmlMixed which in turn depends on
<p>Mode for html embedded scripts like JSP and ASP.NET. Depends on multiplex and HtmlMixed which in turn depends on
JavaScript, CSS and XML.<br />Other dependencies include those of the scripting language chosen.</p>
<p><strong>MIME types defined:</strong> <code>application/x-aspx</code> (ASP.NET),
<code>application/x-ejs</code> (Embedded Javascript), <code>application/x-jsp</code> (JavaServer Pages)</p>
<code>application/x-ejs</code> (Embedded Javascript), <code>application/x-jsp</code> (JavaServer Pages)
and <code>application/x-erb</code></p>
</article>

View file

@ -115,7 +115,7 @@
return {
startState: function () {
var state = htmlMode.startState();
var state = CodeMirror.startState(htmlMode);
return {token: html, inTag: null, localMode: null, localState: null, htmlState: state};
},

View file

@ -86,6 +86,7 @@ option.</p>
<li><a href="lua/index.html">Lua</a></li>
<li><a href="markdown/index.html">Markdown</a> (<a href="gfm/index.html">GitHub-flavour</a>)</li>
<li><a href="mathematica/index.html">Mathematica</a></li>
<li><a href="mbox/index.html">mbox</a></li>
<li><a href="mirc/index.html">mIRC</a></li>
<li><a href="modelica/index.html">Modelica</a></li>
<li><a href="mscgen/index.html">MscGen</a></li>

View file

@ -36,7 +36,7 @@ CodeMirror.defineMode('jade', function (config) {
this.isInterpolating = false;
this.interpolationNesting = 0;
this.jsState = jsMode.startState();
this.jsState = CodeMirror.startState(jsMode);
this.restOfLine = '';
@ -386,7 +386,7 @@ CodeMirror.defineMode('jade', function (config) {
if (state.inAttributeName && stream.match(/^[^=,\)!]+/)) {
if (stream.peek() === '=' || stream.peek() === '!') {
state.inAttributeName = false;
state.jsState = jsMode.startState();
state.jsState = CodeMirror.startState(jsMode);
if (state.lastTag === 'script' && stream.current().trim().toLowerCase() === 'type') {
state.attributeIsType = true;
} else {
@ -492,7 +492,7 @@ CodeMirror.defineMode('jade', function (config) {
if (stream.indentation() > state.indentOf || (state.innerModeForLine && !stream.sol()) || force) {
if (state.innerMode) {
if (!state.innerState) {
state.innerState = state.innerMode.startState ? state.innerMode.startState(stream.indentation()) : {};
state.innerState = state.innerMode.startState ? CodeMirror.startState(state.innerMode, stream.indentation()) : {};
}
return stream.hideFirstChars(state.indentOf + 2, function () {
return state.innerMode.token(stream, state.innerState) || true;

View file

@ -42,7 +42,8 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
"in": operator, "typeof": operator, "instanceof": operator,
"true": atom, "false": atom, "null": atom, "undefined": atom, "NaN": atom, "Infinity": atom,
"this": kw("this"), "class": kw("class"), "super": kw("atom"),
"yield": C, "export": kw("export"), "import": kw("import"), "extends": C
"yield": C, "export": kw("export"), "import": kw("import"), "extends": C,
"await": C, "async": kw("async")
};
// Extend the 'normal' keywords with the TypeScript language extensions
@ -366,6 +367,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
if (type == "export") return cont(pushlex("stat"), afterExport, poplex);
if (type == "import") return cont(pushlex("stat"), afterImport, poplex);
if (type == "module") return cont(pushlex("form"), pattern, pushlex("}"), expect("{"), block, poplex, poplex)
if (type == "async") return cont(statement)
return pass(pushlex("stat"), expression, expect(";"), poplex);
}
function expression(type) {
@ -488,17 +490,17 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
if (type == "(") return pass(functiondef);
}
function commasep(what, end) {
function proceed(type) {
function proceed(type, value) {
if (type == ",") {
var lex = cx.state.lexical;
if (lex.info == "call") lex.pos = (lex.pos || 0) + 1;
return cont(what, proceed);
}
if (type == end) return cont();
if (type == end || value == end) return cont();
return cont(expect(end));
}
return function(type) {
if (type == end) return cont();
return function(type, value) {
if (type == end || value == end) return cont();
return pass(what, proceed);
};
}
@ -512,13 +514,17 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
return pass(statement, block);
}
function maybetype(type) {
if (isTS && type == ":") return cont(typedef);
if (isTS && type == ":") return cont(typeexpr);
}
function maybedefault(_, value) {
if (value == "=") return cont(expressionNoComma);
}
function typedef(type) {
if (type == "variable") {cx.marked = "variable-3"; return cont();}
function typeexpr(type) {
if (type == "variable") {cx.marked = "variable-3"; return cont(afterType);}
}
function afterType(type, value) {
if (value == "<") return cont(commasep(typeexpr, ">"), afterType)
if (type == "[") return cont(expect("]"), afterType)
}
function vardef() {
return pass(pattern, maybetype, maybeAssign, vardefCont);
@ -573,7 +579,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
function functiondef(type, value) {
if (value == "*") {cx.marked = "keyword"; return cont(functiondef);}
if (type == "variable") {register(value); return cont(functiondef);}
if (type == "(") return cont(pushcontext, pushlex(")"), commasep(funarg, ")"), poplex, statement, popcontext);
if (type == "(") return cont(pushcontext, pushlex(")"), commasep(funarg, ")"), poplex, maybetype, statement, popcontext);
}
function funarg(type) {
if (type == "spread") return cont(funarg);

View file

@ -218,7 +218,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
state.fencedChars = match[1]
// try switching mode
state.localMode = getMode(match[2]);
if (state.localMode) state.localState = state.localMode.startState();
if (state.localMode) state.localState = CodeMirror.startState(state.localMode);
state.f = state.block = local;
if (modeCfg.highlightFormatting) state.formatting = "code-block";
state.code = -1
@ -437,13 +437,13 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
return tokenTypes.image;
}
if (ch === '[' && stream.match(/.*\](\(.*\)| ?\[.*\])/, false)) {
if (ch === '[' && stream.match(/[^\]]*\](\(.*\)| ?\[.*?\])/, false)) {
state.linkText = true;
if (modeCfg.highlightFormatting) state.formatting = "link";
return getType(state);
}
if (ch === ']' && state.linkText && stream.match(/\(.*\)| ?\[.*\]/, false)) {
if (ch === ']' && state.linkText && stream.match(/\(.*?\)| ?\[.*?\]/, false)) {
if (modeCfg.highlightFormatting) state.formatting = "link";
var type = getType(state);
state.linkText = false;
@ -596,7 +596,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
}
var ch = stream.next();
if (ch === '(' || ch === '[') {
state.f = state.inline = getLinkHrefInside(ch === "(" ? ")" : "]");
state.f = state.inline = getLinkHrefInside(ch === "(" ? ")" : "]", 0);
if (modeCfg.highlightFormatting) state.formatting = "link-string";
state.linkHref = true;
return getType(state);
@ -604,6 +604,11 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
return 'error';
}
var linkRE = {
")": /^(?:[^\\\(\)]|\\.|\((?:[^\\\(\)]|\\.)*\))*?(?=\))/,
"]": /^(?:[^\\\[\]]|\\.|\[(?:[^\\\[\\]]|\\.)*\])*?(?=\])/
}
function getLinkHrefInside(endChar) {
return function(stream, state) {
var ch = stream.next();
@ -616,10 +621,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
return returnState;
}
if (stream.match(inlineRE(endChar), true)) {
stream.backUp(1);
}
stream.match(linkRE[endChar])
state.linkHref = true;
return getType(state);
};
@ -667,18 +669,6 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
return tokenTypes.linkHref + " url";
}
var savedInlineRE = [];
function inlineRE(endChar) {
if (!savedInlineRE[endChar]) {
// Escape endChar for RegExp (taken from http://stackoverflow.com/a/494122/526741)
endChar = (endChar+'').replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1");
// Match any non-endChar, escaped character, as well as the closing
// endChar.
savedInlineRE[endChar] = new RegExp('^(?:[^\\\\]|\\\\.)*?(' + endChar + ')');
}
return savedInlineRE[endChar];
}
var mode = {
startState: function() {
return {

View file

@ -782,6 +782,9 @@
MT("emStrongMixed",
"[em *foo][em&strong __bar_hello** world]");
MT("linkWithNestedParens",
"[link [[foo]]][string&url (bar(baz))]")
// These characters should be escaped:
// \ backslash
// ` backtick

View file

@ -0,0 +1,44 @@
<!doctype html>
<title>CodeMirror: mbox mode</title>
<meta charset="utf-8"/>
<link rel=stylesheet href="../../doc/docs.css">
<link rel="stylesheet" href="../../lib/codemirror.css">
<script src="../../lib/codemirror.js"></script>
<script src="mbox.js"></script>
<style>.CodeMirror { border-top: 1px solid #ddd; border-bottom: 1px solid #ddd; }</style>
<div id=nav>
<a href="http://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png"></a>
<ul>
<li><a href="../../index.html">Home</a>
<li><a href="../../doc/manual.html">Manual</a>
<li><a href="https://github.com/codemirror/codemirror">Code</a>
</ul>
<ul>
<li><a href="../index.html">Language modes</a>
<li><a class=active href="#">mbox</a>
</ul>
</div>
<article>
<h2>mbox mode</h2>
<form><textarea id="code" name="code">
From timothygu99@gmail.com Sun Apr 17 01:40:43 2016
From: Timothy Gu &lt;timothygu99@gmail.com&gt;
Date: Sat, 16 Apr 2016 18:40:43 -0700
Subject: mbox mode
Message-ID: &lt;Z8d+bTT50U/az94FZnyPkDjZmW0=@gmail.com&gt;
mbox mode is working!
Timothy
</textarea></form>
<script>
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {});
</script>
<p><strong>MIME types defined:</strong> <code>application/mbox</code>.</p>
</article>

View file

@ -0,0 +1,129 @@
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
"use strict";
var rfc2822 = [
"From", "Sender", "Reply-To", "To", "Cc", "Bcc", "Message-ID",
"In-Reply-To", "References", "Resent-From", "Resent-Sender", "Resent-To",
"Resent-Cc", "Resent-Bcc", "Resent-Message-ID", "Return-Path", "Received"
];
var rfc2822NoEmail = [
"Date", "Subject", "Comments", "Keywords", "Resent-Date"
];
CodeMirror.registerHelper("hintWords", "mbox", rfc2822.concat(rfc2822NoEmail));
var whitespace = /^[ \t]/;
var separator = /^From /; // See RFC 4155
var rfc2822Header = new RegExp("^(" + rfc2822.join("|") + "): ");
var rfc2822HeaderNoEmail = new RegExp("^(" + rfc2822NoEmail.join("|") + "): ");
var header = /^[^:]+:/; // Optional fields defined in RFC 2822
var email = /^[^ ]+@[^ ]+/;
var untilEmail = /^.*?(?=[^ ]+?@[^ ]+)/;
var bracketedEmail = /^<.*?>/;
var untilBracketedEmail = /^.*?(?=<.*>)/;
function styleForHeader(header) {
if (header === "Subject") return "header";
return "string";
}
function readToken(stream, state) {
if (stream.sol()) {
// From last line
state.inSeparator = false;
if (state.inHeader && stream.match(whitespace)) {
// Header folding
return null;
} else {
state.inHeader = false;
state.header = null;
}
if (stream.match(separator)) {
state.inHeaders = true;
state.inSeparator = true;
return "atom";
}
var match;
var emailPermitted = false;
if ((match = stream.match(rfc2822HeaderNoEmail)) ||
(emailPermitted = true) && (match = stream.match(rfc2822Header))) {
state.inHeaders = true;
state.inHeader = true;
state.emailPermitted = emailPermitted;
state.header = match[1];
return "atom";
}
// Use vim's heuristics: recognize custom headers only if the line is in a
// block of legitimate headers.
if (state.inHeaders && (match = stream.match(header))) {
state.inHeader = true;
state.emailPermitted = true;
state.header = match[1];
return "atom";
}
state.inHeaders = false;
stream.skipToEnd();
return null;
}
if (state.inSeparator) {
if (stream.match(email)) return "link";
if (stream.match(untilEmail)) return "atom";
stream.skipToEnd();
return "atom";
}
if (state.inHeader) {
var style = styleForHeader(state.header);
if (state.emailPermitted) {
if (stream.match(bracketedEmail)) return style + " link";
if (stream.match(untilBracketedEmail)) return style;
}
stream.skipToEnd();
return style;
}
stream.skipToEnd();
return null;
};
CodeMirror.defineMode("mbox", function() {
return {
startState: function() {
return {
// Is in a mbox separator
inSeparator: false,
// Is in a mail header
inHeader: false,
// If bracketed email is permitted. Only applicable when inHeader
emailPermitted: false,
// Name of current header
header: null,
// Is in a region of mail headers
inHeaders: false
};
},
token: readToken,
blankLine: function(state) {
state.inHeaders = state.inSeparator = state.inHeader = false;
}
};
});
CodeMirror.defineMIME("application/mbox", "mbox");
});

View file

@ -87,6 +87,7 @@
{name: "Modelica", mime: "text/x-modelica", mode: "modelica", ext: ["mo"]},
{name: "MUMPS", mime: "text/x-mumps", mode: "mumps", ext: ["mps"]},
{name: "MS SQL", mime: "text/x-mssql", mode: "sql"},
{name: "mbox", mime: "application/mbox", mode: "mbox", ext: ["mbox"]},
{name: "MySQL", mime: "text/x-mysql", mode: "sql"},
{name: "Nginx", mime: "text/x-nginx-conf", mode: "nginx", file: /nginx.*\.conf$/i},
{name: "NSIS", mime: "text/x-nsis", mode: "nsis", ext: ["nsh", "nsi"]},

View file

@ -81,7 +81,7 @@ CodeMirror.defineMode("pegjs", function (config) {
return "comment";
} else if (state.braced || stream.peek() === '{') {
if (state.localState === null) {
state.localState = jsMode.startState();
state.localState = CodeMirror.startState(jsMode);
}
var token = jsMode.token(stream, state.localState);
var text = stream.current();

File diff suppressed because one or more lines are too long

View file

@ -32,13 +32,6 @@
"sorted", "staticmethod", "str", "sum", "super", "tuple",
"type", "vars", "zip", "__import__", "NotImplemented",
"Ellipsis", "__debug__"];
var py2 = {builtins: ["apply", "basestring", "buffer", "cmp", "coerce", "execfile",
"file", "intern", "long", "raw_input", "reduce", "reload",
"unichr", "unicode", "xrange", "False", "True", "None"],
keywords: ["exec", "print"]};
var py3 = {builtins: ["ascii", "bytes", "exec", "print"],
keywords: ["nonlocal", "False", "True", "None", "async", "await"]};
CodeMirror.registerHelper("hintWords", "python", commonKeywords.concat(commonBuiltins));
function top(state) {
@ -53,15 +46,6 @@
var doubleDelimiters = parserConf.doubleDelimiters || /^(\+=|\-=|\*=|%=|\/=|&=|\|=|\^=)/;
var tripleDelimiters = parserConf.tripleDelimiters || /^(\/\/=|>>=|<<=|\*\*=)/;
if (parserConf.version && parseInt(parserConf.version, 10) == 3) {
// since http://legacy.python.org/dev/peps/pep-0465/ @ is also an operator
var singleOperators = parserConf.singleOperators || /^[\+\-\*\/%&|\^~<>!@]/;
var identifiers = parserConf.identifiers|| /^[_A-Za-z\u00A1-\uFFFF][_A-Za-z0-9\u00A1-\uFFFF]*/;
} else {
var singleOperators = parserConf.singleOperators || /^[\+\-\*\/%&|\^~<>!]/;
var identifiers = parserConf.identifiers|| /^[_A-Za-z][_A-Za-z0-9]*/;
}
var hangingIndent = parserConf.hangingIndent || conf.indentUnit;
var myKeywords = commonKeywords, myBuiltins = commonBuiltins;
@ -71,13 +55,21 @@
if (parserConf.extra_builtins != undefined)
myBuiltins = myBuiltins.concat(parserConf.extra_builtins);
if (parserConf.version && parseInt(parserConf.version, 10) == 3) {
myKeywords = myKeywords.concat(py3.keywords);
myBuiltins = myBuiltins.concat(py3.builtins);
var stringPrefixes = new RegExp("^(([rb]|(br))?('{3}|\"{3}|['\"]))", "i");
var py3 = parserConf.version && parseInt(parserConf.version, 10) == 3
if (py3) {
// since http://legacy.python.org/dev/peps/pep-0465/ @ is also an operator
var singleOperators = parserConf.singleOperators || /^[\+\-\*\/%&|\^~<>!@]/;
var identifiers = parserConf.identifiers|| /^[_A-Za-z\u00A1-\uFFFF][_A-Za-z0-9\u00A1-\uFFFF]*/;
myKeywords = myKeywords.concat(["nonlocal", "False", "True", "None", "async", "await"]);
myBuiltins = myBuiltins.concat(["ascii", "bytes", "exec", "print"]);
var stringPrefixes = new RegExp("^(([rbuf]|(br))?('{3}|\"{3}|['\"]))", "i");
} else {
myKeywords = myKeywords.concat(py2.keywords);
myBuiltins = myBuiltins.concat(py2.builtins);
var singleOperators = parserConf.singleOperators || /^[\+\-\*\/%&|\^~<>!]/;
var identifiers = parserConf.identifiers|| /^[_A-Za-z][_A-Za-z0-9]*/;
myKeywords = myKeywords.concat(["exec", "print"]);
myBuiltins = myBuiltins.concat(["apply", "basestring", "buffer", "cmp", "coerce", "execfile",
"file", "intern", "long", "raw_input", "reduce", "reload",
"unichr", "unicode", "xrange", "False", "True", "None"]);
var stringPrefixes = new RegExp("^(([rub]|(ur)|(br))?('{3}|\"{3}|['\"]))", "i");
}
var keywords = wordRegexp(myKeywords);
@ -249,16 +241,16 @@
}
function tokenLexer(stream, state) {
if (stream.sol()) state.beginningOfLine = true;
var style = state.tokenize(stream, state);
var current = stream.current();
// Handle decorators
if (current == "@") {
if (parserConf.version && parseInt(parserConf.version, 10) == 3)
return stream.match(identifiers, false) ? "meta" : "operator";
else
return stream.match(identifiers, false) ? "meta" : ERRORCLASS;
}
if (state.beginningOfLine && current == "@")
return stream.match(identifiers, false) ? "meta" : py3 ? "operator" : ERRORCLASS;
if (/\S/.test(current)) state.beginningOfLine = false;
if ((style == "variable" || style == "builtin")
&& state.lastToken == "meta")

View file

@ -0,0 +1,30 @@
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function() {
var mode = CodeMirror.getMode({indentUnit: 4},
{name: "python",
version: 3,
singleLineStringErrors: false});
function MT(name) { test.mode(name, mode, Array.prototype.slice.call(arguments, 1)); }
// Error, because "foobarhello" is neither a known type or property, but
// property was expected (after "and"), and it should be in parentheses.
MT("decoratorStartOfLine",
"[meta @dec]",
"[keyword def] [def function]():",
" [keyword pass]");
MT("decoratorIndented",
"[keyword class] [def Foo]:",
" [meta @dec]",
" [keyword def] [def function]():",
" [keyword pass]");
MT("matmulWithSpace:", "[variable a] [operator @] [variable b]");
MT("matmulWithoutSpace:", "[variable a][operator @][variable b]");
MT("matmulSpaceBefore:", "[variable a] [operator @][variable b]");
MT("fValidStringPrefix", "[string f'this is a {formatted} string']");
MT("uValidStringPrefix", "[string u'this is an unicode string']");
})();

View file

@ -165,7 +165,7 @@
};
return function(stream, state) {
rubyState = state.rubyState;
state.rubyState = rubyMode.startState();
state.rubyState = CodeMirror.startState(rubyMode);
state.tokenize = runSplat;
return ruby(stream, state);
};
@ -317,7 +317,7 @@
function startSubMode(mode, state) {
var subMode = getMode(mode);
var subState = subMode.startState && subMode.startState();
var subState = CodeMirror.startState(subMode);
state.subMode = subMode;
state.subState = subState;
@ -507,8 +507,8 @@
var mode = {
// default to html mode
startState: function() {
var htmlState = htmlMode.startState();
var rubyState = rubyMode.startState();
var htmlState = CodeMirror.startState(htmlMode);
var rubyState = CodeMirror.startState(rubyMode);
return {
htmlState: htmlState,
rubyState: rubyState,

View file

@ -85,6 +85,7 @@ var singleOperators = /^[:<=>?]/;
var integers = /^-?([1-9][0-9]*|0[Xx][0-9A-Fa-f]+|0[0-7]*)/;
var floats = /^-?(([0-9]+\.[0-9]*|[0-9]*\.[0-9]+)([Ee][+-]?[0-9]+)?|[0-9]+[Ee][+-]?[0-9]+)/;
var identifiers = /^_?[A-Za-z][0-9A-Z_a-z-]*/;
var identifiersEnd = /^_?[A-Za-z][0-9A-Z_a-z-]*(?=\s*;)/;
var strings = /^"[^"]*"/;
var multilineComments = /^\/\*.*?\*\//;
var multilineCommentsStart = /^\/\*.*/;
@ -122,13 +123,12 @@ function readToken(stream, state) {
if (stream.match(strings)) return "string";
// identifier
if (stream.match(identifiers)) {
if (state.startDef) return "def";
if (state.endDef && stream.match(/^\s*;/, false)) {
if (state.startDef && stream.match(identifiers)) return "def";
if (state.endDef && stream.match(identifiersEnd)) {
state.endDef = false;
return "def";
}
}
if (stream.match(keywords)) return "keyword";

View file

@ -16,6 +16,19 @@
CodeMirror.defineMode('yacas', function(_config, _parserConfig) {
function words(str) {
var obj = {}, words = str.split(" ");
for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
return obj;
}
var bodiedOps = words("Assert BackQuote D Defun Deriv For ForEach FromFile " +
"FromString Function Integrate InverseTaylor Limit " +
"LocalSymbols Macro MacroRule MacroRulePattern " +
"NIntegrate Rule RulePattern Subst TD TExplicitSum " +
"TSum Taylor Taylor1 Taylor2 Taylor3 ToFile " +
"ToStdout ToString TraceRule Until While");
// patterns
var pFloatForm = "(?:(?:\\.\\d+|\\d+\\.\\d*|\\d+)(?:[eE][+-]?\\d+)?)";
var pIdentifier = "(?:[a-zA-Z\\$'][a-zA-Z0-9\\$']*)";
@ -53,6 +66,33 @@ CodeMirror.defineMode('yacas', function(_config, _parserConfig) {
// go back one character
stream.backUp(1);
// update scope info
var m = stream.match(/^(\w+)\s*\(/, false);
if (m !== null && bodiedOps.hasOwnProperty(m[1]))
state.scopes.push('bodied');
var scope = currentScope(state);
if (scope === 'bodied' && ch === '[')
state.scopes.pop();
if (ch === '[' || ch === '{' || ch === '(')
state.scopes.push(ch);
scope = currentScope(state);
if (scope === '[' && ch === ']' ||
scope === '{' && ch === '}' ||
scope === '(' && ch === ')')
state.scopes.pop();
if (ch === ';') {
while (scope === 'bodied') {
state.scopes.pop();
scope = currentScope(state);
}
}
// look for ordered rules
if (stream.match(/\d+ *#/, true, false)) {
return 'qualifier';
@ -111,20 +151,46 @@ CodeMirror.defineMode('yacas', function(_config, _parserConfig) {
function tokenComment(stream, state) {
var prev, next;
while((next = stream.next()) != null) {
if (prev === '*' && next === '/')
if (prev === '*' && next === '/') {
state.tokenize = tokenBase;
break;
}
prev = next;
}
state.tokenize = tokenBase;
return 'comment';
}
function currentScope(state) {
var scope = null;
if (state.scopes.length > 0)
scope = state.scopes[state.scopes.length - 1];
return scope;
}
return {
startState: function() {return {tokenize: tokenBase, commentLevel: 0};},
startState: function() {
return {
tokenize: tokenBase,
scopes: []
};
},
token: function(stream, state) {
if (stream.eatSpace()) return null;
return state.tokenize(stream, state);
},
indent: function(state, textAfter) {
if (state.tokenize !== tokenBase && state.tokenize !== null)
return CodeMirror.Pass;
var delta = 0;
if (textAfter === ']' || textAfter === '];' ||
textAfter === '}' || textAfter === '};' ||
textAfter === ');')
delta = -1;
return (state.scopes.length + delta) * _config.indentUnit;
},
electricChars: "{}[]();",
blockCommentStart: "/*",
blockCommentEnd: "*/",
lineComment: "//"

View file

@ -0,0 +1,214 @@
/**
* Atom One Solarized Theme
*
* Copyright (c) 2016 jackycute
*
* Licensed under MIT
*/
/* Editor */
.solarized .panel,
.solarized #main-toolbar {
background: #1d222a;
}
.solarized #working-set-list-container,
.solarized #editor-holder .pane-header {
background: #15181e;
}
.solarized .working-set-header,
.solarized #project-files-header .btn-alt-quiet {
background: rgba(204, 217, 255, 0.05);
}
.solarized .working-set-header > span {
background: transparent;
}
.solarized .sidebar-selection,
.solarized .filetree-selection,
.solarized .sidebar-selection-extension,
.solarized .filetree-selection-extension {
background: #282c34;
}
.solarized #status-bar,
.solarized #status-indicators {
background: #15181e;
border-top-color: #1d222a;
}
.solarized a,
.solarized .open-files-container li.selected a {
color: #528bff;
}
/* Code Styling */
.cm-s-one-solarized.CodeMirror,
.cm-s-one-solarized .CodeMirror-scroll {
/* background-color: #282c34;*/
background-color: #fdf6e3;
color: #657b83;
}
.cm-s-one-solarized .CodeMirror-activeline-background {
background: transparent;
}
.cm-s-one-solarized.CodeMirror-focused .CodeMirror-activeline-background {
background: #eee8d5;
}
.show-line-padding .cm-s-one-solarized.CodeMirror-focused .CodeMirror-activeline-background {
box-shadow: inset 15px 0 0 0 #000;
}
.cm-s-one-solarized.CodeMirror-focused .CodeMirror-activeline .CodeMirror-gutter-elt {
background: transparent;
color: #5c6370;
}
.cm-s-one-solarized.CodeMirror-focused .CodeMirror-activeline .inline-widget .CodeMirror-gutter-elt {
color: red;
}
.cm-s-one-solarized .cm-string-2,
.cm-s-one-solarized .cm-hr {
color: #2aa198;
}
.cm-s-one-solarized .cm-number,
.cm-s-one-solarized .cm-attribute,
.cm-s-one-solarized .cm-qualifier,
.cm-s-one-solarized .cm-plus,
.cm-s-one-solarized .cm-atom {
color: #b58900;
}
.cm-s-one-solarized .cm-def {
color: #c678dd;
}
.cm-s-one-solarized .cm-property,
.cm-s-one-solarized .cm-variable,
.cm-s-one-solarized .cm-variable-2,
.cm-s-one-solarized .cm-variable-3,
.cm-s-one-solarized .cm-operator,
/*.cm-meta,*/
.cm-s-one-solarized .cm-bracket {
color: #b58900;
}
/*borrow from tomorrow-night-eighties*/
.cm-s-one-solarized .cm-variable {
color: #839496;
}
.cm-s-one-solarized .cm-variable-2 {
color: #cb4b16;
}
.cm-s-one-solarized .cm-comment {
color: #93a1a1;
font-style: italic;
}
.cm-s-one-solarized .cm-error,
.cm-s-one-solarized .cm-minus {
color: #be5046;
}
.cm-s-one-solarized .cm-header {
color: #268bd2;
}
.cm-s-one-solarized .cm-link {
color: #2aa198;
text-decoration: none;
}
.cm-s-one-solarized .cm-rangeinfo {
color: #c678dd;
}
.cm-s-one-solarized .cm-keyword,
.cm-s-one-solarized .cm-builtin,
.cm-s-one-solarized .cm-tag {
color: #268bd2;
}
.cm-s-one-solarized .cm-string {
/* color: #98c379;*/
color: #cb4b16;
}
/* Extra CSS */
.cm-s-one-solarized .CodeMirror-searching {
color: #fff !important;
border: 1px solid #1e3f47;
margin: 0 -1px;
background-color: rgba(147, 161, 161, 0.09);
box-shadow: 0px 0px 6px rgba(66, 133, 244, 0.4);
}
.cm-s-one-solarized .CodeMirror-searching.searching-current-match {
color: #fff;
background-color: #1e3f47;
box-shadow: 0px 0px 6px rgba(66, 133, 244, 0.8);
}
.cm-s-one-solarized .CodeMirror-cursor {
border-left: 2px solid #1e3f47 !important;
}
.cm-fat-cursor .CodeMirror-cursor {
border-left: 2px solid #667b83 !important;
background: #667b83;
}
.cm-s-one-solarized .CodeMirror-gutters {
/* background-color: #282c34;*/
background-color: #eee8d5;
border-right: 1px solid rgba(147, 161, 161, 0.05);
}
.cm-s-one-solarized .CodeMirror-linenumber {
color: #6f838c;
}
.cm-s-one-solarized.CodeMirror .CodeMirror-selected {
background: rgba(147, 161, 161, 0.05);
}
.cm-s-one-solarized.CodeMirror-focused .CodeMirror-selected {
background: rgba(147, 161, 161, 0.09);
}
.cm-s-one-solarized .CodeMirror-matchingbracket,
.cm-s-one-solarized .CodeMirror-matchingtag {
/* Ensure visibility against gray inline editor background */
background-color: rgba(147, 161, 161, 0.09);
color: #657b83 !important;
border-bottom: 1px solid #1e3f47;
}
.cm-s-one-solarized .CodeMirror-overwrite .CodeMirror-cursor {
border-left: none !important;
border-bottom: 1px solid #fff;
width: 0.5em;
}
.cm-s-one-solarized.CodeMirror .CodeMirror {
background: transparent;
}
.cm-s-one-solarized.CodeMirror .CodeMirror .CodeMirror-gutters {
background: transparent;
border-right: none;
}
.cm-s-one-solarized.CodeMirror .CodeMirror .CodeMirror-activeline-background {
background: transparent;
}
.cm-s-one-solarized.CodeMirror .CodeMirror .CodeMirror-activeline .CodeMirror-gutter-elt {
background: transparent;
color: #5c6370;
}
.cm-s-one-solarized.CodeMirror .CodeMirror-focused .CodeMirror-activeline-background {
background: #000;
}
.cm-s-one-solarized.CodeMirror .CodeMirror-focused .CodeMirror-activeline .CodeMirror-gutter-elt {
background: rgba(147, 161, 161, 0.05);
color: #fff;
}
.cm-s-one-solarized .CodeMirror-foldgutter-open:after {
color: #393e46;
}
.cm-s-one-solarized .CodeMirror-foldgutter-folded:after {
color: #5c6370;
}
.cm-s-one-solarized .CodeMirror.over-gutter .CodeMirror-foldgutter-open:after,
.cm-s-one-solarized.CodeMirror-focused .CodeMirror-activeline .CodeMirror-foldgutter-open:after {
color: #5c6370;
}
.cm-s-one-solarized .CodeMirror-foldmarker {
border-color: #393e46;
color: #abb2bf;
background: rgba(147, 161, 161, 0.05);
}
/* Non-editor styling */
.image-view,
.not-editor {
background-color: #282c34;
}
.view-pane .image-view {
color: #abb2bf;
}
.cm-s-one-solarized .CodeMirror-overlayscroll-horizontal div,
.cm-s-one-solarized .CodeMirror-overlayscroll-vertical div {
border: 2px solid #fdf6e3;
}

View file

@ -4,7 +4,7 @@ http://ethanschoonover.com/solarized
*/
/*
Solarized color pallet
Solarized color palette
http://ethanschoonover.com/solarized/img/solarized-palette.png
*/
@ -113,32 +113,34 @@ http://ethanschoonover.com/solarized/img/solarized-palette.png
box-shadow: inset 7px 0 12px -6px #000;
}
/* Gutter border and some shadow from it */
/* Remove gutter border */
.cm-s-solarized .CodeMirror-gutters {
border-right: 1px solid;
border-right: 0;
}
/* Gutter colors and line number styling based of color scheme (dark / light) */
/* Dark */
.cm-s-solarized.cm-s-dark .CodeMirror-gutters {
background-color: #002b36;
border-color: #00232c;
background-color: #073642;
}
.cm-s-solarized.cm-s-dark .CodeMirror-linenumber {
color: #586e75;
text-shadow: #021014 0 -1px;
}
/* Light */
.cm-s-solarized.cm-s-light .CodeMirror-gutters {
background-color: #fdf6e3;
border-color: #eee8d5;
background-color: #eee8d5;
}
.cm-s-solarized.cm-s-light .CodeMirror-linenumber {
color: #839496;
}
/* Common */
.cm-s-solarized .CodeMirror-linenumber {
color: #586e75;
padding: 0 5px;
}
.cm-s-solarized .CodeMirror-guttermarker-subtle { color: #586e75; }
@ -149,15 +151,19 @@ http://ethanschoonover.com/solarized/img/solarized-palette.png
color: #586e75;
}
/* Cursor */
.cm-s-solarized .CodeMirror-cursor { border-left: 1px solid #819090; }
/*
Active line. Negative margin compensates left padding of the text in the
view-port
*/
/* Fat cursor */
.cm-s-solarized.cm-s-light.cm-fat-cursor .CodeMirror-cursor { background: #fdf6e3; }
.cm-s-solarized.cm-s-light .cm-animate-fat-cursor { background-color: #fdf6e3; }
.cm-s-solarized.cm-s-dark.cm-fat-cursor .CodeMirror-cursor { background: #586e75; }
.cm-s-solarized.cm-s-dark .cm-animate-fat-cursor { background-color: #586e75; }
/* Active line */
.cm-s-solarized.cm-s-dark .CodeMirror-activeline-background {
background: rgba(255, 255, 255, 0.10);
background: rgba(255, 255, 255, 0.06);
}
.cm-s-solarized.cm-s-light .CodeMirror-activeline-background {
background: rgba(0, 0, 0, 0.10);
background: rgba(0, 0, 0, 0.06);
}