Index: Source/devtools/front_end/CSSStyleModel.js |
diff --git a/Source/devtools/front_end/CSSStyleModel.js b/Source/devtools/front_end/CSSStyleModel.js |
index 19aa7f21b2434dc0e368746290798031b1fc5cea..c2ba9734ef5fb42c349818b30053d3d1c3adf52e 100644 |
--- a/Source/devtools/front_end/CSSStyleModel.js |
+++ b/Source/devtools/front_end/CSSStyleModel.js |
@@ -557,6 +557,11 @@ WebInspector.CSSStyleModel.prototype = { |
*/ |
setStyleSheetText: function(styleSheetId, newText, majorChange, userCallback) |
{ |
+ var header = this._styleSheetIdToHeader[styleSheetId]; |
+ console.assert(header); |
+ this._pendingCommandsMajorState.push(majorChange); |
+ header.setContent(styleSheetId, newText, callback.bind(this)); |
+ |
/** |
* @param {?Protocol.Error} error |
* @this {WebInspector.CSSStyleModel} |
@@ -570,8 +575,6 @@ WebInspector.CSSStyleModel.prototype = { |
if (!error && userCallback) |
userCallback(error); |
} |
- this._pendingCommandsMajorState.push(majorChange); |
- CSSAgent.setStyleSheetText(styleSheetId, newText, callback.bind(this)); |
}, |
_undoRedoRequested: function() |
@@ -1413,6 +1416,8 @@ WebInspector.CSSStyleSheetHeader = function(payload) |
this._sourceMappings = []; |
} |
+WebInspector.CSSStyleSheetHeader.sourceURLRegex = /\n[\040\t]*\/\*[#@][\040\t]sourceURL=[\040\t]*([^\s]*)[\040\t]*\*\/[\040\t]*$/m; |
apavlov
2013/12/20 10:06:25
Perhaps, \n -> ^ in the multiline mode? (this may
|
+ |
WebInspector.CSSStyleSheetHeader.prototype = { |
/** |
* @return {string} |
@@ -1513,6 +1518,7 @@ WebInspector.CSSStyleSheetHeader.prototype = { |
/** |
* @override |
+ * @return {string} |
*/ |
contentURL: function() |
{ |
@@ -1521,6 +1527,7 @@ WebInspector.CSSStyleSheetHeader.prototype = { |
/** |
* @override |
+ * @return {!WebInspector.ResourceType} |
*/ |
contentType: function() |
{ |
@@ -1529,6 +1536,7 @@ WebInspector.CSSStyleSheetHeader.prototype = { |
/** |
* @override |
+ * @param {function(?string)} callback |
*/ |
requestContent: function(callback) |
{ |
@@ -1544,6 +1552,7 @@ WebInspector.CSSStyleSheetHeader.prototype = { |
text = ""; |
// Fall through. |
} |
+ text = text.replace(WebInspector.CSSStyleSheetHeader.sourceURLRegex, ""); |
callback(text); |
} |
}, |
@@ -1560,7 +1569,20 @@ WebInspector.CSSStyleSheetHeader.prototype = { |
// searchInContent should call back later. |
this.requestContent(performSearch); |
- } |
+ }, |
+ |
+ /** |
+ * @param {!CSSAgent.StyleSheetId} styleSheetId |
+ * @param {string} newText |
+ * @param {function(?Protocol.Error)} callback |
+ */ |
+ setContent: function(styleSheetId, newText, callback) |
+ { |
+ var regex = WebInspector.CSSStyleSheetHeader.sourceURLRegex; |
apavlov
2013/12/20 10:06:25
This can be inlined, since regex is used only once
|
+ if (this.hasSourceURL && !regex.exec(newText)) |
apavlov
2013/12/20 10:06:25
exec->test
|
+ newText += "\n/*# sourceURL=" + this.sourceURL + " */"; |
+ CSSAgent.setStyleSheetText(styleSheetId, newText, callback); |
+ }, |
} |
/** |