Bug 1346662 - do not revert original text after saving; r?gl draft
authorTom Tromey <tom@tromey.com>
Wed, 13 Sep 2017 12:33:32 -0600
changeset 664101 4fe84b1f055400878fbbe9ab97077853cfaec048
parent 664100 c33f931c946c0eb70dcc869202d58902837e6126
child 664233 b384b5c22b45a5d4ed9524e09ea9c7e5f4e4ea5d
push id79626
push userbmo:ttromey@mozilla.com
push dateWed, 13 Sep 2017 18:33:57 +0000
reviewersgl
bugs1346662
milestone57.0a1
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
devtools/client/styleeditor/StyleSheetEditor.jsm
devtools/client/styleeditor/test/browser_styleeditor_sourcemap_watching.js
--- 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");