Bug 1213412 - don't override property while editing. r=bgrins, a=ritu
authorTom Tromey <tromey@mozilla.com>
Tue, 27 Oct 2015 12:22:00 +0100
changeset 305382 3c27305c3ee658eba76412960ab9970f362e83e1
parent 305381 ef5a44ab4ef0344d35f2e465566d37e4906af6ff
child 305383 b42fa55211af72e4afe5e9e0511eebe1ec6da9ab
push id1001
push userraliiev@mozilla.com
push dateMon, 18 Jan 2016 19:06:03 +0000
treeherdermozilla-release@8b89261f3ac4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbgrins, ritu
bugs1213412
milestone44.0a2
Bug 1213412 - don't override property while editing. r=bgrins, a=ritu
devtools/client/shared/widgets/Tooltip.js
devtools/client/styleinspector/rule-view.js
devtools/client/styleinspector/test/browser_ruleview_add-property_01.js
--- a/devtools/client/shared/widgets/Tooltip.js
+++ b/devtools/client/shared/widgets/Tooltip.js
@@ -1084,19 +1084,21 @@ SwatchBasedEditorTooltip.prototype = {
     }
   },
 
   /**
    * This parent class only calls this on <esc> keypress
    */
   revert: function() {
     if (this.activeSwatch) {
+      this._reverted = true;
       let swatch = this.swatches.get(this.activeSwatch);
-      swatch.callbacks.onRevert();
-      this._reverted = true;
+      this.tooltip.once("hiding", () => {
+        swatch.callbacks.onRevert();
+      });
     }
   },
 
   /**
    * This parent class only calls this on <enter> keypress
    */
   commit: function() {
     if (this.activeSwatch) {
--- a/devtools/client/styleinspector/rule-view.js
+++ b/devtools/client/styleinspector/rule-view.js
@@ -3413,18 +3413,19 @@ TextPropertyEditor.prototype = {
       this.enable.removeAttribute("checked");
     }
 
     this.warning.hidden = this.editing || this.isValid();
     this.filterProperty.hidden = this.editing ||
                                  !this.isValid() ||
                                  !this.prop.overridden;
 
-    if (this.prop.overridden || !this.prop.enabled ||
-        !this.prop.isKnownProperty()) {
+    if (!this.editing &&
+        (this.prop.overridden || !this.prop.enabled ||
+         !this.prop.isKnownProperty())) {
       this.element.classList.add("ruleview-overridden");
     } else {
       this.element.classList.remove("ruleview-overridden");
     }
 
     let name = this.prop.name;
     this.nameSpan.textContent = name;
 
@@ -3799,17 +3800,17 @@ TextPropertyEditor.prototype = {
     this._previewValue(this.valueSpan.textContent);
   },
 
   /**
    * Called when the swatch editor closes from an ESC. Revert to the original
    * value of this property before editing.
    */
   _onSwatchRevert: function() {
-    this._previewValue(this.prop.value);
+    this._previewValue(this.prop.value, true);
     this.update();
   },
 
   /**
    * Parse a value string and break it into pieces, starting with the
    * first value, and into an array of additional properties (if any).
    *
    * Example: Calling with "red; width: 100px" would return
@@ -3855,21 +3856,23 @@ TextPropertyEditor.prototype = {
     };
   },
 
   /**
    * Live preview this property, without committing changes.
    *
    * @param {String} value
    *        The value to set the current property to.
+   * @param {Boolean} reverting
+   *        True if we're reverting the previously previewed value
    */
-  _previewValue: function(value) {
+  _previewValue: function(value, reverting = false) {
     // Since function call is throttled, we need to make sure we are still
     // editing, and any selector modifications have been completed
-    if (!this.editing || this.ruleEditor.isEditing) {
+    if (!reverting && (!this.editing || this.ruleEditor.isEditing)) {
       return;
     }
 
     let val = parseSingleValue(value);
     this.ruleEditor.rule.previewPropertyValue(this.prop, val.value,
                                               val.priority);
   },
 
--- a/devtools/client/styleinspector/test/browser_ruleview_add-property_01.js
+++ b/devtools/client/styleinspector/test/browser_ruleview_add-property_01.js
@@ -55,16 +55,19 @@ function* testCreateNew(view) {
 
   is(elementRuleEditor.rule.textProps.length, 1,
     "Created a new text property.");
   is(elementRuleEditor.propertyList.children.length, 1,
     "Created a property editor.");
   is(editor, inplaceEditor(textProp.editor.valueSpan),
     "Editing the value span now.");
 
+  ok(!textProp.editor.element.classList.contains("ruleview-overridden"),
+    "property should not be overridden.");
+
   info("Entering a value and bluring the field to expect a rule change");
   editor.input.value = "#XYZ";
   let onBlur = once(editor.input, "blur");
   onModifications = elementRuleEditor.rule._applyingModifications;
   editor.input.blur();
   yield onBlur;
   yield onModifications;