Bug 1346662 - do not revert original text after saving; r?gl
When saving an original style sheet, arrange not to reload the text
from the OriginalSourceActor afterward. The actor will serve stale
text, but the editor knows better already.
MozReview-Commit-ID: BcMaSSB1uhA
--- a/devtools/client/styleeditor/StyleSheetEditor.jsm
+++ b/devtools/client/styleeditor/StyleSheetEditor.jsm
@@ -353,16 +353,17 @@ StyleSheetEditor.prototype = {
/**
* Called when the stylesheet text changes.
*/
_onStyleApplied: function () {
if (this._isUpdating) {
// We just applied an edit in the editor, so we can drop this
// notification.
this._isUpdating = false;
+ this.emit("style-applied");
} else if (this.sourceEditor) {
this._getSourceTextAndPrettify().then((newText) => {
this._justSetText = true;
let firstLine = this.sourceEditor.getFirstVisibleLine();
let pos = this.sourceEditor.getCursor();
this.sourceEditor.setText(newText);
this.sourceEditor.setFirstVisibleLine(firstLine);
this.sourceEditor.setCursor(pos);
@@ -737,16 +738,19 @@ StyleSheetEditor.prototype = {
* For original sources (e.g. Sass files). Fetch contents of linked CSS
* file from disk and live update the stylesheet object with the contents.
*/
updateLinkedStyleSheet: function () {
OS.File.read(this.linkedCSSFile).then((array) => {
let decoder = new TextDecoder();
let text = decoder.decode(array);
+ // Ensure we don't re-fetch the text from the original source
+ // actor when we're notified that the style sheet changed.
+ this._isUpdating = true;
let relatedSheet = this.styleSheet.relatedStyleSheet;
relatedSheet.update(text, this.transitionsEnabled);
}, this.markLinkedFileBroken);
},
/**
* Retrieve custom key bindings objects as expected by Editor.
* Editor action names are not displayed to the user.
--- a/devtools/client/styleeditor/test/browser_styleeditor_sourcemap_watching.js
+++ b/devtools/client/styleeditor/test/browser_styleeditor_sourcemap_watching.js
@@ -68,16 +68,19 @@ add_task(function* () {
yield editCSSFile(CSSFile);
info("wrote to CSS file, waiting for style-applied event");
yield styleApplied;
color = yield getComputedStyleProperty({selector: "div", name: "color"});
is(color, "rgb(0, 0, 255)", "div is blue after saving file");
+
+ // Ensure that the editor didn't revert. Bug 1346662.
+ is(editor.sourceEditor.getText(), CSS_TEXT, "edits remain applied");
});
function editSCSS(editor) {
return new Promise(resolve => {
editor.sourceEditor.setText(CSS_TEXT);
editor.saveToFile(null, function (file) {
ok(file, "Scss file should be saved");