Title: [247760] trunk/Source/WebInspectorUI
Revision
247760
Author
[email protected]
Date
2019-07-23 17:20:39 -0700 (Tue, 23 Jul 2019)

Log Message

Web Inspector: Styles: Command-X should cut selected properties
https://bugs.webkit.org/show_bug.cgi?id=199341

Reviewed by Devin Rousso.

Implement cutting of selected CSS properties in the style editor.
Unify cutting and copying logic wherever possible.

* UserInterface/Views/SpreadsheetCSSStyleDeclarationEditor.js:
(WI.SpreadsheetCSSStyleDeclarationEditor.prototype.initialLayout):
(WI.SpreadsheetCSSStyleDeclarationEditor.prototype.placeTextCaretInFocusedProperty): Added.
Cut/copy events could only fire on SpreadsheetCSSStyleDeclarationEditor element if it
has selection inside of it. Placing text caret at the beginning of the focused property
ensures that.

(WI.SpreadsheetCSSStyleDeclarationEditor.prototype.spreadsheetStylePropertyCopy): Deleted.
(WI.SpreadsheetCSSStyleDeclarationEditor.prototype._handleKeyDown):
(WI.SpreadsheetCSSStyleDeclarationEditor.prototype._copySelectedProperties): Added.
(WI.SpreadsheetCSSStyleDeclarationEditor.prototype._removeSelectedProperties): Added.
* UserInterface/Views/SpreadsheetCSSStyleDeclarationSection.js:
(WI.SpreadsheetCSSStyleDeclarationSection.prototype._stopSelection):
* UserInterface/Views/SpreadsheetStyleProperty.js:
Remove old copying logic.

Modified Paths

Diff

Modified: trunk/Source/WebInspectorUI/ChangeLog (247759 => 247760)


--- trunk/Source/WebInspectorUI/ChangeLog	2019-07-24 00:08:06 UTC (rev 247759)
+++ trunk/Source/WebInspectorUI/ChangeLog	2019-07-24 00:20:39 UTC (rev 247760)
@@ -1,5 +1,31 @@
 2019-07-23  Nikita Vasilyev  <[email protected]>
 
+        Web Inspector: Styles: Command-X should cut selected properties
+        https://bugs.webkit.org/show_bug.cgi?id=199341
+
+        Reviewed by Devin Rousso.
+
+        Implement cutting of selected CSS properties in the style editor.
+        Unify cutting and copying logic wherever possible.
+
+        * UserInterface/Views/SpreadsheetCSSStyleDeclarationEditor.js:
+        (WI.SpreadsheetCSSStyleDeclarationEditor.prototype.initialLayout):
+        (WI.SpreadsheetCSSStyleDeclarationEditor.prototype.placeTextCaretInFocusedProperty): Added.
+        Cut/copy events could only fire on SpreadsheetCSSStyleDeclarationEditor element if it
+        has selection inside of it. Placing text caret at the beginning of the focused property
+        ensures that.
+
+        (WI.SpreadsheetCSSStyleDeclarationEditor.prototype.spreadsheetStylePropertyCopy): Deleted.
+        (WI.SpreadsheetCSSStyleDeclarationEditor.prototype._handleKeyDown):
+        (WI.SpreadsheetCSSStyleDeclarationEditor.prototype._copySelectedProperties): Added.
+        (WI.SpreadsheetCSSStyleDeclarationEditor.prototype._removeSelectedProperties): Added.
+        * UserInterface/Views/SpreadsheetCSSStyleDeclarationSection.js:
+        (WI.SpreadsheetCSSStyleDeclarationSection.prototype._stopSelection):
+        * UserInterface/Views/SpreadsheetStyleProperty.js:
+        Remove old copying logic.
+
+2019-07-23  Nikita Vasilyev  <[email protected]>
+
         Web Inspector: Display "Resource has no content" for about:blank iframes instead of an error
         https://bugs.webkit.org/show_bug.cgi?id=198029
 

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/SpreadsheetCSSStyleDeclarationEditor.js (247759 => 247760)


--- trunk/Source/WebInspectorUI/UserInterface/Views/SpreadsheetCSSStyleDeclarationEditor.js	2019-07-24 00:08:06 UTC (rev 247759)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/SpreadsheetCSSStyleDeclarationEditor.js	2019-07-24 00:20:39 UTC (rev 247760)
@@ -69,6 +69,8 @@
         }, true);
 
         this.element.addEventListener("keydown", this._handleKeyDown.bind(this));
+        this.element.addEventListener("cut", this._handleCut.bind(this));
+        this.element.addEventListener("copy", this._handleCopy.bind(this));
     }
 
     layout()
@@ -368,6 +370,17 @@
         this._focusIndex = NaN;
     }
 
+    placeTextCaretInFocusedProperty()
+    {
+        if (isNaN(this._focusIndex))
+            return;
+
+        let focusedProperty = this._propertyViews[this._focusIndex];
+        let selection = window.getSelection();
+        selection.removeAllRanges();
+        selection.setBaseAndExtent(focusedProperty.element, 0, focusedProperty.element, 0);
+    }
+
     applyFilter(filterText)
     {
         this._filterText = filterText;
@@ -471,22 +484,6 @@
         this._pendingAddBlankPropertyIndexOffset = this._propertyViews.length - index;
     }
 
