Bug 1242309 - Upgrade to CodeMirror 5.11.0 r=bgrins

This commit is contained in:
Gabriel Luong 2016-01-25 14:46:22 -05:00
Родитель b905e1271d
Коммит 998ec86a10
10 изменённых файлов: 128 добавлений и 106 удалений

Просмотреть файл

@ -5,7 +5,7 @@ code, and optionally help with indentation.
# Upgrade # Upgrade
Currently used version is 5.10.0. To upgrade, download a new version of Currently used version is 5.11.0. To upgrade, download a new version of
CodeMirror from the project's page [1] and replace all JavaScript and CodeMirror from the project's page [1] and replace all JavaScript and
CSS files inside the codemirror directory [2]. CSS files inside the codemirror directory [2].

Просмотреть файл

@ -63,7 +63,7 @@
} }
for (var i = ranges.length - 1; i >= 0; i--) { for (var i = ranges.length - 1; i >= 0; i--) {
var cur = ranges[i].head; var cur = ranges[i].head;
cm.replaceRange("", Pos(cur.line, cur.ch - 1), Pos(cur.line, cur.ch + 1)); cm.replaceRange("", Pos(cur.line, cur.ch - 1), Pos(cur.line, cur.ch + 1), "+delete");
} }
} }

Просмотреть файл

@ -20,7 +20,7 @@
cm.off("viewportChange", onViewportChange); cm.off("viewportChange", onViewportChange);
cm.off("fold", onFold); cm.off("fold", onFold);
cm.off("unfold", onFold); cm.off("unfold", onFold);
cm.off("swapDoc", updateInViewport); cm.off("swapDoc", onChange);
} }
if (val) { if (val) {
cm.state.foldGutter = new State(parseOptions(val)); cm.state.foldGutter = new State(parseOptions(val));
@ -30,7 +30,7 @@
cm.on("viewportChange", onViewportChange); cm.on("viewportChange", onViewportChange);
cm.on("fold", onFold); cm.on("fold", onFold);
cm.on("unfold", onFold); cm.on("unfold", onFold);
cm.on("swapDoc", updateInViewport); cm.on("swapDoc", onChange);
} }
}); });

27
devtools/client/sourceeditor/codemirror/lib/codemirror.js поставляемый Normal file → Executable file
Просмотреть файл

