Title: [289258] branches/safari-613-branch
Revision
289258
Author
[email protected]
Date
2022-02-07 18:52:11 -0800 (Mon, 07 Feb 2022)

Log Message

Cherry-pick r287891. rdar://problem/85345180

    REGRESSION (r283723): Web Inspector: CSS declarations unexpectedly removed when editing property value
    https://bugs.webkit.org/show_bug.cgi?id=233195

    Reviewed by Devin Rousso.

    Source/WebInspectorUI:

    Re-attach CSS property if it was detached while editing.

    CSSProperty is detached when focusing on property name and deleting it. Consequent edits of the detached
    CSSProperty were not saved. This patch re-attaches detached property at the previous position.

    * UserInterface/Models/CSSProperty.js:
    (WI.CSSProperty.prototype.set name):
    * UserInterface/Models/CSSStyleDeclaration.js:
    (WI.CSSStyleDeclaration.prototype.newBlankProperty):
    (WI.CSSStyleDeclaration.prototype.insertProperty):
    Introduce this method since the logic is used in two different places now.

    LayoutTests:

    Test removing CSS property name.

    * inspector/css/modify-css-property-expected.txt:
    * inspector/css/modify-css-property.html:
    * inspector/css/resources/modify-css-property.css:
    (.rule-e):

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@287891 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Modified Paths

Diff

Modified: branches/safari-613-branch/LayoutTests/ChangeLog (289257 => 289258)


--- branches/safari-613-branch/LayoutTests/ChangeLog	2022-02-08 02:52:07 UTC (rev 289257)
+++ branches/safari-613-branch/LayoutTests/ChangeLog	2022-02-08 02:52:11 UTC (rev 289258)
@@ -1,5 +1,54 @@
 2022-02-07  Russell Epstein  <[email protected]>
 
+        Cherry-pick r287891. rdar://problem/85345180
+
+    REGRESSION (r283723): Web Inspector: CSS declarations unexpectedly removed when editing property value
+    https://bugs.webkit.org/show_bug.cgi?id=233195
+    
+    Reviewed by Devin Rousso.
+    
+    Source/WebInspectorUI:
+    
+    Re-attach CSS property if it was detached while editing.
+    
+    CSSProperty is detached when focusing on property name and deleting it. Consequent edits of the detached
+    CSSProperty were not saved. This patch re-attaches detached property at the previous position.
+    
+    * UserInterface/Models/CSSProperty.js:
+    (WI.CSSProperty.prototype.set name):
+    * UserInterface/Models/CSSStyleDeclaration.js:
+    (WI.CSSStyleDeclaration.prototype.newBlankProperty):
+    (WI.CSSStyleDeclaration.prototype.insertProperty):
+    Introduce this method since the logic is used in two different places now.
+    
+    LayoutTests:
+    
+    Test removing CSS property name.
+    
+    * inspector/css/modify-css-property-expected.txt:
+    * inspector/css/modify-css-property.html:
+    * inspector/css/resources/modify-css-property.css:
+    (.rule-e):
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@287891 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2022-01-11  Nikita Vasilyev  <[email protected]>
+
+            REGRESSION (r283723): Web Inspector: CSS declarations unexpectedly removed when editing property value
+            https://bugs.webkit.org/show_bug.cgi?id=233195
+
+            Reviewed by Devin Rousso.
+
+            Test removing CSS property name.
+
+            * inspector/css/modify-css-property-expected.txt:
+            * inspector/css/modify-css-property.html:
+            * inspector/css/resources/modify-css-property.css:
+            (.rule-e):
+
+2022-02-07  Russell Epstein  <[email protected]>
+
         Cherry-pick r287847. rdar://problem/86488039
 
     ASSERTION FAILED in RenderLayer::updateClipRects

Modified: branches/safari-613-branch/LayoutTests/inspector/css/modify-css-property-expected.txt (289257 => 289258)


--- branches/safari-613-branch/LayoutTests/inspector/css/modify-css-property-expected.txt	2022-02-08 02:52:07 UTC (rev 289257)
+++ branches/safari-613-branch/LayoutTests/inspector/css/modify-css-property-expected.txt	2022-02-08 02:52:11 UTC (rev 289258)
@@ -41,3 +41,7 @@
 PASS: Style declaration text should update immediately with commented out property.
 PASS: Uncommented property should be enabled.
 