-    spreadsheetStylePropertyCopy(event)
-    {
-        if (!this.hasSelectedProperties())
-            return;
-
-        let formattedProperties = [];
-        let [startIndex, endIndex] = this.selectionRange;
-        for (let i = startIndex; i <= endIndex; ++i) {
-            let propertyView = this._propertyViews[i];
-            formattedProperties.push(propertyView.property.formattedText);
-        }
-
-        event.clipboardData.setData("text/plain", formattedProperties.join("\n"));
-        event.stop();
-    }
-
     spreadsheetStylePropertyWillRemove(propertyView)
     {
         this._propertyViews.remove(propertyView);
@@ -550,27 +547,13 @@
                 property.startEditingName();
             }
         } else if (event.key === "Backspace" || event.key === "Delete") {
-            if (!this.style.editable)
+            if (!this.style.editable) {
+                InspectorFrontendHost.beep();
                 return;
+            }
 
-            let [startIndex, endIndex] = this.selectionRange;
-
-            let propertyIndexToSelect = NaN;
-            if (endIndex + 1 !== this._propertyViews.length)
-                propertyIndexToSelect = startIndex;
-            else if (startIndex > 0)
-                propertyIndexToSelect = startIndex - 1;
-
-            this.deselectProperties();
-
-            for (let i = endIndex; i >= startIndex; i--)
-                this._propertyViews[i].remove();
-
-            if (!isNaN(propertyIndexToSelect))
-                this.selectProperties(propertyIndexToSelect, propertyIndexToSelect);
-
+            this._removeSelectedProperties();
             event.stop();
-
         } else if ((event.code === "Space" && !event.shiftKey && !event.metaKey && !event.ctrlKey) || (event.key === "/" && event.commandOrControlKey && !event.shiftKey)) {
             if (!this.style.editable)
                 return;
@@ -597,6 +580,56 @@
             this.deselectProperties();
     }
 
+    _handleCopy(event)
+    {
+        if (!this.hasSelectedProperties())
+            return;
+
+        this._copySelectedProperties(event);
+    }
+
+    _handleCut(event)
+    {
+        if (!this.style.editable) {
+            InspectorFrontendHost.beep();
+            return;
+        }
+
+        if (!this.hasSelectedProperties())
+            return;
+
+        this._copySelectedProperties(event);
+        this._removeSelectedProperties();
+    }
+
+    _copySelectedProperties(event)
+    {
+        let [startIndex, endIndex] = this.selectionRange;
+        let formattedProperties = this._propertyViews.slice(startIndex, endIndex + 1).map((propertyView) => propertyView.property.formattedText);
+        event.clipboardData.setData("text/plain", formattedProperties.join("\n"));
+        event.stop();
+    }
+
+    _removeSelectedProperties()
+    {
+        console.assert(this.style.editable);
+        let [startIndex, endIndex] = this.selectionRange;
+
+        let propertyIndexToSelect = NaN;
+        if (endIndex + 1 !== this._propertyViews.length)
+            propertyIndexToSelect = startIndex;
+        else if (startIndex > 0)
+            propertyIndexToSelect = startIndex - 1;
+
+        this.deselectProperties();
+
+        for (let i = endIndex; i >= startIndex; i--)
+            this._propertyViews[i].remove();
+
+        if (!isNaN(propertyIndexToSelect))
+            this.selectProperties(propertyIndexToSelect, propertyIndexToSelect);
+    }
+
     _editablePropertyAfter(propertyIndex)
     {
         for (let index = propertyIndex + 1; index < this._propertyViews.length; index++) {

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/SpreadsheetCSSStyleDeclarationSection.js (247759 => 247760)


--- trunk/Source/WebInspectorUI/UserInterface/Views/SpreadsheetCSSStyleDeclarationSection.js	2019-07-24 00:08:06 UTC (rev 247759)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/SpreadsheetCSSStyleDeclarationSection.js	2019-07-24 00:20:39 UTC (rev 247760)
@@ -490,6 +490,10 @@
         this._mouseDownIndex = NaN;
         this._element.classList.remove("selecting");
 
+        // "copy" and "cut" events won't fire on SpreadsheetCSSStyleDeclarationEditor unless it has text selected.
+        // Placing a text caret inside of a property has no visible effects but it allows the events to fire.
+        this._propertiesEditor.placeTextCaretInFocusedProperty();
+
         window.removeEventListener("mousemove", this._boundHandleWindowMouseMove);
         this._mouseDownPoint = null;
     }

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/SpreadsheetStyleProperty.js (247759 => 247760)


--- trunk/Source/WebInspectorUI/UserInterface/Views/SpreadsheetStyleProperty.js	2019-07-24 00:08:06 UTC (rev 247759)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/SpreadsheetStyleProperty.js	2019-07-24 00:20:39 UTC (rev 247760)
@@ -73,8 +73,6 @@
                 this._toggle();
                 this._select();
             }, this._element);
-
-            this._element.copyHandler = this;
         }
     }
 
@@ -336,11 +334,6 @@
         return matches;
     }
 
-    handleCopyEvent(event)
-    {
-        this._delegate.spreadsheetStylePropertyCopy(event, this);
-    }
-
     // SpreadsheetTextField delegate
 
     spreadsheetTextFieldWillStartEditing(textField)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to