@ -1258,6 +1258,7 @@
}); });
function prepareCopyCut(e) { function prepareCopyCut(e) {
if (signalDOMEvent(cm, e)) return
if (cm.somethingSelected()) { if (cm.somethingSelected()) {
lastCopied = cm.getSelections(); lastCopied = cm.getSelections();
if (input.inaccurateSelection) { if (input.inaccurateSelection) {
@ -1615,6 +1616,7 @@
}); });
function onCopyCut(e) { function onCopyCut(e) {
if (signalDOMEvent(cm, e)) return
if (cm.somethingSelected()) { if (cm.somethingSelected()) {
lastCopied = cm.getSelections(); lastCopied = cm.getSelections();
if (e.type == "cut") cm.replaceSelection("", null, "cut"); if (e.type == "cut") cm.replaceSelection("", null, "cut");
@ -3433,7 +3435,7 @@
return dx * dx + dy * dy > 20 * 20; return dx * dx + dy * dy > 20 * 20;
} }
on(d.scroller, "touchstart", function(e) { on(d.scroller, "touchstart", function(e) {
if (!isMouseLikeTouchEvent(e)) { if (!signalDOMEvent(cm, e) && !isMouseLikeTouchEvent(e)) {
clearTimeout(touchFinished); clearTimeout(touchFinished);
var now = +new Date; var now = +new Date;
d.activeTouch = {start: now, moved: false, d.activeTouch = {start: now, moved: false,
@ -3562,7 +3564,7 @@
// not interfere with, such as a scrollbar or widget. // not interfere with, such as a scrollbar or widget.
function onMouseDown(e) { function onMouseDown(e) {
var cm = this, display = cm.display; var cm = this, display = cm.display;
if (display.activeTouch && display.input.supportsTouch() || signalDOMEvent(cm, e)) return; if (signalDOMEvent(cm, e) || display.activeTouch && display.input.supportsTouch()) return;
display.shift = e.shiftKey; display.shift = e.shiftKey;
if (eventInWidget(display, e)) { if (eventInWidget(display, e)) {
@ -4814,10 +4816,9 @@
function findPosH(doc, pos, dir, unit, visually) { function findPosH(doc, pos, dir, unit, visually) {
var line = pos.line, ch = pos.ch, origDir = dir; var line = pos.line, ch = pos.ch, origDir = dir;
var lineObj = getLine(doc, line); var lineObj = getLine(doc, line);
var possible = true;
function findNextLine() { function findNextLine() {
var l = line + dir; var l = line + dir;
if (l < doc.first || l >= doc.first + doc.size) return (possible = false); if (l < doc.first || l >= doc.first + doc.size) return false
line = l; line = l;
return lineObj = getLine(doc, l); return lineObj = getLine(doc, l);
} }
@ -4827,14 +4828,16 @@
if (!boundToLine && findNextLine()) { if (!boundToLine && findNextLine()) {
if (visually) ch = (dir < 0 ? lineRight : lineLeft)(lineObj); if (visually) ch = (dir < 0 ? lineRight : lineLeft)(lineObj);
else ch = dir < 0 ? lineObj.text.length : 0; else ch = dir < 0 ? lineObj.text.length : 0;
} else return (possible = false); } else return false
} else ch = next; } else ch = next;
return true; return true;
} }
if (unit == "char") moveOnce(); if (unit == "char") {
else if (unit == "column") moveOnce(true); moveOnce()
else if (unit == "word" || unit == "group") { } else if (unit == "column") {
moveOnce(true)
} else if (unit == "word" || unit == "group") {
var sawType = null, group = unit == "group"; var sawType = null, group = unit == "group";
var helper = doc.cm && doc.cm.getHelper(pos, "wordChars"); var helper = doc.cm && doc.cm.getHelper(pos, "wordChars");
for (var first = true;; first = false) { for (var first = true;; first = false) {
@ -4855,7 +4858,7 @@
} }
} }
var result = skipAtomic(doc, Pos(line, ch), pos, origDir, true); var result = skipAtomic(doc, Pos(line, ch), pos, origDir, true);
if (!possible) result.hitSide = true; if (!cmp(pos, result)) result.hitSide = true;
return result; return result;
} }
@ -7113,14 +7116,14 @@
if (endStyles) for (var j = 0; j < endStyles.length; j += 2) if (endStyles) for (var j = 0; j < endStyles.length; j += 2)
if (endStyles[j + 1] == nextChange) spanEndStyle += " " + endStyles[j] if (endStyles[j + 1] == nextChange) spanEndStyle += " " + endStyles[j]
if (!collapsed || collapsed.from == pos) for (var j = 0; j < foundBookmarks.length; ++j)
buildCollapsedSpan(builder, 0, foundBookmarks[j]);
if (collapsed && (collapsed.from || 0) == pos) { if (collapsed && (collapsed.from || 0) == pos) {
buildCollapsedSpan(builder, (collapsed.to == null ? len + 1 : collapsed.to) - pos, buildCollapsedSpan(builder, (collapsed.to == null ? len + 1 : collapsed.to) - pos,
collapsed.marker, collapsed.from == null); collapsed.marker, collapsed.from == null);
if (collapsed.to == null) return; if (collapsed.to == null) return;
if (collapsed.to == pos) collapsed = false; if (collapsed.to == pos) collapsed = false;
} }
if (!collapsed && foundBookmarks.length) for (var j = 0; j < foundBookmarks.length; ++j)
buildCollapsedSpan(builder, 0, foundBookmarks[j]);
} }
if (pos >= len) break; if (pos >= len) break;
@ -8881,7 +8884,7 @@
// THE END // THE END
CodeMirror.version = "5.10.0"; CodeMirror.version = "5.11.0";
return CodeMirror; return CodeMirror;
}); });

4
devtools/client/sourceeditor/codemirror/mode/clike.js поставляемый Normal file → Executable file
Просмотреть файл

@ -264,9 +264,7 @@ CodeMirror.defineMode("clike", function(config, parserConfig) {
function cppHook(stream, state) { function cppHook(stream, state) {
if (!state.startOfLine) return false if (!state.startOfLine) return false
for (var ch, next = null; ch = stream.peek();) { for (var ch, next = null; ch = stream.peek();) {
if (!ch) { if (ch == "\\" && stream.match(/^.$/)) {
break
} else if (ch == "\\" && stream.match(/^.$/)) {
next = cppHook next = cppHook
break break
} else if (ch == "/" && stream.match(/^\/[\/\*]/, false)) { } else if (ch == "/" && stream.match(/^\/[\/\*]/, false)) {

27
devtools/client/sourceeditor/codemirror/mode/css.js поставляемый Normal file → Executable file
Просмотреть файл

@ -452,8 +452,8 @@ CodeMirror.defineMode("css", function(config, parserConfig) {
"animation-direction", "animation-duration", "animation-fill-mode", "animation-direction", "animation-duration", "animation-fill-mode",
"animation-iteration-count", "animation-name", "animation-play-state", "animation-iteration-count", "animation-name", "animation-play-state",
"animation-timing-function", "appearance", "azimuth", "backface-visibility", "animation-timing-function", "appearance", "azimuth", "backface-visibility",
"background", "background-attachment", "background-clip", "background-color", "background", "background-attachment", "background-blend-mode", "background-clip",
"background-image", "background-origin", "background-position", "background-color", "background-image", "background-origin", "background-position",
"background-repeat", "background-size", "baseline-shift", "binding", "background-repeat", "background-size", "baseline-shift", "binding",
"bleed", "bookmark-label", "bookmark-level", "bookmark-state", "bleed", "bookmark-label", "bookmark-level", "bookmark-state",
"bookmark-target", "border", "border-bottom", "border-bottom-color", "bookmark-target", "border", "border-bottom", "border-bottom-color",
@ -597,11 +597,12 @@ CodeMirror.defineMode("css", function(config, parserConfig) {
"capitalize", "caps-lock-indicator", "caption", "captiontext", "caret", "capitalize", "caps-lock-indicator", "caption", "captiontext", "caret",
"cell", "center", "checkbox", "circle", "cjk-decimal", "cjk-earthly-branch", "cell", "center", "checkbox", "circle", "cjk-decimal", "cjk-earthly-branch",
"cjk-heavenly-stem", "cjk-ideographic", "clear", "clip", "close-quote", "cjk-heavenly-stem", "cjk-ideographic", "clear", "clip", "close-quote",
"col-resize", "collapse", "column", "column-reverse", "compact", "condensed", "contain", "content", "col-resize", "collapse", "color", "color-burn", "color-dodge", "column", "column-reverse",
"compact", "condensed", "contain", "content",
"content-box", "context-menu", "continuous", "copy", "counter", "counters", "cover", "crop", "content-box", "context-menu", "continuous", "copy", "counter", "counters", "cover", "crop",
"cross", "crosshair", "currentcolor", "cursive", "cyclic", "dashed", "decimal", "cross", "crosshair", "currentcolor", "cursive", "cyclic", "darken", "dashed", "decimal",
"decimal-leading-zero", "default", "default-button", "destination-atop", "decimal-leading-zero", "default", "default-button", "destination-atop",
"destination-in", "destination-out", "destination-over", "devanagari", "destination-in", "destination-out", "destination-over", "devanagari", "difference",
"disc", "discard", "disclosure-closed", "disclosure-open", "document", "disc", "discard", "disclosure-closed", "disclosure-open", "document",
"dot-dash", "dot-dot-dash", "dot-dash", "dot-dot-dash",
"dotted", "double", "down", "e-resize", "ease", "ease-in", "ease-in-out", "ease-out", "dotted", "double", "down", "e-resize", "ease", "ease-in", "ease-in-out", "ease-out",
@ -612,23 +613,23 @@ CodeMirror.defineMode("css", function(config, parserConfig) {
"ethiopic-halehame-gez", "ethiopic-halehame-om-et", "ethiopic-halehame-gez", "ethiopic-halehame-om-et",
"ethiopic-halehame-sid-et", "ethiopic-halehame-so-et", "ethiopic-halehame-sid-et", "ethiopic-halehame-so-et",
"ethiopic-halehame-ti-er", "ethiopic-halehame-ti-et", "ethiopic-halehame-tig", "ethiopic-halehame-ti-er", "ethiopic-halehame-ti-et", "ethiopic-halehame-tig",
"ethiopic-numeric", "ew-resize", "expanded", "extends", "extra-condensed", "ethiopic-numeric", "ew-resize", "exclusion", "expanded", "extends", "extra-condensed",
"extra-expanded", "fantasy", "fast", "fill", "fixed", "flat", "flex", "flex-end", "flex-start", "footnotes", "extra-expanded", "fantasy", "fast", "fill", "fixed", "flat", "flex", "flex-end", "flex-start", "footnotes",
"forwards", "from", "geometricPrecision", "georgian", "graytext", "groove", "forwards", "from", "geometricPrecision", "georgian", "graytext", "groove",
"gujarati", "gurmukhi", "hand", "hangul", "hangul-consonant", "hebrew", "gujarati", "gurmukhi", "hand", "hangul", "hangul-consonant", "hard-light", "hebrew",
"help", "hidden", "hide", "higher", "highlight", "highlighttext", "help", "hidden", "hide", "higher", "highlight", "highlighttext",
"hiragana", "hiragana-iroha", "horizontal", "hsl", "hsla", "icon", "ignore", "hiragana", "hiragana-iroha", "horizontal", "hsl", "hsla", "hue", "icon", "ignore",
"inactiveborder", "inactivecaption", "inactivecaptiontext", "infinite", "inactiveborder", "inactivecaption", "inactivecaptiontext", "infinite",
"infobackground", "infotext", "inherit", "initial", "inline", "inline-axis", "infobackground", "infotext", "inherit", "initial", "inline", "inline-axis",
"inline-block", "inline-flex", "inline-table", "inset", "inside", "intrinsic", "invert", "inline-block", "inline-flex", "inline-table", "inset", "inside", "intrinsic", "invert",
"italic", "japanese-formal", "japanese-informal", "justify", "kannada", "italic", "japanese-formal", "japanese-informal", "justify", "kannada",
"katakana", "katakana-iroha", "keep-all", "khmer", "katakana", "katakana-iroha", "keep-all", "khmer",
"korean-hangul-formal", "korean-hanja-formal", "korean-hanja-informal", "korean-hangul-formal", "korean-hanja-formal", "korean-hanja-informal",
"landscape", "lao", "large", "larger", "left", "level", "lighter", "landscape", "lao", "large", "larger", "left", "level", "lighter", "lighten",
"line-through", "linear", "linear-gradient", "lines", "list-item", "listbox", "listitem", "line-through", "linear", "linear-gradient", "lines", "list-item", "listbox", "listitem",
"local", "logical", "loud", "lower", "lower-alpha", "lower-armenian", "local", "logical", "loud", "lower", "lower-alpha", "lower-armenian",
"lower-greek", "lower-hexadecimal", "lower-latin", "lower-norwegian", "lower-greek", "lower-hexadecimal", "lower-latin", "lower-norwegian",
"lower-roman", "lowercase", "ltr", "malayalam", "match", "matrix", "matrix3d", "lower-roman", "lowercase", "ltr", "luminosity", "malayalam", "match", "matrix", "matrix3d",
"media-controls-background", "media-current-time-display", "media-controls-background", "media-current-time-display",
"media-fullscreen-button", "media-mute-button", "media-play-button", "media-fullscreen-button", "media-mute-button", "media-play-button",
"media-return-to-realtime-button", "media-rewind-button", "media-return-to-realtime-button", "media-rewind-button",
@ -637,7 +638,7 @@ CodeMirror.defineMode("css", function(config, parserConfig) {
"media-volume-slider-container", "media-volume-sliderthumb", "medium", "media-volume-slider-container", "media-volume-sliderthumb", "medium",
"menu", "menulist", "menulist-button", "menulist-text", "menu", "menulist", "menulist-button", "menulist-text",
"menulist-textfield", "menutext", "message-box", "middle", "min-intrinsic", "menulist-textfield", "menutext", "message-box", "middle", "min-intrinsic",
"mix", "mongolian", "monospace", "move", "multiple", "myanmar", "n-resize", "mix", "mongolian", "monospace", "move", "multiple", "multiply", "myanmar", "n-resize",
"narrower", "ne-resize", "nesw-resize", "no-close-quote", "no-drop", "narrower", "ne-resize", "nesw-resize", "no-close-quote", "no-drop",
"no-open-quote", "no-repeat", "none", "normal", "not-allowed", "nowrap", "no-open-quote", "no-repeat", "none", "normal", "not-allowed", "nowrap",
"ns-resize", "numbers", "numeric", "nw-resize", "nwse-resize", "oblique", "octal", "open-quote", "ns-resize", "numbers", "numeric", "nw-resize", "nwse-resize", "oblique", "octal", "open-quote",
@ -651,7 +652,7 @@ CodeMirror.defineMode("css", function(config, parserConfig) {
"repeating-radial-gradient", "repeat-x", "repeat-y", "reset", "reverse", "repeating-radial-gradient", "repeat-x", "repeat-y", "reset", "reverse",
"rgb", "rgba", "ridge", "right", "rotate", "rotate3d", "rotateX", "rotateY", "rgb", "rgba", "ridge", "right", "rotate", "rotate3d", "rotateX", "rotateY",
"rotateZ", "round", "row", "row-resize", "row-reverse", "rtl", "run-in", "running", "rotateZ", "round", "row", "row-resize", "row-reverse", "rtl", "run-in", "running",
"s-resize", "sans-serif", "scale", "scale3d", "scaleX", "scaleY", "scaleZ", "s-resize", "sans-serif", "saturation", "scale", "scale3d", "scaleX", "scaleY", "scaleZ", "screen",
"scroll", "scrollbar", "se-resize", "searchfield", "scroll", "scrollbar", "se-resize", "searchfield",
"searchfield-cancel-button", "searchfield-decoration", "searchfield-cancel-button", "searchfield-decoration",
"searchfield-results-button", "searchfield-results-decoration", "searchfield-results-button", "searchfield-results-decoration",
@ -659,7 +660,7 @@ CodeMirror.defineMode("css", function(config, parserConfig) {
"simp-chinese-formal", "simp-chinese-informal", "single", "simp-chinese-formal", "simp-chinese-informal", "single",
"skew", "skewX", "skewY", "skip-white-space", "slide", "slider-horizontal", "skew", "skewX", "skewY", "skip-white-space", "slide", "slider-horizontal",
"slider-vertical", "sliderthumb-horizontal", "sliderthumb-vertical", "slow", "slider-vertical", "sliderthumb-horizontal", "sliderthumb-vertical", "slow",
"small", "small-caps", "small-caption", "smaller", "solid", "somali", "small", "small-caps", "small-caption", "smaller", "soft-light", "solid", "somali",
"source-atop", "source-in", "source-out", "source-over", "space", "space-around", "space-between", "spell-out", "square", "source-atop", "source-in", "source-out", "source-over", "space", "space-around", "space-between", "spell-out", "square",
"square-button", "start", "static", "status-bar", "stretch", "stroke", "sub", "square-button", "start", "static", "status-bar", "stretch", "stroke", "sub",
"subpixel-antialiased", "super", "sw-resize", "symbolic", "symbols", "table", "subpixel-antialiased", "super", "sw-resize", "symbolic", "symbols", "table",

19
devtools/client/sourceeditor/codemirror/mode/javascript.js поставляемый Normal file → Executable file
Просмотреть файл

@ -13,6 +13,11 @@
})(function(CodeMirror) { })(function(CodeMirror) {
"use strict"; "use strict";
function expressionAllowed(stream, state, backUp) {
return /^(?:operator|sof|keyword c|case|new|[\[{}\(,;:]|=>)$/.test(state.lastType) ||
(state.lastType == "quasi" && /\{\s*$/.test(stream.string.slice(0, stream.pos - (backUp || 0))))
}
CodeMirror.defineMode("javascript", function(config, parserConfig) { CodeMirror.defineMode("javascript", function(config, parserConfig) {
var indentUnit = config.indentUnit; var indentUnit = config.indentUnit;
var statementIndent = parserConfig.statementIndent; var statementIndent = parserConfig.statementIndent;
@ -126,8 +131,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
} else if (stream.eat("/")) { } else if (stream.eat("/")) {
stream.skipToEnd(); stream.skipToEnd();
return ret("comment", "comment"); return ret("comment", "comment");
} else if (/^(?:operator|sof|keyword c|case|new|[\[{}\(,;:])$/.test(state.lastType) || } else if (expressionAllowed(stream, state, 1)) {
(state.lastType == "quasi" && /\{\s*$/.test(stream.string.slice(0, stream.pos - 1)))) {
readRegexp(stream); readRegexp(stream);
stream.match(/^\b(([gimyu])(?![gimyu]*\2))+\b/); stream.match(/^\b(([gimyu])(?![gimyu]*\2))+\b/);
return ret("regexp", "string-2"); return ret("regexp", "string-2");
@ -533,6 +537,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
} }
if (type == "variable") cx.marked = "property"; if (type == "variable") cx.marked = "property";
if (type == "spread") return cont(pattern); if (type == "spread") return cont(pattern);
if (type == "}") return pass();
return cont(expect(":"), pattern, maybeAssign); return cont(expect(":"), pattern, maybeAssign);
} }
function maybeAssign(_type, value) { function maybeAssign(_type, value) {
@ -655,7 +660,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
lexical: new JSLexical((basecolumn || 0) - indentUnit, 0, "block", false), lexical: new JSLexical((basecolumn || 0) - indentUnit, 0, "block", false),
localVars: parserConfig.localVars, localVars: parserConfig.localVars,
context: parserConfig.localVars && {vars: parserConfig.localVars}, context: parserConfig.localVars && {vars: parserConfig.localVars},
indented: 0 indented: basecolumn || 0
}; };
if (parserConfig.globalVars && typeof parserConfig.globalVars == "object") if (parserConfig.globalVars && typeof parserConfig.globalVars == "object")
state.globalVars = parserConfig.globalVars; state.globalVars = parserConfig.globalVars;
@ -711,7 +716,13 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
helperType: jsonMode ? "json" : "javascript", helperType: jsonMode ? "json" : "javascript",
jsonldMode: jsonldMode, jsonldMode: jsonldMode,
jsonMode: jsonMode jsonMode: jsonMode,
expressionAllowed: expressionAllowed,
skipExpression: function(state) {
var top = state.cc[state.cc.length - 1]
if (top == expression || top == expressionNoComma) state.cc.pop()
}
}; };
}); });

Просмотреть файл

@ -11,54 +11,56 @@
})(function(CodeMirror) { })(function(CodeMirror) {
"use strict"; "use strict";
CodeMirror.defineMode("xml", function(config, parserConfig) { var htmlConfig = {
var indentUnit = config.indentUnit; autoSelfClosers: {'area': true, 'base': true, 'br': true, 'col': true, 'command': true,
var multilineTagIndentFactor = parserConfig.multilineTagIndentFactor || 1; 'embed': true, 'frame': true, 'hr': true, 'img': true, 'input': true,
var multilineTagIndentPastTag = parserConfig.multilineTagIndentPastTag; 'keygen': true, 'link': true, 'meta': true, 'param': true, 'source': true,
if (multilineTagIndentPastTag == null) multilineTagIndentPastTag = true; 'track': true, 'wbr': true, 'menuitem': true},
implicitlyClosed: {'dd': true, 'li': true, 'optgroup': true, 'option': true, 'p': true,
'rp': true, 'rt': true, 'tbody': true, 'td': true, 'tfoot': true,
'th': true, 'tr': true},
contextGrabbers: {
'dd': {'dd': true, 'dt': true},
'dt': {'dd': true, 'dt': true},
'li': {'li': true},
'option': {'option': true, 'optgroup': true},
'optgroup': {'optgroup': true},
'p': {'address': true, 'article': true, 'aside': true, 'blockquote': true, 'dir': true,
'div': true, 'dl': true, 'fieldset': true, 'footer': true, 'form': true,
'h1': true, 'h2': true, 'h3': true, 'h4': true, 'h5': true, 'h6': true,
'header': true, 'hgroup': true, 'hr': true, 'menu': true, 'nav': true, 'ol': true,
'p': true, 'pre': true, 'section': true, 'table': true, 'ul': true},
'rp': {'rp': true, 'rt': true},
'rt': {'rp': true, 'rt': true},
'tbody': {'tbody': true, 'tfoot': true},
'td': {'td': true, 'th': true},
'tfoot': {'tbody': true},
'th': {'td': true, 'th': true},
'thead': {'tbody': true, 'tfoot': true},
'tr': {'tr': true}
},
doNotIndent: {"pre": true},
allowUnquoted: true,
allowMissing: true,
caseFold: true
}
var Kludges = parserConfig.htmlMode ? { var xmlConfig = {
autoSelfClosers: {'area': true, 'base': true, 'br': true, 'col': true, 'command': true, autoSelfClosers: {},
'embed': true, 'frame': true, 'hr': true, 'img': true, 'input': true, implicitlyClosed: {},
'keygen': true, 'link': true, 'meta': true, 'param': true, 'source': true, contextGrabbers: {},
'track': true, 'wbr': true, 'menuitem': true}, doNotIndent: {},
implicitlyClosed: {'dd': true, 'li': true, 'optgroup': true, 'option': true, 'p': true, allowUnquoted: false,
'rp': true, 'rt': true, 'tbody': true, 'td': true, 'tfoot': true, allowMissing: false,
'th': true, 'tr': true}, caseFold: false
contextGrabbers: { }
'dd': {'dd': true, 'dt': true},
'dt': {'dd': true, 'dt': true}, CodeMirror.defineMode("xml", function(editorConf, config_) {
'li': {'li': true}, var indentUnit = editorConf.indentUnit
'option': {'option': true, 'optgroup': true}, var config = {}
'optgroup': {'optgroup': true}, var defaults = config_.htmlMode ? htmlConfig : xmlConfig
'p': {'address': true, 'article': true, 'aside': true, 'blockquote': true, 'dir': true, for (var prop in defaults) config[prop] = defaults[prop]
'div': true, 'dl': true, 'fieldset': true, 'footer': true, 'form': true, for (var prop in config_) config[prop] = config_[prop]
'h1': true, 'h2': true, 'h3': true, 'h4': true, 'h5': true, 'h6': true,
'header': true, 'hgroup': true, 'hr': true, 'menu': true, 'nav': true, 'ol': true,
'p': true, 'pre': true, 'section': true, 'table': true, 'ul': true},
'rp': {'rp': true, 'rt': true},
'rt': {'rp': true, 'rt': true},
'tbody': {'tbody': true, 'tfoot': true},
'td': {'td': true, 'th': true},
'tfoot': {'tbody': true},
'th': {'td': true, 'th': true},
'thead': {'tbody': true, 'tfoot': true},
'tr': {'tr': true}
},
doNotIndent: {"pre": true},
allowUnquoted: true,
allowMissing: true,
caseFold: true
} : {
autoSelfClosers: {},
implicitlyClosed: {},
contextGrabbers: {},
doNotIndent: {},
allowUnquoted: false,
allowMissing: false,
caseFold: false
};
var alignCDATA = parserConfig.alignCDATA;
// Return variables for tokenizers // Return variables for tokenizers
var type, setStyle; var type, setStyle;
@ -188,7 +190,7 @@ CodeMirror.defineMode("xml", function(config, parserConfig) {
this.tagName = tagName; this.tagName = tagName;
this.indent = state.indented; this.indent = state.indented;
this.startOfLine = startOfLine; this.startOfLine = startOfLine;
if (Kludges.doNotIndent.hasOwnProperty(tagName) || (state.context && state.context.noIndent)) if (config.doNotIndent.hasOwnProperty(tagName) || (state.context && state.context.noIndent))
this.noIndent = true; this.noIndent = true;
} }
function popContext(state) { function popContext(state) {
@ -201,8 +203,8 @@ CodeMirror.defineMode("xml", function(config, parserConfig) {
return; return;
} }
parentTagName = state.context.tagName; parentTagName = state.context.tagName;
if (!Kludges.contextGrabbers.hasOwnProperty(parentTagName) || if (!config.contextGrabbers.hasOwnProperty(parentTagName) ||
!Kludges.contextGrabbers[parentTagName].hasOwnProperty(nextTagName)) { !config.contextGrabbers[parentTagName].hasOwnProperty(nextTagName)) {
return; return;
} }
popContext(state); popContext(state);
@ -233,7 +235,7 @@ CodeMirror.defineMode("xml", function(config, parserConfig) {
if (type == "word") { if (type == "word") {
var tagName = stream.current(); var tagName = stream.current();
if (state.context && state.context.tagName != tagName && if (state.context && state.context.tagName != tagName &&
Kludges.implicitlyClosed.hasOwnProperty(state.context.tagName)) config.implicitlyClosed.hasOwnProperty(state.context.tagName))
popContext(state); popContext(state);
if (state.context && state.context.tagName == tagName) { if (state.context && state.context.tagName == tagName) {
setStyle = "tag"; setStyle = "tag";
@ -269,7 +271,7 @@ CodeMirror.defineMode("xml", function(config, parserConfig) {
var tagName = state.tagName, tagStart = state.tagStart; var tagName = state.tagName, tagStart = state.tagStart;
state.tagName = state.tagStart = null; state.tagName = state.tagStart = null;
if (type == "selfcloseTag" || if (type == "selfcloseTag" ||
Kludges.autoSelfClosers.hasOwnProperty(tagName)) { config.autoSelfClosers.hasOwnProperty(tagName)) {
maybePopContext(state, tagName); maybePopContext(state, tagName);
} else { } else {
maybePopContext(state, tagName); maybePopContext(state, tagName);
@ -282,12 +284,12 @@ CodeMirror.defineMode("xml", function(config, parserConfig) {
} }
function attrEqState(type, stream, state) { function attrEqState(type, stream, state) {
if (type == "equals") return attrValueState; if (type == "equals") return attrValueState;
if (!Kludges.allowMissing) setStyle = "error"; if (!config.allowMissing) setStyle = "error";
return attrState(type, stream, state); return attrState(type, stream, state);
} }
function attrValueState(type, stream, state) { function attrValueState(type, stream, state) {
if (type == "string") return attrContinuedState; if (type == "string") return attrContinuedState;
if (type == "word" && Kludges.allowUnquoted) {setStyle = "string"; return attrState;} if (type == "word" && config.allowUnquoted) {setStyle = "string"; return attrState;}
setStyle = "error"; setStyle = "error";
return attrState(type, stream, state); return attrState(type, stream, state);
} }
@ -297,12 +299,14 @@ CodeMirror.defineMode("xml", function(config, parserConfig) {
} }
return { return {
startState: function() { startState: function(baseIndent) {
return {tokenize: inText, var state = {tokenize: inText,
state: baseState, state: baseState,
indented: 0, indented: baseIndent || 0,
tagName: null, tagStart: null, tagName: null, tagStart: null,
context: null}; context: null}
if (baseIndent != null) state.baseIndent = baseIndent
return state
}, },
token: function(stream, state) { token: function(stream, state) {
@ -335,19 +339,19 @@ CodeMirror.defineMode("xml", function(config, parserConfig) {
return fullLine ? fullLine.match(/^(\s*)/)[0].length : 0; return fullLine ? fullLine.match(/^(\s*)/)[0].length : 0;
// Indent the starts of attribute names. // Indent the starts of attribute names.
if (state.tagName) { if (state.tagName) {
if (multilineTagIndentPastTag) if (config.multilineTagIndentPastTag !== false)
return state.tagStart + state.tagName.length + 2; return state.tagStart + state.tagName.length + 2;
else else
return state.tagStart + indentUnit * multilineTagIndentFactor; return state.tagStart + indentUnit * (config.multilineTagIndentFactor || 1);
} }
if (alignCDATA && /<!\[CDATA\[/.test(textAfter)) return 0; if (config.alignCDATA && /<!\[CDATA\[/.test(textAfter)) return 0;
var tagAfter = textAfter && /^<(\/)?([\w_:\.-]*)/.exec(textAfter); var tagAfter = textAfter && /^<(\/)?([\w_:\.-]*)/.exec(textAfter);
if (tagAfter && tagAfter[1]) { // Closing tag spotted if (tagAfter && tagAfter[1]) { // Closing tag spotted
while (context) { while (context) {
if (context.tagName == tagAfter[2]) { if (context.tagName == tagAfter[2]) {
context = context.prev; context = context.prev;
break; break;
} else if (Kludges.implicitlyClosed.hasOwnProperty(context.tagName)) { } else if (config.implicitlyClosed.hasOwnProperty(context.tagName)) {
context = context.prev; context = context.prev;
} else { } else {
break; break;
@ -355,25 +359,30 @@ CodeMirror.defineMode("xml", function(config, parserConfig) {
} }
} else if (tagAfter) { // Opening tag spotted } else if (tagAfter) { // Opening tag spotted
while (context) { while (context) {
var grabbers = Kludges.contextGrabbers[context.tagName]; var grabbers = config.contextGrabbers[context.tagName];
if (grabbers && grabbers.hasOwnProperty(tagAfter[2])) if (grabbers && grabbers.hasOwnProperty(tagAfter[2]))
context = context.prev; context = context.prev;
else else
break; break;
} }
} }
while (context && !context.startOfLine) while (context && context.prev && !context.startOfLine)
context = context.prev; context = context.prev;
if (context) return context.indent + indentUnit; if (context) return context.indent + indentUnit;
else return 0; else return state.baseIndent || 0;
}, },
electricInput: /<\/[\s\w:]+>$/, electricInput: /<\/[\s\w:]+>$/,
blockCommentStart: "<!--", blockCommentStart: "<!--",
blockCommentEnd: "-->", blockCommentEnd: "-->",
configuration: parserConfig.htmlMode ? "html" : "xml", configuration: config.htmlMode ? "html" : "xml",
helperType: parserConfig.htmlMode ? "html" : "xml" helperType: config.htmlMode ? "html" : "xml",
skipAttribute: function(state) {
if (state.state == attrValueState)
state.state = attrState
}
}; };
}); });

2
devtools/client/sourceeditor/test/codemirror/mode_test.js поставляемый Normal file → Executable file
Просмотреть файл

@ -170,7 +170,7 @@
for (var i = 0; i < output.length; ++i) { for (var i = 0; i < output.length; ++i) {
var style = output[i].style, val = output[i].text; var style = output[i].style, val = output[i].text;
s += s +=
'<td class="mt-token"' + (i == diffAt * 2 ? " style='background: pink'" : "") + '>' + '<td class="mt-token"' + (i == diffAt ? " style='background: pink'" : "") + '>' +
'<span class="cm-' + esc(String(style)) + '">' + '<span class="cm-' + esc(String(style)) + '">' +
esc(val.replace(/ /g,'\xb7')) + // · MIDDLE DOT esc(val.replace(/ /g,'\xb7')) + // · MIDDLE DOT
'</span>' + '</span>' +

0
devtools/client/sourceeditor/test/codemirror/test.js Normal file → Executable file
Просмотреть файл