Diff
Modified: trunk/Source/WebInspectorUI/ChangeLog (168169 => 168170)
--- trunk/Source/WebInspectorUI/ChangeLog 2014-05-02 13:52:01 UTC (rev 168169)
+++ trunk/Source/WebInspectorUI/ChangeLog 2014-05-02 16:04:09 UTC (rev 168170)
@@ -1,3 +1,27 @@
+2014-05-02 Jono Wells <jonowe...@apple.com>
+
+ Web Inspector: CodeMirror 4 CSS mode new state data structure breaks helpers.
+ https://bugs.webkit.org/show_bug.cgi?id=132149
+
+ Reviewed by Joseph Pecoraro.
+
+ The update to CodeMirror 4 included dramatic changes to the CSS mode,
+ particularly the way it handles tokens. `state.stack` is gone, replaced
+ by `state.context`.
+
+ * Tools/PrettyPrinting/CodeMirrorFormatters.js:
+ * Tools/PrettyPrinting/codemirror.js:
+ * UserInterface/External/CodeMirror/codemirror.js:
+ * UserInterface/External/CodeMirror/livescript.js:
+ * UserInterface/External/CodeMirror/runmode.js:
+ Updates from ToT CodeMirror.
+
+ * UserInterface/Controllers/CodeMirrorCompletionController.js:
+ (WebInspector.CodeMirrorCompletionController.prototype._generateCSSCompletions):
+ * UserInterface/Views/CodeMirrorAdditions.js:
+ * UserInterface/Views/CodeMirrorFormatters.js: `lastToken` is null now for ":" characters.
+ Changes to match structural changes to the state object and changes to expected values of `lastToken`.
+
2014-04-30 Brian J. Burg <b...@cs.washington.edu>
Web Inspector: clean up and decompose InspectorBackend functionality
Modified: trunk/Source/WebInspectorUI/Tools/PrettyPrinting/CodeMirrorFormatters.js (168169 => 168170)
--- trunk/Source/WebInspectorUI/Tools/PrettyPrinting/CodeMirrorFormatters.js 2014-05-02 13:52:01 UTC (rev 168169)
+++ trunk/Source/WebInspectorUI/Tools/PrettyPrinting/CodeMirrorFormatters.js 2014-05-02 16:04:09 UTC (rev 168170)
@@ -316,12 +316,8 @@
if (!lastToken) {
if (lastContent === ",")
return true;
- return false;
- }
-
- if (/\boperator\b/.test(lastToken)) {
if (lastContent === ":") // Space in "prop: value" but not in a selectors "a:link" or "div::after" or media queries "(max-device-width:480px)".
- return state.stack.lastValue === "propertyValue";
+ return state.state === "prop";
return false;
}
@@ -337,7 +333,7 @@
if (content === ";")
return 1;
if (content === ",") { // "a,b,c,...,z{}" rule list at top level or in @media top level and only if the line length will be large.
- if ((!state.stack || !state.stack.length || state.stack.lastValue === "@media{") && state._cssPrettyPrint.lineLength > 60) {
+ if ((state.state === "top" || state.state === "media") && state._cssPrettyPrint.lineLength > 60) {
state._cssPrettyPrint.lineLength = 0;
return 1;
}
@@ -395,7 +391,7 @@
// In order insert newlines in selector lists we need keep track of the length of the current line.
// This isn't exact line length, only the builder knows that, but it is good enough to get an idea.
// If we are at a top level, keep track of the current line length, otherwise we reset to 0.
- if (!state.stack || !state.stack.length || state.stack.lastValue === "@media{")
+ if (state.state === "top" || state.state === "media")
state._cssPrettyPrint.lineLength += content.length;
else
state._cssPrettyPrint.lineLength = 0;
Modified: trunk/Source/WebInspectorUI/Tools/PrettyPrinting/codemirror.js (168169 => 168170)
--- trunk/Source/WebInspectorUI/Tools/PrettyPrinting/codemirror.js 2014-05-02 13:52:01 UTC (rev 168169)
+++ trunk/Source/WebInspectorUI/Tools/PrettyPrinting/codemirror.js 2014-05-02 16:04:09 UTC (rev 168170)
@@ -230,6 +230,10 @@
// True when shift is held down.
d.shift = false;
+
+ // Used to track whether anything happened since the context menu
+ // was opened.
+ d.selForContextMenu = null;
}
// STATE UPDATES
@@ -1621,7 +1625,7 @@
else
rect = nullRect;
} else {
- rect = range(node, start, end).getBoundingClientRect();
+ rect = range(node, start, end).getBoundingClientRect() || nullRect;
}
} else { // If it is a widget, simply get the box for the whole widget.
if (start > 0) collapse = bias = "right";
@@ -2246,6 +2250,8 @@
if (withOp) startOperation(cm);
cm.display.shift = false;
+ if (text.charCodeAt(0) == 0x200b && doc.sel == cm.display.selForContextMenu && !prevInput)
+ prevInput = "\u200b";
// Find the part of the input that is actually new
var same = 0, l = Math.min(prevInput.length, text.length);
while (same < l && prevInput.charCodeAt(same) == text.charCodeAt(same)) ++same;
@@ -3110,7 +3116,7 @@
// The prevInput test prevents this from firing when a context
// menu is closed (since the resetInput would kill the
// select-all detection hack)
- if (!cm.curOp && cm.display.selForContextMenu == cm.doc.sel) {
+ if (!cm.curOp && cm.display.selForContextMenu != cm.doc.sel) {
resetInput(cm);
if (webkit) setTimeout(bind(resetInput, cm, true), 0); // Issue #1730
}
@@ -3130,7 +3136,6 @@
// CONTEXT MENU HANDLING
- var detectingSelectAll;
// To make the context menu work, we need to briefly unhide the
// textarea (making it as unobtrusive as possible) to let the
// right-click take effect on it.
@@ -3159,6 +3164,7 @@
// Adds "Select all" to context menu in FF
if (!cm.somethingSelected()) display.input.value = display.prevInput = " ";
display.selForContextMenu = cm.doc.sel;
+ clearTimeout(display.detectingSelectAll);
// Select-all will be greyed out if there's nothing to select, so
// this adds a zero-width space so that we can later check whether
@@ -3180,14 +3186,13 @@
// Try to detect the user choosing select-all
if (display.input.selectionStart != null) {
if (!ie || ie_upto8) prepareSelectAllHack();
- clearTimeout(detectingSelectAll);
var i = 0, poll = function() {
if (display.selForContextMenu == cm.doc.sel && display.input.selectionStart == 0)
operation(cm, commands.selectAll)(cm);
- else if (i++ < 10) detectingSelectAll = setTimeout(poll, 500);
+ else if (i++ < 10) display.detectingSelectAll = setTimeout(poll, 500);
else resetInput(cm);
};
- detectingSelectAll = setTimeout(poll, 200);
+ display.detectingSelectAll = setTimeout(poll, 200);
}
}
@@ -3383,7 +3388,7 @@
var after = i ? computeSelAfterChange(doc, change, null) : lst(source);
makeChangeSingleDoc(doc, change, after, mergeOldSpans(doc, change));
- if (doc.cm) ensureCursorVisible(doc.cm);
+ if (!i && doc.cm) doc.cm.scrollIntoView(change);
var rebased = [];
// Propagate to the linked documents
@@ -3400,12 +3405,17 @@
// Sub-views need their line numbers shifted when text is added
// above or below them in the parent document.
function shiftDoc(doc, distance) {
+ if (distance == 0) return;
doc.first += distance;
doc.sel = new Selection(map(doc.sel.ranges, function(range) {
return new Range(Pos(range.anchor.line + distance, range.anchor.ch),
Pos(range.head.line + distance, range.head.ch));
}), doc.sel.primIndex);
- if (doc.cm) regChange(doc.cm, doc.first, doc.first - distance, distance);
+ if (doc.cm) {
+ regChange(doc.cm, doc.first, doc.first - distance, distance);
+ for (var d = doc.cm.display, l = d.viewFrom; l < d.viewTo; l++)
+ regLineChange(doc.cm, l, "gutter");
+ }
}
// More lower-level change function, handling only a single document
@@ -3497,6 +3507,7 @@
if (changeHandler) signalLater(cm, "change", cm, obj);
if (changesHandler) (cm.curOp.changeObjs || (cm.curOp.changeObjs = [])).push(obj);
}
+ cm.display.selForContextMenu = null;
}
function replaceRange(doc, code, from, to, origin) {
@@ -7520,7 +7531,7 @@
// THE END
- CodeMirror.version = "4.1.0";
+ CodeMirror.version = "4.1.1";
return CodeMirror;
});
Modified: trunk/Source/WebInspectorUI/UserInterface/Controllers/CodeMirrorCompletionController.js (168169 => 168170)
--- trunk/Source/WebInspectorUI/UserInterface/Controllers/CodeMirrorCompletionController.js 2014-05-02 13:52:01 UTC (rev 168169)
+++ trunk/Source/WebInspectorUI/UserInterface/Controllers/CodeMirrorCompletionController.js 2014-05-02 16:04:09 UTC (rev 168170)
@@ -519,7 +519,7 @@
_generateCSSCompletions: function(mainToken, base, suffix)
{
// We only support completion inside CSS block context.
- if (!mainToken.state || !mainToken.state.state || !mainToken.state.state === "block")
+ if (mainToken.state.state === "media" || mainToken.state.state === "top" || mainToken.state.state === "parens")
return [];
var token = mainToken;
Modified: trunk/Source/WebInspectorUI/UserInterface/External/CodeMirror/codemirror.js (168169 => 168170)
--- trunk/Source/WebInspectorUI/UserInterface/External/CodeMirror/codemirror.js 2014-05-02 13:52:01 UTC (rev 168169)
+++ trunk/Source/WebInspectorUI/UserInterface/External/CodeMirror/codemirror.js 2014-05-02 16:04:09 UTC (rev 168170)
@@ -230,6 +230,10 @@
// True when shift is held down.
d.shift = false;
+
+ // Used to track whether anything happened since the context menu
+ // was opened.
+ d.selForContextMenu = null;
}
// STATE UPDATES
@@ -1621,7 +1625,7 @@
else
rect = nullRect;
} else {
- rect = range(node, start, end).getBoundingClientRect();
+ rect = range(node, start, end).getBoundingClientRect() || nullRect;
}
} else { // If it is a widget, simply get the box for the whole widget.
if (start > 0) collapse = bias = "right";
@@ -2246,6 +2250,8 @@
if (withOp) startOperation(cm);
cm.display.shift = false;
+ if (text.charCodeAt(0) == 0x200b && doc.sel == cm.display.selForContextMenu && !prevInput)
+ prevInput = "\u200b";
// Find the part of the input that is actually new
var same = 0, l = Math.min(prevInput.length, text.length);
while (same < l && prevInput.charCodeAt(same) == text.charCodeAt(same)) ++same;
@@ -3110,7 +3116,7 @@
// The prevInput test prevents this from firing when a context
// menu is closed (since the resetInput would kill the
// select-all detection hack)
- if (!cm.curOp && cm.display.selForContextMenu == cm.doc.sel) {
+ if (!cm.curOp && cm.display.selForContextMenu != cm.doc.sel) {
resetInput(cm);
if (webkit) setTimeout(bind(resetInput, cm, true), 0); // Issue #1730
}
@@ -3130,7 +3136,6 @@
// CONTEXT MENU HANDLING
- var detectingSelectAll;
// To make the context menu work, we need to briefly unhide the
// textarea (making it as unobtrusive as possible) to let the
// right-click take effect on it.
@@ -3159,6 +3164,7 @@
// Adds "Select all" to context menu in FF
if (!cm.somethingSelected()) display.input.value = display.prevInput = " ";
display.selForContextMenu = cm.doc.sel;
+ clearTimeout(display.detectingSelectAll);
// Select-all will be greyed out if there's nothing to select, so
// this adds a zero-width space so that we can later check whether
@@ -3180,14 +3186,13 @@
// Try to detect the user choosing select-all
if (display.input.selectionStart != null) {
if (!ie || ie_upto8) prepareSelectAllHack();
- clearTimeout(detectingSelectAll);
var i = 0, poll = function() {
if (display.selForContextMenu == cm.doc.sel && display.input.selectionStart == 0)
operation(cm, commands.selectAll)(cm);
- else if (i++ < 10) detectingSelectAll = setTimeout(poll, 500);
+ else if (i++ < 10) display.detectingSelectAll = setTimeout(poll, 500);
else resetInput(cm);
};
- detectingSelectAll = setTimeout(poll, 200);
+ display.detectingSelectAll = setTimeout(poll, 200);
}
}
@@ -3383,7 +3388,7 @@
var after = i ? computeSelAfterChange(doc, change, null) : lst(source);
makeChangeSingleDoc(doc, change, after, mergeOldSpans(doc, change));
- if (doc.cm) ensureCursorVisible(doc.cm);
+ if (!i && doc.cm) doc.cm.scrollIntoView(change);
var rebased = [];
// Propagate to the linked documents
@@ -3400,12 +3405,17 @@
// Sub-views need their line numbers shifted when text is added
// above or below them in the parent document.
function shiftDoc(doc, distance) {
+ if (distance == 0) return;
doc.first += distance;
doc.sel = new Selection(map(doc.sel.ranges, function(range) {
return new Range(Pos(range.anchor.line + distance, range.anchor.ch),
Pos(range.head.line + distance, range.head.ch));
}), doc.sel.primIndex);
- if (doc.cm) regChange(doc.cm, doc.first, doc.first - distance, distance);
+ if (doc.cm) {
+ regChange(doc.cm, doc.first, doc.first - distance, distance);
+ for (var d = doc.cm.display, l = d.viewFrom; l < d.viewTo; l++)
+ regLineChange(doc.cm, l, "gutter");
+ }
}
// More lower-level change function, handling only a single document
@@ -3497,6 +3507,7 @@
if (changeHandler) signalLater(cm, "change", cm, obj);
if (changesHandler) (cm.curOp.changeObjs || (cm.curOp.changeObjs = [])).push(obj);
}
+ cm.display.selForContextMenu = null;
}
function replaceRange(doc, code, from, to, origin) {
@@ -7520,7 +7531,7 @@
// THE END
- CodeMirror.version = "4.1.0";
+ CodeMirror.version = "4.1.1";
return CodeMirror;
});
Modified: trunk/Source/WebInspectorUI/UserInterface/External/CodeMirror/livescript.js (168169 => 168170)
--- trunk/Source/WebInspectorUI/UserInterface/External/CodeMirror/livescript.js 2014-05-02 13:52:01 UTC (rev 168169)
+++ trunk/Source/WebInspectorUI/UserInterface/External/CodeMirror/livescript.js 2014-05-02 16:04:09 UTC (rev 168170)
@@ -11,18 +11,17 @@
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
-"use strict";
+ "use strict";
-(function() {
CodeMirror.defineMode('livescript', function(){
- var tokenBase, external;
- tokenBase = function(stream, state){
- var next_rule, nr, i$, len$, r, m;
- if (next_rule = state.next || 'start') {
+ var tokenBase = function(stream, state) {
+ var next_rule = state.next || "start";
+ if (next_rule) {
state.next = state.next;
- if (Array.isArray(nr = Rules[next_rule])) {
- for (i$ = 0, len$ = nr.length; i$ < len$; ++i$) {
- r = nr[i$];
+ var nr = Rules[next_rule];
+ if (nr.splice) {
+ for (var i$ = 0; i$ < nr.length; ++i$) {
+ var r = nr[i$], m;
if (r.regex && (m = stream.match(r.regex))) {
state.next = r.next || state.next;
return r.token;
@@ -44,7 +43,7 @@
stream.next();
return 'error';
};
- external = {
+ var external = {
startState: function(){
return {
next: 'start',
@@ -52,8 +51,8 @@
};
},
token: function(stream, state){
- var style;
- style = tokenBase(stream, state);
+ while (stream.pos == stream.start)
+ var style = tokenBase(stream, state);
state.lastToken = {
style: style,
indent: stream.indentation(),
@@ -62,8 +61,7 @@
return style.replace(/\./g, ' ');
},
indent: function(state){
- var indentation;
- indentation = state.lastToken.indent;
+ var indentation = state.lastToken.indent;
if (state.lastToken.content.match(indenter)) {
indentation += 2;
}
@@ -262,7 +260,7 @@
};
for (var idx in Rules) {
var r = Rules[idx];
- if (Array.isArray(r)) {
+ if (r.splice) {
for (var i = 0, len = r.length; i < len; ++i) {
var rr = r[i];
if (typeof rr.regex === 'string') {
@@ -273,8 +271,7 @@
Rules[idx].regex = new RegExp('^' + r.regex);
}
}
-})();
-CodeMirror.defineMIME('text/x-livescript', 'livescript');
+ CodeMirror.defineMIME('text/x-livescript', 'livescript');
});
Modified: trunk/Source/WebInspectorUI/UserInterface/External/CodeMirror/runmode.js (168169 => 168170)
--- trunk/Source/WebInspectorUI/UserInterface/External/CodeMirror/runmode.js 2014-05-02 13:52:01 UTC (rev 168169)
+++ trunk/Source/WebInspectorUI/UserInterface/External/CodeMirror/runmode.js 2014-05-02 16:04:09 UTC (rev 168170)
@@ -57,7 +57,7 @@
for (var i = 0, e = lines.length; i < e; ++i) {
if (i) callback("\n");
var stream = new CodeMirror.StringStream(lines[i]);
- if (!stream.string && mode.blankLine) mode.blankLine();
+ if (!stream.string && mode.blankLine) mode.blankLine(state);
while (!stream.eol()) {
var style = mode.token(stream, state);
callback(stream.current(), style, i, stream.start, state);
Modified: trunk/Source/WebInspectorUI/UserInterface/Views/CodeMirrorAdditions.js (168169 => 168170)
--- trunk/Source/WebInspectorUI/UserInterface/Views/CodeMirrorAdditions.js 2014-05-02 13:52:01 UTC (rev 168169)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/CodeMirrorAdditions.js 2014-05-02 16:04:09 UTC (rev 168170)
@@ -187,10 +187,10 @@
var style = this._token(stream, state);
if (style) {
- if (style === "string-2" && stream.current() === "url") {
+ if (style === "atom" && stream.current() === "url") {
// If the current text is "url" then we should expect the next string token to be a link.
state._expectLink = true;
- } else if (state._expectLink && style === "string") {
+ } else if (state._expectLink && style === "atom") {
// We expected a string and got it. This is a link. Parse it the way we want it.
delete state._expectLink;
Modified: trunk/Source/WebInspectorUI/UserInterface/Views/CodeMirrorFormatters.js (168169 => 168170)
--- trunk/Source/WebInspectorUI/UserInterface/Views/CodeMirrorFormatters.js 2014-05-02 13:52:01 UTC (rev 168169)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/CodeMirrorFormatters.js 2014-05-02 16:04:09 UTC (rev 168170)
@@ -316,12 +316,8 @@
if (!lastToken) {
if (lastContent === ",")
return true;
- return false;
- }
-
- if (/\boperator\b/.test(lastToken)) {
if (lastContent === ":") // Space in "prop: value" but not in a selectors "a:link" or "div::after" or media queries "(max-device-width:480px)".
- return state.stack.lastValue === "propertyValue";
+ return state.state === "prop";
return false;
}
@@ -337,7 +333,7 @@
if (content === ";")
return 1;
if (content === ",") { // "a,b,c,...,z{}" rule list at top level or in @media top level and only if the line length will be large.
- if ((!state.stack || !state.stack.length || state.stack.lastValue === "@media{") && state._cssPrettyPrint.lineLength > 60) {
+ if ((state.state === "top" || state.state === "media") && state._cssPrettyPrint.lineLength > 60) {
state._cssPrettyPrint.lineLength = 0;
return 1;
}
@@ -395,7 +391,7 @@
// In order insert newlines in selector lists we need keep track of the length of the current line.
// This isn't exact line length, only the builder knows that, but it is good enough to get an idea.
// If we are at a top level, keep track of the current line length, otherwise we reset to 0.
- if (!state.stack || !state.stack.length || state.stack.lastValue === "@media{")
+ if (state.state === "top" || state.state === "media")
state._cssPrettyPrint.lineLength += content.length;
else
state._cssPrettyPrint.lineLength = 0;