Title: [228072] branches/safari-605-branch/Source/WebInspectorUI

Diff

Modified: branches/safari-605-branch/Source/WebInspectorUI/ChangeLog (228071 => 228072)


--- branches/safari-605-branch/Source/WebInspectorUI/ChangeLog	2018-02-05 05:30:39 UTC (rev 228071)
+++ branches/safari-605-branch/Source/WebInspectorUI/ChangeLog	2018-02-05 05:30:42 UTC (rev 228072)
@@ -1,3 +1,41 @@
+2018-02-04  Jason Marcell  <jmarc...@apple.com>
+
+        Cherry-pick r228030. rdar://problem/37220121
+
+    2018-02-02  Devin Rousso  <web...@devinrousso.com>
+
+            Web Inspector: Styles Redesign: Pasting multiple properties should create properties instead of a bad property
+            https://bugs.webkit.org/show_bug.cgi?id=179622
+            <rdar://problem/35511170>
+
+            Reviewed by Matt Baker.
+
+            * UserInterface/Views/SpreadsheetStyleProperty.js:
+            (WI.SpreadsheetStyleProperty.prototype._remove):
+            (WI.SpreadsheetStyleProperty.prototype._update):
+            (WI.SpreadsheetStyleProperty.prototype.spreadsheetTextFieldDidCommit):
+            (WI.SpreadsheetStyleProperty.prototype._handleNamePaste):
+            When the user pastes into the name field, parse the text for a list of name-value pairs and
+            replace the property being edited with the text of those pairs.
+
+            * UserInterface/Views/SpreadsheetCSSStyleDeclarationEditor.js:
+            (WI.SpreadsheetCSSStyleDeclarationEditor):
+            (WI.SpreadsheetCSSStyleDeclarationEditor.prototype.layout):
+            (WI.SpreadsheetCSSStyleDeclarationEditor.prototype.addBlankProperty):
+            (WI.SpreadsheetCSSStyleDeclarationEditor.prototype.spreadsheetStylePropertyFocusMoved):
+            (WI.SpreadsheetCSSStyleDeclarationEditor.prototype.spreadsheetStylePropertyAddBlankPropertySoon):
+            (WI.SpreadsheetCSSStyleDeclarationEditor.prototype.spreadsheetStylePropertyRemoved):
+            (WI.SpreadsheetCSSStyleDeclarationEditor.prototype._propertiesChanged):
+            (WI.SpreadsheetCSSStyleDeclarationEditor.prototype.spreadsheetCSSStyleDeclarationEditorFocusMoved): Deleted.
+            Calling `addBlankProperty` will trigger a layout on the next frame, but that might be before
+            the CSSAgent has had a chance to finish refreshing, so we need a way to defer the creation
+            of a new property until after we have finished the next layout (which is after the refresh).
+            Drive-by: fix naming of some delegate functions.
+
+            * UserInterface/Models/CSSProperty.js:
+            (WI.CSSProperty.prototype.replaceWithText):
+            Provide a way for replacing the property with new text.
+
 2018-01-30  Jason Marcell  <jmarc...@apple.com>
 
         Cherry-pick r227707. rdar://problem/37019463

Modified: branches/safari-605-branch/Source/WebInspectorUI/UserInterface/Models/CSSProperty.js (228071 => 228072)


--- branches/safari-605-branch/Source/WebInspectorUI/UserInterface/Models/CSSProperty.js	2018-02-05 05:30:39 UTC (rev 228071)
+++ branches/safari-605-branch/Source/WebInspectorUI/UserInterface/Models/CSSProperty.js	2018-02-05 05:30:42 UTC (rev 228072)
@@ -131,6 +131,11 @@
         this._updateStyleText(forceRemove);
     }
 
+    replaceWithText(text)
+    {
+        this._updateOwnerStyleText(this._text, text, true);
+    }
+
     commentOut(disabled)
     {
         console.assert(this._enabled === disabled, "CSS property is already " + (disabled ? "disabled" : "enabled"));

Modified: branches/safari-605-branch/Source/WebInspectorUI/UserInterface/Views/SpreadsheetCSSStyleDeclarationEditor.js (228071 => 228072)


--- branches/safari-605-branch/Source/WebInspectorUI/UserInterface/Views/SpreadsheetCSSStyleDeclarationEditor.js	2018-02-05 05:30:39 UTC (rev 228071)
+++ branches/safari-605-branch/Source/WebInspectorUI/UserInterface/Views/SpreadsheetCSSStyleDeclarationEditor.js	2018-02-05 05:30:42 UTC (rev 228072)
@@ -39,6 +39,7 @@
         this._focused = false;
 
         this._propertyPendingStartEditing = null;
+        this._pendingAddBlankPropertyIndexOffset = NaN;
         this._filterText = null;
     }
 
@@ -90,6 +91,9 @@
 
         if (this._filterText)
             this.applyFilter(this._filterText);
