Changeset 188427 in webkit


Ignore:
Timestamp:
Aug 13, 2015 6:51:06 PM (9 years ago)
Author:
Devin Rousso
Message:

REGRESSION (r184000): Web Inspector: Stripped whitespace after editing CSS in Styles sidebar
https://bugs.webkit.org/show_bug.cgi?id=145679

Reviewed by Timothy Hatcher.

The formatter will now calculate the number of beginning spaces before the first line in a rule
and duplicate them in front of every other line. If there is no new line at the beginning or are
no spaces, assume 4 spaces and a new line for each property.
Also cleaned up the code for _resetContent a bit.

  • UserInterface/Views/CSSStyleDeclarationTextEditor.js:

(WebInspector.CSSStyleDeclarationTextEditor):
(WebInspector.CSSStyleDeclarationTextEditor.prototype._resetContent.update.set get this):
(WebInspector.CSSStyleDeclarationTextEditor.prototype._resetContent.update.get this):
(WebInspector.CSSStyleDeclarationTextEditor.prototype._resetContent.update):
(WebInspector.CSSStyleDeclarationTextEditor.prototype._resetContent):

Location:
trunk/Source/WebInspectorUI
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebInspectorUI/ChangeLog

    r188408 r188427  
     12015-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
    1202015-08-13  Matt Baker  <mattbaker@apple.com>
    221
  • trunk/Source/WebInspectorUI/UserInterface/Views/CSSStyleDeclarationTextEditor.js

    r188325 r188427  
    4444        this._sortProperties = false;
    4545
    46         this._prefixWhitespace = "";
    47         this._suffixWhitespace = "";
     46        this._prefixWhitespace = "\n";
     47        this._suffixWhitespace = "\n";
    4848        this._linePrefixWhitespace = "";
    4949
     
    5555            mode: "css-rule",
    5656            electricChars: false,
    57             indentWithTabs: true,
     57            indentWithTabs: false,
    5858            indentUnit: 4,
    5959            smartIndent: false,
     
    16071607        if (this._commitChangesTimeout) {
    16081608            clearTimeout(this._commitChangesTimeout);
    1609             delete this._commitChangesTimeout;
     1609            this._commitChangesTimeout = null;
    16101610        }
    16111611
     
    16131613
    16141614        // Only allow editing if we have a style, it is editable and we have text range in the stylesheet.
    1615         var readOnly = !this._style || !this._style.editable || !this._style.styleSheetTextRange;
     1615        const readOnly = !this._style || !this._style.editable || !this._style.styleSheetTextRange;
    16161616        this._codeMirror.setOption("readOnly", readOnly);
    16171617
     
    16281628
    16291629            this._clearTextMarkers(false, true);
    1630 
    16311630            this._codeMirror.setValue("");
    16321631            this._codeMirror.clearHistory();
    16331632            this._codeMirror.markClean();
    16341633
    1635             delete this._ignoreCodeMirrorContentDidChangeEvent;
    1636 
     1634            this._ignoreCodeMirrorContentDidChangeEvent = false;
    16371635            return;
    16381636        }
     
    16411639        {
    16421640            // 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();
    16481644
    16491645            // We only need to format non-empty styles, but prepare checkbox placeholders
    16501646            // in any case because that will indent the cursor when the User starts typing.
    1651             if (!styleText && !isEditorReadOnly) {
     1647            if (!trimmedStyleText && !isEditorReadOnly) {
    16521648                this._markLinesWithCheckboxPlaceholder();
    16531649                return;
     
    16571653            if (isEditorReadOnly) {
    16581654                this._codeMirror.setValue("");
    1659                 var lineNumber = 0;
     1655                let lineNumber = 0;
    16601656                this._iterateOverProperties(false, function(property) {
    1661                     var from = {line: lineNumber, ch: 0};
    1662                     var to = {line: lineNumber};
     1657                    let from = {line: lineNumber, ch: 0};
     1658                    let to = {line: lineNumber};
    16631659                    // Readonly properties are pretty printed by `synthesizedText` and not the Formatter.
    16641660                    this._codeMirror.replaceRange((lineNumber ? "\n" : "") + property.synthesizedText, from);
     
    16691665            }
    16701666
     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
    16711684            // Set non-optimized, valid and invalid styles in preparation for the Formatter.
    1672             this._codeMirror.setValue(styleText);
     1685            this._codeMirror.setValue(trimmedStyleText);
    16731686
    16741687            // Now the Formatter pretty prints the styles.
     
    16791692            // comments and invalid properties like `color;`.
    16801693            // 2) `_createTextMarkerForPropertyIfNeeded` relies on CSSProperty instances.
    1681             var cssPropertiesMap = new Map();
     1694            let cssPropertiesMap = new Map();
    16821695            this._iterateOverProperties(false, function(cssProperty) {
    16831696                cssProperty.__refreshedAfterBlur = false;
    16841697
    1685                 var propertyTextSansWhitespace = cssProperty.text.replace(findWhitespace, "");
    1686                 var existingProperties = cssPropertiesMap.get(propertyTextSansWhitespace) || [];
     1698                let propertyTextSansWhitespace = cssProperty.text.replace(whitespaceRegex, "");
     1699                let existingProperties = cssPropertiesMap.get(propertyTextSansWhitespace) || [];
    16871700                existingProperties.push(cssProperty);
    16881701
     
    16931706            // CSSProperty instance for that property exists. If not, then don't create a TextMarker.
    16941707            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);
    16991711                if (!properties) {
    17001712                    this._createCommentedCheckboxMarker(lineHandler);
     
    17021714                }
    17031715
    1704                 for (var property of properties) {
     1716                for (let property of properties) {
    17051717                    if (property.__refreshedAfterBlur)
    17061718                        continue;
    17071719
    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};
    17111722                    this._createTextMarkerForPropertyIfNeeded(from, to, property);
    17121723                    property.__refreshedAfterBlur = true;
    1713 
    17141724                    break;
    17151725                }
     
    17381748        this._ignoreCodeMirrorContentDidChangeEvent = true;
    17391749        this._codeMirror.operation(update.bind(this));
    1740         delete this._ignoreCodeMirrorContentDidChangeEvent;
     1750        this._ignoreCodeMirrorContentDidChangeEvent = false;
    17411751    }
    17421752
Note: See TracChangeset for help on using the changeset viewer.