Source/WebInspectorUI/ChangeLog

112017-12-18 Devin Rousso <webkit@devinrousso.com>
22
 3 Web Inspector: Styles Redesign: Pasting multiple properties should create properties instead of a bad property
 4 https://bugs.webkit.org/show_bug.cgi?id=179622
 5 <rdar://problem/35511170>
 6
 7 Reviewed by NOBODY (OOPS!).
 8
 9 * UserInterface/Views/SpreadsheetStyleProperty.js:
 10 (WI.SpreadsheetStyleProperty.prototype._remove):
 11 (WI.SpreadsheetStyleProperty.prototype._update):
 12 (WI.SpreadsheetStyleProperty.prototype.spreadsheetTextFieldDidCommit):
 13 (WI.SpreadsheetStyleProperty.prototype._handleNamePaste):
 14 When the user pastes into the name field, parse the text for a list of name-value pairs and
 15 replace the property being edited with the text of those pairs.
 16
 17 * UserInterface/Views/SpreadsheetCSSStyleDeclarationEditor.js:
 18 (WI.SpreadsheetCSSStyleDeclarationEditor):
 19 (WI.SpreadsheetCSSStyleDeclarationEditor.prototype.layout):
 20 (WI.SpreadsheetCSSStyleDeclarationEditor.prototype.addBlankProperty):
 21 (WI.SpreadsheetCSSStyleDeclarationEditor.prototype.spreadsheetStylePropertyFocusMoved):
 22 (WI.SpreadsheetCSSStyleDeclarationEditor.prototype.spreadsheetStylePropertyAddBlankPropertySoon):
 23 (WI.SpreadsheetCSSStyleDeclarationEditor.prototype.spreadsheetCSSStyleDeclarationEditorFocusMoved): Deleted.
 24 Calling `addBlankProperty` will trigger a layout on the next frame, but that might be before
 25 the CSSAgent has had a chance to finish refreshing, so we need a way to defer the creation
 26 of a new property until after we have finished the next layout (which is after the refresh).
 27 Drive-by: fix naming of some delegate functions.
 28
 29 * UserInterface/Models/CSSProperty.js:
 30 (WI.CSSProperty.prototype.remove):
 31 Provide a way for replacing the property with new text when removing it.
 32
 332017-12-18 Devin Rousso <webkit@devinrousso.com>
 34
335 Web Inspector: Styles Redesign: add inline swatch for CSS variables
436 https://bugs.webkit.org/show_bug.cgi?id=180798
537

Source/WebInspectorUI/UserInterface/Models/CSSProperty.js

@@WI.CSSProperty = class CSSProperty extends WI.Object
118118 this.dispatchEventToListeners(WI.CSSProperty.Event.Changed);
119119 }
120120
121  remove()
 121 remove(replacement = "")
122122 {
123  // Setting name or value to an empty string removes the entire CSSProperty.
124  this._name = "";
125123 const forceRemove = true;
126  this._updateStyleText(forceRemove);
 124 if (replacement)
 125 this._updateOwnerStyleText(this._text, replacement, forceRemove);
 126 else {
 127 // Setting name or value to an empty string removes the entire CSSProperty.
 128 this._name = "";
 129 this._updateStyleText(forceRemove);
 130 }
127131 }
128132
129133 commentOut(disabled)

Source/WebInspectorUI/UserInterface/Views/SpreadsheetCSSStyleDeclarationEditor.js

@@WI.SpreadsheetCSSStyleDeclarationEditor = class SpreadsheetCSSStyleDeclarationEd
3535 this.style = style;
3636 this._propertyViews = [];
3737 this._propertyPendingStartEditing = null;
 38 this._pendingAddBlankPropertyIndex = NaN;
3839 this._filterText = null;
3940 }
4041

@@WI.SpreadsheetCSSStyleDeclarationEditor = class SpreadsheetCSSStyleDeclarationEd
7071
7172 if (this._filterText)
7273 this.applyFilter(this._filterText);
 74
 75 if (!isNaN(this._pendingAddBlankPropertyIndex))
 76 this.addBlankProperty(this._pendingAddBlankPropertyIndex);
7377 }
7478
7579 detached()