+
+        if (!isNaN(this._pendingAddBlankPropertyIndexOffset))
+            this.addBlankProperty(this._propertyViews.length - 1 - this._pendingAddBlankPropertyIndexOffset);
     }
 
     detached()
@@ -204,6 +208,8 @@
 
     addBlankProperty(index)
     {
+        this._pendingAddBlankPropertyIndexOffset = NaN;
+
         if (index === -1) {
             // Append to the end.
             index = this._propertyViews.length;
@@ -213,9 +219,9 @@
         this.needsLayout();
     }
 
-    spreadsheetCSSStyleDeclarationEditorFocusMoved({direction, movedFromProperty, willRemoveProperty})
+    spreadsheetStylePropertyFocusMoved(propertyView, {direction, willRemoveProperty})
     {
-        let movedFromIndex = this._propertyViews.indexOf(movedFromProperty);
+        let movedFromIndex = this._propertyViews.indexOf(propertyView);
         console.assert(movedFromIndex !== -1, "Property doesn't exist, focusing on a selector as a fallback.");
         if (movedFromIndex === -1) {
             if (this._style.selectorEditable)
@@ -254,6 +260,13 @@
 
     // SpreadsheetStyleProperty delegate
 
+    spreadsheetStylePropertyAddBlankPropertySoon(propertyView, {index})
+    {
+        if (isNaN(index))
+            index = this._propertyViews.length;
+        this._pendingAddBlankPropertyIndexOffset = this._propertyViews.length - index;
+    }
+
     spreadsheetStylePropertyRemoved(propertyView)
     {
         this._propertyViews.remove(propertyView);
@@ -260,6 +273,8 @@
 
         for (let index = 0; index < this._propertyViews.length; index++)
             this._propertyViews[index].index = index;
+
+        this._focused = false;
     }
 
     stylePropertyInlineSwatchActivated()
@@ -322,7 +337,7 @@
 
     _propertiesChanged(event)
     {
-        if (this.editing) {
+        if (this.editing && isNaN(this._pendingAddBlankPropertyIndexOffset)) {
             for (let propertyView of this._propertyViews)
                 propertyView.updateStatus();
         } else

Modified: branches/safari-605-branch/Source/WebInspectorUI/UserInterface/Views/SpreadsheetStyleProperty.js (228071 => 228072)


--- branches/safari-605-branch/Source/WebInspectorUI/UserInterface/Views/SpreadsheetStyleProperty.js	2018-02-05 05:30:39 UTC (rev 228071)
+++ branches/safari-605-branch/Source/WebInspectorUI/UserInterface/Views/SpreadsheetStyleProperty.js	2018-02-05 05:30:42 UTC (rev 228072)
@@ -148,10 +148,15 @@
 
     // Private
 
-    _remove()
+    _remove(replacement = "")
     {
         this.element.remove();
-        this._property.remove();
+
+        if (replacement)
+            this._property.replaceWithText(replacement);
+        else
+            this._property.remove();
+
         this.detached();
 
         if (this._delegate && typeof this._delegate.spreadsheetStylePropertyRemoved === "function")
@@ -194,6 +199,7 @@
         if (this._property.editable && this._property.enabled) {
             this._nameElement.tabIndex = 0;
             this._nameElement.addEventListener("beforeinput", this._handleNameBeforeInput.bind(this));
+            this._nameElement.addEventListener("paste", this._handleNamePaste.bind(this));
 
             this._nameTextField = new WI.SpreadsheetTextField(this, this._nameElement, this._nameCompletionDataProvider.bind(this));
 
@@ -262,9 +268,9 @@
             }
         }
 
-        if (typeof this._delegate.spreadsheetCSSStyleDeclarationEditorFocusMoved === "function") {
+        if (typeof this._delegate.spreadsheetStylePropertyFocusMoved === "function") {
             // Move focus away from the current property, to the next or previous one, if exists, or to the next or previous rule, if exists.
-            this._delegate.spreadsheetCSSStyleDeclarationEditorFocusMoved({direction, willRemoveProperty, movedFromProperty: this});
+            this._delegate.spreadsheetStylePropertyFocusMoved(this, {direction, willRemoveProperty});
         }
 
         if (willRemoveProperty)
@@ -559,6 +565,23 @@
         this._valueTextField.startEditing();
     }
 
+    _handleNamePaste(event)
+    {
+        let text = event.clipboardData.getData("text/plain");
+        if (!text || !text.includes(":"))
+            return;
+
+        event.preventDefault();
+
+        this._remove(text);
+
+        if (this._delegate.spreadsheetStylePropertyAddBlankPropertySoon) {
+            this._delegate.spreadsheetStylePropertyAddBlankPropertySoon(this, {
+                index: parseInt(this._element.dataset.propertyIndex) + 1,
+            });
+        }
+    }
+
     _nameCompletionDataProvider(prefix)
     {
         return WI.CSSCompletions.cssNameCompletions.startsWith(prefix);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to