+-- Running test case: ModifyCSSProperty.ReplacePropertyName
+PASS: Style declaration text should be empty.
+PASS: Style declaration text should have new property name.
+

Modified: branches/safari-613-branch/LayoutTests/inspector/css/modify-css-property.html (289257 => 289258)


--- branches/safari-613-branch/LayoutTests/inspector/css/modify-css-property.html	2022-02-08 02:52:07 UTC (rev 289257)
+++ branches/safari-613-branch/LayoutTests/inspector/css/modify-css-property.html	2022-02-08 02:52:11 UTC (rev 289258)
@@ -316,6 +316,35 @@
         }
     });
 
+    suite.addTestCase({
+        name: "ModifyCSSProperty.ReplacePropertyName",
+        async test() {
+            let getMatchedStyleDeclaration = () => {
+                for (let rule of nodeStyles.matchedRules) {
+                    if (rule.selectorText === ".rule-e")
+                        return rule.style;
+                }
+                throw "No declaration found.";
+            };
+            let getProperty = (propertyName) => {
+                let styleDeclaration = getMatchedStyleDeclaration();
+                for (let property of styleDeclaration.properties) {
+                    if (property.name === propertyName)
+                        return property;
+                }
+                throw "No property found.";
+            };
+            let styleDeclaration = getMatchedStyleDeclaration();
+
+            let cssProperty = getProperty("color");
+            cssProperty.name = "";
+            InspectorTest.expectEqual(styleDeclaration.text, "", "Style declaration text should be empty.");
+
+            cssProperty.name = "border-color";
+            InspectorTest.expectEqual(styleDeclaration.text, `\n    border-color: darkseagreen;\n`, "Style declaration text should have new property name.");
+        }
+    });
+
     WI.domManager.requestDocument((documentNode) => {
         documentNode.querySelector("#x", (contentNodeId) => {
             if (contentNodeId) {
@@ -339,6 +368,6 @@
 </head>
 <body _onload_="runTest()">
     <p>Testing that CSSStyleDeclaration update immediately after modifying its properties when it is not locked.</p>
-    <div id="x" class="test-node rule-a rule-b rule-c rule-d" style="width: 100px"></div>
+    <div id="x" class="test-node rule-a rule-b rule-c rule-d rule-e" style="width: 100px"></div>
 </body>
 </html>

Modified: branches/safari-613-branch/LayoutTests/inspector/css/resources/modify-css-property.css (289257 => 289258)


--- branches/safari-613-branch/LayoutTests/inspector/css/resources/modify-css-property.css	2022-02-08 02:52:07 UTC (rev 289257)
+++ branches/safari-613-branch/LayoutTests/inspector/css/resources/modify-css-property.css	2022-02-08 02:52:11 UTC (rev 289258)
@@ -13,3 +13,6 @@
     /* padding-right: 0px; */
 }
 .rule-d {/*font-size: 13px;*//*border: 2px solid brown*/}
+.rule-e {
+    color: darkseagreen;
+}

Modified: branches/safari-613-branch/Source/WebInspectorUI/ChangeLog (289257 => 289258)


--- branches/safari-613-branch/Source/WebInspectorUI/ChangeLog	2022-02-08 02:52:07 UTC (rev 289257)
+++ branches/safari-613-branch/Source/WebInspectorUI/ChangeLog	2022-02-08 02:52:11 UTC (rev 289258)
@@ -1,3 +1,57 @@
+2022-02-07  Russell Epstein  <[email protected]>
+
+        Cherry-pick r287891. rdar://problem/85345180
+
+    REGRESSION (r283723): Web Inspector: CSS declarations unexpectedly removed when editing property value
+    https://bugs.webkit.org/show_bug.cgi?id=233195
+    
+    Reviewed by Devin Rousso.
+    
+    Source/WebInspectorUI:
+    
+    Re-attach CSS property if it was detached while editing.
+    
+    CSSProperty is detached when focusing on property name and deleting it. Consequent edits of the detached
+    CSSProperty were not saved. This patch re-attaches detached property at the previous position.
+    
+    * UserInterface/Models/CSSProperty.js:
+    (WI.CSSProperty.prototype.set name):
+    * UserInterface/Models/CSSStyleDeclaration.js:
+    (WI.CSSStyleDeclaration.prototype.newBlankProperty):
+    (WI.CSSStyleDeclaration.prototype.insertProperty):
+    Introduce this method since the logic is used in two different places now.
+    
+    LayoutTests:
+    
+    Test removing CSS property name.
+    
+    * inspector/css/modify-css-property-expected.txt:
+    * inspector/css/modify-css-property.html:
+    * inspector/css/resources/modify-css-property.css:
+    (.rule-e):
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@287891 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2022-01-11  Nikita Vasilyev  <[email protected]>
+
+            REGRESSION (r283723): Web Inspector: CSS declarations unexpectedly removed when editing property value
+            https://bugs.webkit.org/show_bug.cgi?id=233195
+
+            Reviewed by Devin Rousso.
+
+            Re-attach CSS property if it was detached while editing.
+
+            CSSProperty is detached when focusing on property name and deleting it. Consequent edits of the detached
+            CSSProperty were not saved. This patch re-attaches detached property at the previous position.
+
+            * UserInterface/Models/CSSProperty.js:
+            (WI.CSSProperty.prototype.set name):
+            * UserInterface/Models/CSSStyleDeclaration.js:
+            (WI.CSSStyleDeclaration.prototype.newBlankProperty):
+            (WI.CSSStyleDeclaration.prototype.insertProperty):
+            Introduce this method since the logic is used in two different places now.
+
 2022-01-24  Alan Coon  <[email protected]>
 
         Cherry-pick r288385. rdar://problem/87851989

Modified: branches/safari-613-branch/Source/WebInspectorUI/UserInterface/Models/CSSProperty.js (289257 => 289258)


--- branches/safari-613-branch/Source/WebInspectorUI/UserInterface/Models/CSSProperty.js	2022-02-08 02:52:07 UTC (rev 289257)
+++ branches/safari-613-branch/Source/WebInspectorUI/UserInterface/Models/CSSProperty.js	2022-02-08 02:52:11 UTC (rev 289258)
@@ -256,6 +256,17 @@
         if (name === this._name)
             return;
 
+        if (!name) {
+            // Deleting property name causes CSSProperty to be detached from CSSStyleDeclaration.
+            console.assert(!isNaN(this._index), this);
+            this._indexBeforeDetached = this._index;
+        } else if (!isNaN(this._indexBeforeDetached) && isNaN(this._index)) {
+            // Reattach CSSProperty.
+            console.assert(!this._ownerStyle.properties.includes(this), this);
+            this._ownerStyle.insertProperty(this, this._indexBeforeDetached);
+            this._indexBeforeDetached = NaN;
+        }
+
         this._markModified();
         this._name = name;
         this._updateStyleText();

Modified: branches/safari-613-branch/Source/WebInspectorUI/UserInterface/Models/CSSStyleDeclaration.js (289257 => 289258)


--- branches/safari-613-branch/Source/WebInspectorUI/UserInterface/Models/CSSStyleDeclaration.js	2022-02-08 02:52:07 UTC (rev 289257)
+++ branches/safari-613-branch/Source/WebInspectorUI/UserInterface/Models/CSSStyleDeclaration.js	2022-02-08 02:52:11 UTC (rev 289258)
@@ -390,11 +390,7 @@
 
         this.markModified();
         let property = new WI.CSSProperty(propertyIndex, text, name, value, priority, enabled, overridden, implicit, anonymous, valid, styleSheetTextRange);
-
-        this._properties.insertAtIndex(property, propertyIndex);
-        for (let index = propertyIndex + 1; index < this._properties.length; index++)
-            this._properties[index].index = index;
-
+        this.insertProperty(property, propertyIndex);
         this.update(this._text, this._properties, this._styleSheetTextRange, {dontFireEvents: true, forceUpdate: true});
 
         return property;
@@ -422,6 +418,17 @@
         WI.cssManager.addModifiedStyle(this);
     }
 
+    insertProperty(cssProperty, propertyIndex)
+    {
+        this._properties.insertAtIndex(cssProperty, propertyIndex);
+        for (let index = propertyIndex + 1; index < this._properties.length; index++)
+            this._properties[index].index = index;
+
+        // Invalidate cached properties.
+        this._enabledProperties = null;
+        this._visibleProperties = null;
+    }
+
     removeProperty(cssProperty)
     {
         // cssProperty.index could be set to NaN by WI.CSSStyleDeclaration.prototype.update.
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to