Changeset 188427 in webkit
- Timestamp:
- Aug 13, 2015 6:51:06 PM (9 years ago)
- Location:
- trunk/Source/WebInspectorUI
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebInspectorUI/ChangeLog
r188408 r188427 1 2015-08-13 Devin Rousso <drousso@apple.com> 2 3 REGRESSION (r184000): Web Inspector: Stripped whitespace after editing CSS in Styles sidebar 4 https://bugs.webkit.org/show_bug.cgi?id=145679 5 6 Reviewed by Timothy Hatcher. 7 8 The formatter will now calculate the number of beginning spaces before the first line in a rule 9 and duplicate them in front of every other line. If there is no new line at the beginning or are 10 no spaces, assume 4 spaces and a new line for each property. 11 Also cleaned up the code for _resetContent a bit. 12 13 * UserInterface/Views/CSSStyleDeclarationTextEditor.js: 14 (WebInspector.CSSStyleDeclarationTextEditor): 15 (WebInspector.CSSStyleDeclarationTextEditor.prototype._resetContent.update.set get this): 16 (WebInspector.CSSStyleDeclarationTextEditor.prototype._resetContent.update.get this): 17 (WebInspector.CSSStyleDeclarationTextEditor.prototype._resetContent.update): 18 (WebInspector.CSSStyleDeclarationTextEditor.prototype._resetContent): 19 1 20 2015-08-13 Matt Baker <mattbaker@apple.com> 2 21 -
trunk/Source/WebInspectorUI/UserInterface/Views/CSSStyleDeclarationTextEditor.js
r188325 r188427 44 44 this._sortProperties = false; 45 45 46 this._prefixWhitespace = " ";47 this._suffixWhitespace = " ";46 this._prefixWhitespace = "\n"; 47 this._suffixWhitespace = "\n"; 48 48 this._linePrefixWhitespace = ""; 49 49 … … 55 55 mode: "css-rule", 56 56 electricChars: false, 57 indentWithTabs: true,57 indentWithTabs: false, 58 58 indentUnit: 4, 59 59 smartIndent: false, … … 1607 1607 if (this._commitChangesTimeout) { 1608 1608 clearTimeout(this._commitChangesTimeout); 1609 delete this._commitChangesTimeout;1609 this._commitChangesTimeout = null; 1610 1610 } 1611 1611 … … 1613 1613 1614 1614 // Only allow editing if we have a style, it is editable and we have text range in the stylesheet. 1615 varreadOnly = !this._style || !this._style.editable || !this._style.styleSheetTextRange;1615 const readOnly = !this._style || !this._style.editable || !this._style.styleSheetTextRange; 1616 1616 this._codeMirror.setOption("readOnly", readOnly); 1617 1617 … … 1628 1628 1629 1629 this._clearTextMarkers(false, true); 1630 1631 1630 this._codeMirror.setValue(""); 1632 1631 this._codeMirror.clearHistory(); 1633 1632 this._codeMirror.markClean(); 1634 1633 1635 delete this._ignoreCodeMirrorContentDidChangeEvent; 1636 1634 this._ignoreCodeMirrorContentDidChangeEvent = false; 1637 1635 return; 1638 1636 } … … 1641 1639 { 1642 1640 // Remember the cursor position/selection. 1643 var selectionAnchor = this._codeMirror.getCursor("anchor"); 1644 var selectionHead = this._codeMirror.getCursor("head"); 1645 var isEditorReadOnly = this._codeMirror.getOption("readOnly"); 1646 var styleText = this._style.text.trim(); 1647 var findWhitespace = /\s+/g; 1641 let isEditorReadOnly = this._codeMirror.getOption("readOnly"); 1642 let styleText = this._style.text; 1643 let trimmedStyleText = styleText.trim(); 1648 1644 1649 1645 // We only need to format non-empty styles, but prepare checkbox placeholders 1650 1646 // in any case because that will indent the cursor when the User starts typing. 1651 if (! styleText && !isEditorReadOnly) {1647 if (!trimmedStyleText && !isEditorReadOnly) { 1652 1648 this._markLinesWithCheckboxPlaceholder(); 1653 1649 return; … … 1657 1653 if (isEditorReadOnly) { 1658 1654 this._codeMirror.setValue(""); 1659 varlineNumber = 0;1655 let lineNumber = 0; 1660 1656 this._iterateOverProperties(false, function(property) { 1661 varfrom = {line: lineNumber, ch: 0};1662 varto = {line: lineNumber};1657 let from = {line: lineNumber, ch: 0}; 1658 let to = {line: lineNumber}; 1663 1659 // Readonly properties are pretty printed by `synthesizedText` and not the Formatter. 1664 1660 this._codeMirror.replaceRange((lineNumber ? "\n" : "") + property.synthesizedText, from); … … 1669 1665 } 1670 1666 1667 let selectionAnchor = this._codeMirror.getCursor("anchor"); 1668 let selectionHead = this._codeMirror.getCursor("head"); 1669 let whitespaceRegex = /\s+/g; 1670 1671 // FIXME: <rdar://problem/10593948> Provide a way to change the tab width in the Web Inspector 1672 this._linePrefixWhitespace = " "; 1673 let styleTextPrefixWhitespace = styleText.match(/^\s*/); 1674 1675 // If there is a match and the style text contains a newline, attempt to pull out the prefix whitespace 1676 // in front of the first line of CSS to use for every line. If there is no newline, we want to avoid 1677 // adding multiple spaces to a single line CSS rule and instead format it on multiple lines. 1678 if (styleTextPrefixWhitespace && trimmedStyleText.includes("\n")) { 1679 let linePrefixWhitespaceMatch = styleTextPrefixWhitespace[0].match(/[^\S\n]+$/); 1680 if (linePrefixWhitespaceMatch) 1681 this._linePrefixWhitespace = linePrefixWhitespaceMatch[0]; 1682 } 1683 1671 1684 // Set non-optimized, valid and invalid styles in preparation for the Formatter. 1672 this._codeMirror.setValue( styleText);1685 this._codeMirror.setValue(trimmedStyleText); 1673 1686 1674 1687 // Now the Formatter pretty prints the styles. … … 1679 1692 // comments and invalid properties like `color;`. 1680 1693 // 2) `_createTextMarkerForPropertyIfNeeded` relies on CSSProperty instances. 1681 varcssPropertiesMap = new Map();1694 let cssPropertiesMap = new Map(); 1682 1695 this._iterateOverProperties(false, function(cssProperty) { 1683 1696 cssProperty.__refreshedAfterBlur = false; 1684 1697 1685 var propertyTextSansWhitespace = cssProperty.text.replace(findWhitespace, "");1686 varexistingProperties = cssPropertiesMap.get(propertyTextSansWhitespace) || [];1698 let propertyTextSansWhitespace = cssProperty.text.replace(whitespaceRegex, ""); 1699 let existingProperties = cssPropertiesMap.get(propertyTextSansWhitespace) || []; 1687 1700 existingProperties.push(cssProperty); 1688 1701 … … 1693 1706 // CSSProperty instance for that property exists. If not, then don't create a TextMarker. 1694 1707 this._codeMirror.eachLine(function(lineHandler) { 1695 var lineNumber = lineHandler.lineNo(); 1696 var lineContentSansWhitespace = lineHandler.text.replace(findWhitespace, ""); 1697 var properties = cssPropertiesMap.get(lineContentSansWhitespace); 1698 1708 let lineNumber = lineHandler.lineNo(); 1709 let lineContentSansWhitespace = lineHandler.text.replace(whitespaceRegex, ""); 1710 let properties = cssPropertiesMap.get(lineContentSansWhitespace); 1699 1711 if (!properties) { 1700 1712 this._createCommentedCheckboxMarker(lineHandler); … … 1702 1714 } 1703 1715 1704 for ( varproperty of properties) {1716 for (let property of properties) { 1705 1717 if (property.__refreshedAfterBlur) 1706 1718 continue; 1707 1719 1708 var from = {line: lineNumber, ch: 0}; 1709 var to = {line: lineNumber}; 1710 1720 let from = {line: lineNumber, ch: 0}; 1721 let to = {line: lineNumber}; 1711 1722 this._createTextMarkerForPropertyIfNeeded(from, to, property); 1712 1723 property.__refreshedAfterBlur = true; 1713 1714 1724 break; 1715 1725 } … … 1738 1748 this._ignoreCodeMirrorContentDidChangeEvent = true; 1739 1749 this._codeMirror.operation(update.bind(this)); 1740 delete this._ignoreCodeMirrorContentDidChangeEvent;1750 this._ignoreCodeMirrorContentDidChangeEvent = false; 1741 1751 } 1742 1752
Note: See TracChangeset
for help on using the changeset viewer.