Changeset 224174 in webkit
- Timestamp:
- Oct 30, 2017 1:43:53 AM (6 years ago)
- Location:
- trunk/Source/WebInspectorUI
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebInspectorUI/ChangeLog
r224142 r224174 1 2017-10-30 Nikita Vasilyev <nvasilyev@apple.com> 2 3 Web Inspector: [PARITY] Styles Redesign: clicking on the white space after the property should create a blank property 4 https://bugs.webkit.org/show_bug.cgi?id=178022 5 <rdar://problem/34861687> 6 7 Reviewed by Matt Baker. 8 9 - Clicking on the whitespace on the right side of a property should insert a blank property after the clicked one. 10 - Clicking on the whitespace at the end of a CSS rule should append a blank property. 11 - Clicking on the whitespace before the first property should insert a blank property before the first one. 12 13 * UserInterface/Models/CSSProperty.js: 14 (WI.CSSProperty.prototype.remove): 15 (WI.CSSProperty.prototype._updateOwnerStyleText): 16 Remove method previously didn't do anything for a newly added property. 17 18 * UserInterface/Models/CSSStyleDeclaration.js: 19 (WI.CSSStyleDeclaration.prototype.newBlankProperty): 20 Update indices of all properties after the newly added property. 21 22 * UserInterface/Views/SpreadsheetCSSStyleDeclarationEditor.js: 23 (WI.SpreadsheetCSSStyleDeclarationEditor): 24 (WI.SpreadsheetCSSStyleDeclarationEditor.prototype.layout): 25 (WI.SpreadsheetCSSStyleDeclarationEditor.prototype.startEditingFirstProperty): 26 (WI.SpreadsheetCSSStyleDeclarationEditor.prototype.startEditingLastProperty): 27 (WI.SpreadsheetCSSStyleDeclarationEditor.prototype.isFocused): 28 (WI.SpreadsheetCSSStyleDeclarationEditor.prototype.addBlankProperty): 29 (WI.SpreadsheetCSSStyleDeclarationEditor.prototype.spreadsheetCSSStyleDeclarationEditorFocusMoved): 30 (WI.SpreadsheetCSSStyleDeclarationEditor.prototype._propertiesChanged): 31 (WI.SpreadsheetCSSStyleDeclarationEditor.prototype._addBlankProperty): Deleted. 32 (WI.SpreadsheetCSSStyleDeclarationEditor.prototype._isFocused): Deleted. 33 Re-layout SpreadsheetCSSStyleDeclarationEditor after adding a new property. Preserve edited property 34 so we can restore editing state after the re-layout. 35 36 * UserInterface/Views/SpreadsheetCSSStyleDeclarationSection.js: 37 (WI.SpreadsheetCSSStyleDeclarationSection): 38 (WI.SpreadsheetCSSStyleDeclarationSection.prototype.initialLayout): 39 (WI.SpreadsheetCSSStyleDeclarationSection.prototype._handleMouseDown): 40 (WI.SpreadsheetCSSStyleDeclarationSection.prototype._handleClick): 41 Clicking should add a new property only when we aren't editing an existing property. 42 43 * UserInterface/Views/SpreadsheetStyleProperty.js: 44 (WI.SpreadsheetStyleProperty): 45 (WI.SpreadsheetStyleProperty.prototype.updateClassNames): 46 (WI.SpreadsheetStyleProperty.prototype.spreadsheetTextFieldDidCommit): 47 Remove newlyAdded property of SpreadsheetStyleProperty. During layout SpreadsheetCSSStyleDeclarationEditor 48 recreates SpreadsheetStyleProperty views and newlyAdded property gets lost. 49 50 * UserInterface/Views/SpreadsheetTextField.js: 51 (WI.SpreadsheetTextField.prototype.get valueBeforeEditing): 52 (WI.SpreadsheetTextField.prototype.startEditing): 53 (WI.SpreadsheetTextField.prototype.stopEditing): 54 (WI.SpreadsheetTextField.prototype._discardChange): 55 1 56 2017-10-27 Devin Rousso <webkit@devinrousso.com> 2 57 -
trunk/Source/WebInspectorUI/UserInterface/Models/CSSProperty.js
r222959 r224174 122 122 { 123 123 // Setting name or value to an empty string removes the entire CSSProperty. 124 this.name = ""; 124 this._name = ""; 125 const forceRemove = true; 126 this._updateStyleText(forceRemove); 125 127 } 126 128 … … 326 328 // Private 327 329 328 _updateStyleText( )330 _updateStyleText(forceRemove = false) 329 331 { 330 332 let text = ""; … … 335 337 let oldText = this._text; 336 338 this._text = text; 337 this._updateOwnerStyleText(oldText, this._text); 338 } 339 340 _updateOwnerStyleText(oldText, newText) 341 { 342 if (oldText === newText) 343 return; 339 this._updateOwnerStyleText(oldText, this._text, forceRemove); 340 } 341 342 _updateOwnerStyleText(oldText, newText, forceRemove = false) 343 { 344 if (oldText === newText) { 345 if (forceRemove) { 346 const lineDelta = 0; 347 const columnDelta = 0; 348 this._ownerStyle.shiftPropertiesAfter(this, lineDelta, columnDelta, forceRemove); 349 } 350 return; 351 } 344 352 345 353 let styleText = this._ownerStyle.text || ""; -
trunk/Source/WebInspectorUI/UserInterface/Models/CSSStyleDeclaration.js
r223970 r224174 358 358 } 359 359 360 newBlankProperty( insertAfterIndex)360 newBlankProperty(propertyIndex) 361 361 { 362 362 let text, name, value, priority, overridden, implicit, anonymous; 363 363 let enabled = true; 364 364 let valid = false; 365 let styleSheetTextRange = this._rangeAfterPropertyAtIndex(insertAfterIndex); 366 367 let propertyIndex = insertAfterIndex + 1; 365 let styleSheetTextRange = this._rangeAfterPropertyAtIndex(propertyIndex - 1); 366 368 367 let property = new WI.CSSProperty(propertyIndex, text, name, value, priority, enabled, overridden, implicit, anonymous, valid, styleSheetTextRange); 369 368 370 369 this._allProperties.insertAtIndex(property, propertyIndex); 370 for (let index = propertyIndex + 1; index < this._allProperties.length; index++) 371 this._allProperties[index].index = index; 372 371 373 const suppressEvents = true; 372 374 this.update(this._text, this._allProperties, this._styleSheetTextRange, suppressEvents); -
trunk/Source/WebInspectorUI/UserInterface/Views/SpreadsheetCSSStyleDeclarationEditor.js
r223970 r224174 35 35 this.style = style; 36 36 this._propertyViews = []; 37 this._propertyPendingStartEditing = null; 37 38 } 38 39 … … 48 49 this.element.classList.toggle("no-properties", !properties.length); 49 50 51 // FIXME: Only re-layout properties that have been modified and preserve focus whenever possible. 50 52 this._propertyViews = []; 53 54 let propertyViewPendingStartEditing = null; 51 55 for (let index = 0; index < properties.length; index++) { 52 56 let property = properties[index]; 53 let propertyView = new WI.SpreadsheetStyleProperty(this, property );57 let propertyView = new WI.SpreadsheetStyleProperty(this, property, index); 54 58 this.element.append(propertyView.element); 55 59 this._propertyViews.push(propertyView); 60 61 if (property === this._propertyPendingStartEditing) 62 propertyViewPendingStartEditing = propertyView; 63 } 64 65 if (propertyViewPendingStartEditing) { 66 propertyViewPendingStartEditing.nameTextField.startEditing(); 67 this._propertyPendingStartEditing = null; 56 68 } 57 69 } … … 90 102 else { 91 103 let index = 0; 92 this. _addBlankProperty(index);104 this.addBlankProperty(index); 93 105 } 94 106 } … … 101 113 else { 102 114 let index = 0; 103 this. _addBlankProperty(index);115 this.addBlankProperty(index); 104 116 } 105 117 } … … 144 156 145 157 return false; 158 } 159 160 isFocused() 161 { 162 let focusedElement = document.activeElement; 163 164 if (!focusedElement || focusedElement.tagName === "BODY") 165 return false; 166 167 return focusedElement.isSelfOrDescendant(this.element); 168 } 169 170 addBlankProperty(index) 171 { 172 if (index === -1) { 173 // Append to the end. 174 index = this._propertyViews.length; 175 } 176 177 this._propertyPendingStartEditing = this._style.newBlankProperty(index); 178 this.needsLayout(); 146 179 } 147 180 … … 168 201 this._delegate.cssStyleDeclarationEditorStartEditingAdjacentRule(reverse); 169 202 } else 170 this. _addBlankProperty(movedFromIndex);203 this.addBlankProperty(index); 171 204 } 172 205 } else { … … 200 233 } 201 234 202 _addBlankProperty(afterIndex)203 {204 let blankProperty = this._style.newBlankProperty(afterIndex);205 const newlyAdded = true;206 let propertyView = new WI.SpreadsheetStyleProperty(this, blankProperty, newlyAdded);207 this.element.append(propertyView.element);208 this._propertyViews.push(propertyView);209 propertyView.nameTextField.startEditing();210 }211 212 _isFocused()213 {214 let focusedElement = document.activeElement;215 216 if (!focusedElement || focusedElement.tagName === "BODY")217 return false;218 219 return focusedElement.isSelfOrDescendant(this.element);220 }221 222 235 _propertiesChanged(event) 223 236 { 224 if (this. _isFocused()) {237 if (this.isFocused()) { 225 238 for (let propertyView of this._propertyViews) 226 239 propertyView.updateClassNames(); -
trunk/Source/WebInspectorUI/UserInterface/Views/SpreadsheetCSSStyleDeclarationSection.js
r224064 r224174 38 38 this._propertiesEditor = null; 39 39 this._selectorElements = []; 40 this._wasFocused = false; 40 41 } 41 42 … … 55 56 super.initialLayout(); 56 57 57 this._headerElement = document.createElement(" span");58 this._headerElement = document.createElement("div"); 58 59 this._headerElement.classList.add("header"); 59 60 … … 66 67 this._headerElement.append(this._selectorElement); 67 68 69 let openBrace = document.createElement("span"); 70 openBrace.classList.add("open-brace"); 71 openBrace.textContent = " {"; 72 this._headerElement.append(openBrace); 73 68 74 if (this._style.selectorEditable) { 69 75 this._selectorTextField = new WI.SpreadsheetSelectorField(this, this._selectorElement); … … 74 80 this._propertiesEditor.element.classList.add("properties"); 75 81 76 let openBrace = document.createElement("span");77 openBrace.classList.add("open-brace");78 openBrace.textContent = " {";79 80 82 let closeBrace = document.createElement("span"); 81 83 closeBrace.classList.add("close-brace"); 82 84 closeBrace.textContent = "}"; 83 85 84 this._element.append(this._createMediaHeader(), this._headerElement , openBrace);86 this._element.append(this._createMediaHeader(), this._headerElement); 85 87 this.addSubview(this._propertiesEditor); 86 88 this._propertiesEditor.needsLayout(); … … 91 93 else if (!this._style.ownerRule) 92 94 this._element.classList.add("selector-locked"); 95 96 if (this._style.editable) { 97 this.element.addEventListener("click", this._handleClick.bind(this)); 98 this.element.addEventListener("mousedown", this._handleMouseDown.bind(this)); 99 } 93 100 } 94 101 … … 336 343 return mediaElement; 337 344 } 345 346 _handleMouseDown(event) 347 { 348 this._wasFocused = this._propertiesEditor.isFocused(); 349 } 350 351 _handleClick(event) 352 { 353 if (this._wasFocused) 354 return; 355 356 event.stop(); 357 358 if (event.target.classList.contains(WI.SpreadsheetStyleProperty.StyleClassName)) { 359 let propertyIndex = parseInt(event.target.dataset.propertyIndex); 360 this._propertiesEditor.addBlankProperty(propertyIndex + 1); 361 return; 362 } 363 364 if (event.target.isSelfOrDescendant(this._headerElement)) { 365 this._propertiesEditor.addBlankProperty(0); 366 return; 367 } 368 369 const appendAfterLast = -1; 370 this._propertiesEditor.addBlankProperty(appendAfterLast); 371 } 338 372 }; 339 373 -
trunk/Source/WebInspectorUI/UserInterface/Views/SpreadsheetStyleProperty.js
r223978 r224174 26 26 WI.SpreadsheetStyleProperty = class SpreadsheetStyleProperty extends WI.Object 27 27 { 28 constructor(delegate, property, newlyAdded = false)28 constructor(delegate, property, index) 29 29 { 30 30 super(); … … 34 34 this._delegate = delegate || null; 35 35 this._property = property; 36 this._newlyAdded = newlyAdded;37 36 this._element = document.createElement("div"); 37 this._element.dataset.propertyIndex = index; 38 38 39 39 this._nameElement = null; … … 87 87 }; 88 88 89 let classNames = [ "property"];89 let classNames = [WI.SpreadsheetStyleProperty.StyleClassName]; 90 90 91 91 if (this._property.overridden) … … 200 200 let propertyValue = this._valueTextField.value.trim(); 201 201 let willRemoveProperty = false; 202 let newlyAdded = this._valueTextField.valueBeforeEditing === ""; 202 203 203 204 // Remove a property with an empty name or value. However, a newly added property 204 205 // has an empty name and value at first. Don't remove it when moving focus from 205 206 // the name to the value for the first time. 206 if (!propertyName || (! this._newlyAdded && !propertyValue))207 if (!propertyName || (!newlyAdded && !propertyValue)) 207 208 willRemoveProperty = true; 208 209 … … 211 212 if (!isEditingName && !willRemoveProperty) 212 213 this._renderValue(propertyValue); 213 214 if (propertyName && isEditingName)215 this._newlyAdded = false;216 214 217 215 if (direction === "forward") { … … 489 487 }; 490 488 489 WI.SpreadsheetStyleProperty.StyleClassName = "property"; 490 491 491 WI.SpreadsheetStyleProperty.CommitCoalesceDelay = 250; -
trunk/Source/WebInspectorUI/UserInterface/Views/SpreadsheetTextField.js
r223453 r224174 47 47 48 48 this._editing = false; 49 this._ startEditingValue= "";49 this._valueBeforeEditing = ""; 50 50 } 51 51 … … 58 58 get value() { return this._element.textContent; } 59 59 set value(value) { this._element.textContent = value; } 60 61 get valueBeforeEditing() { return this._valueBeforeEditing; } 60 62 61 63 get suggestionHint() … … 84 86 85 87 this._editing = true; 86 this._ startEditingValue= this.value;88 this._valueBeforeEditing = this.value; 87 89 88 90 this._element.classList.add("editing"); … … 103 105 104 106 this._editing = false; 105 this._ startEditingValue= "";107 this._valueBeforeEditing = ""; 106 108 this._element.classList.remove("editing"); 107 109 this._element.contentEditable = false; … … 170 172 _discardChange() 171 173 { 172 if (this._ startEditingValue!== this.value) {173 this.value = this._ startEditingValue;174 if (this._valueBeforeEditing !== this.value) { 175 this.value = this._valueBeforeEditing; 174 176 this._selectText(); 175 177
Note: See TracChangeset
for help on using the changeset viewer.