@@WI.SpreadsheetCSSStyleDeclarationEditor = class SpreadsheetCSSStyleDeclarationEd
173177
174178 addBlankProperty(index)
175179 {
 180 this._pendingAddBlankPropertyIndex = NaN;
 181
176182 if (index === -1) {
177183 // Append to the end.
178184 index = this._propertyViews.length;

@@WI.SpreadsheetCSSStyleDeclarationEditor = class SpreadsheetCSSStyleDeclarationEd
182188 this.needsLayout();
183189 }
184190
185  spreadsheetCSSStyleDeclarationEditorFocusMoved({direction, movedFromProperty, willRemoveProperty})
 191 spreadsheetStylePropertyFocusMoved(propertyView, {direction, willRemoveProperty})
186192 {
187  let movedFromIndex = this._propertyViews.indexOf(movedFromProperty);
 193 let movedFromIndex = this._propertyViews.indexOf(propertyView);
188194 console.assert(movedFromIndex !== -1, "Property doesn't exist, focusing on a selector as a fallback.");
189195 if (movedFromIndex === -1) {
190196 if (this._style.selectorEditable)

@@WI.SpreadsheetCSSStyleDeclarationEditor = class SpreadsheetCSSStyleDeclarationEd
221227 }
222228 }
223229
 230 spreadsheetStylePropertyAddBlankPropertySoon(propertyView, {index})
 231 {
 232 this._pendingAddBlankPropertyIndex = !isNaN(index) ? index : this._propertyViews.length;
 233 }
 234
224235 spreadsheetStylePropertyRemoved(propertyView)
225236 {
226237 this._propertyViews.remove(propertyView);

Source/WebInspectorUI/UserInterface/Views/SpreadsheetStyleProperty.js

@@WI.SpreadsheetStyleProperty = class SpreadsheetStyleProperty extends WI.Object
143143
144144 // Private
145145
146  _remove()
 146 _remove(replacement = "")
147147 {
148148 this.element.remove();
149  this._property.remove();
 149 this._property.remove(replacement);
150150 this.detached();
151151
152152 if (this._delegate && typeof this._delegate.spreadsheetStylePropertyRemoved === "function")

@@WI.SpreadsheetStyleProperty = class SpreadsheetStyleProperty extends WI.Object
189189 if (this._property.editable && this._property.enabled) {
190190 this._nameElement.tabIndex = 0;
191191 this._nameElement.addEventListener("beforeinput", this._handleNameBeforeInput.bind(this));
 192 this._nameElement.addEventListener("paste", this._handleNamePaste.bind(this));
192193
193194 this._nameTextField = new WI.SpreadsheetTextField(this, this._nameElement, this._nameCompletionDataProvider.bind(this));
194195

@@WI.SpreadsheetStyleProperty = class SpreadsheetStyleProperty extends WI.Object
255256 }
256257 }
257258
258  if (typeof this._delegate.spreadsheetCSSStyleDeclarationEditorFocusMoved === "function") {
 259 if (typeof this._delegate.spreadsheetStylePropertyFocusMoved === "function") {
259260 // Move focus away from the current property, to the next or previous one, if exists, or to the next or previous rule, if exists.
260  this._delegate.spreadsheetCSSStyleDeclarationEditorFocusMoved({direction, willRemoveProperty, movedFromProperty: this});
 261 this._delegate.spreadsheetStylePropertyFocusMoved(this, {direction, willRemoveProperty});
261262 }
262263
263264 if (willRemoveProperty)

@@WI.SpreadsheetStyleProperty = class SpreadsheetStyleProperty extends WI.Object
540541 this._valueTextField.startEditing();
541542 }
542543
 544 _handleNamePaste(event)
 545 {
 546 let text = event.clipboardData.getData("text/plain");
 547 if (!text || !text.includes(":"))
 548 return;
 549
 550 let properties = [];
 551 let inSingleQuotes = false;
 552 let inDoubleQuotes = false;
 553 let savedIndex = 0;
 554 for (let i = 0; i < text.length; ++i) {
 555 if (text[i] === "\"")
 556 inDoubleQuotes = !inDoubleQuotes;
 557 else if (text[i] === "\'")
 558 inSingleQuotes = !inSingleQuotes;
 559 else if (!inSingleQuotes && !inDoubleQuotes) {
 560 if (text[i] === ":") {
 561 properties.push({
 562 name: text.substring(savedIndex, i).trim(),
 563 value: "",
 564 });
 565 savedIndex = i + 1;
 566 } else if (text[i] === ";") {
 567 properties.lastValue.value = text.substring(savedIndex, i).trim();
 568 savedIndex = i + 1;
 569 }
 570 }
 571 }
 572
 573 if (!properties || (properties.length === 1 && !properties[0].value))
 574 return;
 575
 576 event.preventDefault();
 577
 578 let replacement = properties.map(({name, value}) => `${name}: ${value};`).join("\n");
 579 this._remove(replacement);
 580
 581 if (this._delegate.spreadsheetStylePropertyAddBlankPropertySoon) {
 582 this._delegate.spreadsheetStylePropertyAddBlankPropertySoon(this, {
 583 index: parseInt(this._element.dataset.propertyIndex) + properties.length,
 584 });
 585 }
 586 }
 587
543588 _nameCompletionDataProvider(prefix)
544589 {
545590 return WI.CSSCompletions.cssNameCompletions.startsWith(prefix);