Changeset 241209 in webkit


Ignore:
Timestamp:
Feb 8, 2019 2:17:56 PM (5 years ago)
Author:
Nikita Vasilyev
Message:

Web Inspector: Styles: close unbalanced quotes and parenthesis when editing values
https://bugs.webkit.org/show_bug.cgi?id=182523
<rdar://problem/37260209>

Reviewed by Devin Rousso.

Source/WebInspectorUI:

Close CSS comments, append missing closed quotes and right parenthesis.

  • UserInterface/Models/CSSCompletions.js:

(WI.CSSCompletions.completeUnbalancedValue):

  • UserInterface/Models/CSSProperty.js:

(WI.CSSProperty.prototype.set rawValue):

LayoutTests:

Test common cases of unmatched quotes, parenthesis, comments, and trailing backslashes.

  • inspector/unit-tests/css-completions-expected.txt: Added.
  • inspector/unit-tests/css-completions.html: Added.
Location:
trunk
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r241208 r241209  
     12019-02-08  Nikita Vasilyev  <nvasilyev@apple.com>
     2
     3        Web Inspector: Styles: close unbalanced quotes and parenthesis when editing values
     4        https://bugs.webkit.org/show_bug.cgi?id=182523
     5        <rdar://problem/37260209>
     6
     7        Reviewed by Devin Rousso.
     8
     9        Test common cases of unmatched quotes, parenthesis, comments, and trailing backslashes.
     10
     11        * inspector/unit-tests/css-completions-expected.txt: Added.
     12        * inspector/unit-tests/css-completions.html: Added.
     13
    1142019-02-08  Per Arne Vollan  <pvollan@apple.com>
    215
  • trunk/Source/WebInspectorUI/ChangeLog

    r241175 r241209  
     12019-02-08  Nikita Vasilyev  <nvasilyev@apple.com>
     2
     3        Web Inspector: Styles: close unbalanced quotes and parenthesis when editing values
     4        https://bugs.webkit.org/show_bug.cgi?id=182523
     5        <rdar://problem/37260209>
     6
     7        Reviewed by Devin Rousso.
     8
     9        Close CSS comments, append missing closed quotes and right parenthesis.
     10
     11        * UserInterface/Models/CSSCompletions.js:
     12        (WI.CSSCompletions.completeUnbalancedValue):
     13        * UserInterface/Models/CSSProperty.js:
     14        (WI.CSSProperty.prototype.set rawValue):
     15
    1162019-02-07  Joseph Pecoraro  <pecoraro@apple.com>
    217
  • trunk/Source/WebInspectorUI/UserInterface/Models/CSSCompletions.js

    r238048 r241209  
    172172    }
    173173
     174    static completeUnbalancedValue(value)
     175    {
     176        const State = {
     177            Data: 0,
     178            SingleQuoteString: 1,
     179            DoubleQuoteString: 2,
     180            Comment: 3
     181        };
     182
     183        let state = State.Data;
     184        let unclosedParenthesisCount = 0;
     185        let trailingBackslash = false;
     186        let length = value.length;
     187
     188        for (let i = 0; i < length; ++i) {
     189            switch (value[i]) {
     190            case "'":
     191                if (state === State.Data)
     192                    state = State.SingleQuoteString;
     193                else if (state === State.SingleQuoteString)
     194                    state = State.Data;
     195                break;
     196
     197            case "\"":
     198                if (state === State.Data)
     199                    state = State.DoubleQuoteString;
     200                else if (state === State.DoubleQuoteString)
     201                    state = State.Data;
     202                break;
     203
     204            case "(":
     205                if (state === State.Data)
     206                    ++unclosedParenthesisCount;
     207                break;
     208
     209            case ")":
     210                if (state === State.Data && unclosedParenthesisCount)
     211                    --unclosedParenthesisCount;
     212                break;
     213
     214            case "/":
     215                if (state === State.Data) {
     216                    if (value[i + 1] === "*")
     217                        state = State.Comment;
     218                }
     219                break;
     220
     221            case "\\":
     222                if (i === length - 1)
     223                    trailingBackslash = true;
     224                else
     225                    ++i; // Skip next character.
     226                break;
     227
     228            case "*":
     229                if (state === State.Comment) {
     230                    if (value[i + 1] === "/")
     231                        state = State.Data;
     232                }
     233                break;
     234            }
     235        }
     236
     237        let suffix = "";
     238
     239        if (trailingBackslash)
     240            suffix += "\\";
     241
     242        switch (state) {
     243        case State.SingleQuoteString:
     244            suffix += "'";
     245            break;
     246        case State.DoubleQuoteString:
     247            suffix += "\"";
     248            break;
     249        case State.Comment:
     250            suffix += "*/";
     251            break;
     252        }
     253
     254        suffix += ")".repeat(unclosedParenthesisCount);
     255
     256        return suffix;
     257    }
     258
    174259    // Public
    175260
  • trunk/Source/WebInspectorUI/UserInterface/Models/CSSProperty.js

    r240946 r241209  
    231231        this._markModified();
    232232
     233        let suffix = WI.CSSCompletions.completeUnbalancedValue(value);
     234        if (suffix)
     235            value += suffix;
     236
    233237        this._rawValue = value;
    234238        this._value = undefined;
Note: See TracChangeset for help on using the changeset viewer.