Changeset 122114 in webkit


Ignore:
Timestamp:
Jul 9, 2012 10:30:38 AM (12 years ago)
Author:
pfeldman@chromium.org
Message:

Web Inspector: unindent line ending block upon { hit.
https://bugs.webkit.org/show_bug.cgi?id=90795

Reviewed by Vsevolod Vlasov.

Added block-start / block-end markup into the highlighter.

  • inspector/front-end/SourceCSSTokenizer.js:

(WebInspector.SourceCSSTokenizer.prototype.nextToken):

  • inspector/front-end/SourceCSSTokenizer.re2js:
  • inspector/front-end/SourceJavaScriptTokenizer.js:

(WebInspector.SourceJavaScriptTokenizer.prototype.nextToken):

  • inspector/front-end/SourceJavaScriptTokenizer.re2js:
  • inspector/front-end/TextEditor.js:

(WebInspector.TextEditorMainPanel.prototype._applyDomUpdates):
(WebInspector.TextEditorMainPanel.prototype._unindentAfterBlock):

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/inspector/syntax-highlight-css-expected.txt

    r103231 r122114  
    55@import url(style.css);: webkit-css-at-rule,*,webkit-css-keyword,*
    66@import url("style.css") projection, tv;: webkit-css-at-rule,*,webkit-css-keyword,*,webkit-css-string,*,webkit-css-keyword,*,webkit-css-keyword,*
    7 @import "/css/fireball_unicode.css"; html {}: webkit-css-at-rule,*,webkit-css-string,*,webkit-css-selector,*
    8 @media screen { body { color: red; } }: webkit-css-at-rule,*,webkit-css-keyword,*,webkit-css-selector,*,webkit-css-property,*,webkit-css-color,*
    9 @font-face { font-family: "MyHelvetica"; }: webkit-css-at-rule,*,webkit-css-property,*,webkit-css-string,*
    10 p { color: color; red: red; color: #000; color: #FFF; color: #123AbC; color: #faebfe; color:papayawhip; }: webkit-css-selector,*,webkit-css-property,*,webkit-css-color,*,webkit-css-property,*,webkit-css-color,*,webkit-css-property,*,webkit-css-color,*,webkit-css-property,*,webkit-css-color,*,webkit-css-property,*,webkit-css-color,*,webkit-css-property,*,webkit-css-color,*
    11 p { margin: -10px !important; }: webkit-css-selector,*,webkit-css-property,*,webkit-css-number,*,webkit-css-important,*
     7@import "/css/fireball_unicode.css"; html {}: webkit-css-at-rule,*,webkit-css-string,*,webkit-css-selector,*,webkit-block-start,webkit-block-end
     8@media screen { body { color: red; } }: webkit-css-at-rule,*,webkit-css-keyword,*,webkit-block-start,*,webkit-css-selector,*,webkit-block-start,*,webkit-css-property,*,webkit-css-color,*,webkit-block-end,*,webkit-block-end
     9@font-face { font-family: "MyHelvetica"; }: webkit-css-at-rule,*,webkit-block-start,*,webkit-css-property,*,webkit-css-string,*,webkit-block-end
     10p { color: color; red: red; color: #000; color: #FFF; color: #123AbC; color: #faebfe; color:papayawhip; }: webkit-css-selector,*,webkit-block-start,*,webkit-css-property,*,webkit-css-color,*,webkit-css-property,*,webkit-css-color,*,webkit-css-property,*,webkit-css-color,*,webkit-css-property,*,webkit-css-color,*,webkit-css-property,*,webkit-css-color,*,webkit-css-property,*,webkit-css-color,*,webkit-block-end
     11p { margin: -10px !important; }: webkit-css-selector,*,webkit-block-start,*,webkit-css-property,*,webkit-css-number,*,webkit-css-important,*,webkit-block-end
    1212
  • trunk/LayoutTests/inspector/syntax-highlight-javascript-expected.txt

    r86554 r122114  
    1616/
    1717*/foo: webkit-javascript-ident,webkit-javascript-comment,,webkit-javascript-comment,,webkit-javascript-comment,webkit-javascript-ident
    18 {0: true}: *,webkit-javascript-number,*,webkit-javascript-keyword,*
     18{0: true}: webkit-block-start,webkit-javascript-number,*,webkit-javascript-keyword,webkit-block-end
    1919var toString;: webkit-javascript-keyword,*,webkit-javascript-ident,*
    2020
  • trunk/Source/WebCore/ChangeLog

    r122110 r122114  
     12012-07-09  Pavel Feldman  <pfeldman@chromium.org>
     2
     3        Web Inspector: unindent line ending block upon { hit.
     4        https://bugs.webkit.org/show_bug.cgi?id=90795
     5
     6        Reviewed by Vsevolod Vlasov.
     7
     8        Added block-start / block-end markup into the highlighter.
     9
     10        * inspector/front-end/SourceCSSTokenizer.js:
     11        (WebInspector.SourceCSSTokenizer.prototype.nextToken):
     12        * inspector/front-end/SourceCSSTokenizer.re2js:
     13        * inspector/front-end/SourceJavaScriptTokenizer.js:
     14        (WebInspector.SourceJavaScriptTokenizer.prototype.nextToken):
     15        * inspector/front-end/SourceJavaScriptTokenizer.re2js:
     16        * inspector/front-end/TextEditor.js:
     17        (WebInspector.TextEditorMainPanel.prototype._applyDomUpdates):
     18        (WebInspector.TextEditorMainPanel.prototype._unindentAfterBlock):
     19
    1202012-07-09  Sheriff Bot  <webkit.review.bot@gmail.com>
    221
  • trunk/Source/WebCore/inspector/front-end/SourceCSSTokenizer.js

    r114880 r122114  
    1 /* Generated by re2c 0.13.5 on Mon Dec 19 17:28:29 2011 */
     1/* Generated by re2c 0.13.5 on Mon Jul  9 19:31:30 2012 */
    22/*
    33 * Copyright (C) 2009 Google Inc. All rights reserved.
     
    3434/*
    3535re2c -isc Source/WebCore/inspector/front-end/SourceCSSTokenizer.re2js \
    36  | sed 's|^yy\([^:]*\)*\:|case \1:|' \
    37  | sed 's|[*]cursor[+][+]|this._charAt(cursor++)|' \
    38  | sed 's|[[*][+][+]cursor|this._charAt(++cursor)|' \
    39  | sed 's|[*]cursor|this._charAt(cursor)|' \
    40  | sed 's|yych = \*\([^;]*\)|yych = this._charAt\1|' \
    41  | sed 's|{ gotoCase = \([^; continue; };]*\)|{ gotoCase = \1; continue; }|' \
    42  | sed 's|unsigned\ int|var|' \
    43  | sed 's|var\ yych|case 1: case 1: var yych|' > Source/WebCore/inspector/front-end/SourceCSSTokenizer.js
     36  | sed 's|^yy\([^:]*\)*\:|case \1:|' \
     37  | sed 's|[*]cursor[+][+]|this._charAt(cursor++)|' \
     38  | sed 's|[[*][+][+]cursor|this._charAt(++cursor)|' \
     39  | sed 's|[*]cursor|this._charAt(cursor)|' \
     40  | sed 's|yych = \*\([^;]*\)|yych = this._charAt\1|' \
     41  | sed 's|{ gotoCase = \([^; continue; };]*\)|{ gotoCase = \1; continue; }|' \
     42  | sed 's|yych <= \(0x[0-9a-fA-F]*\)|yych \<\= String.fromCharCode(\1)|' \
     43  | sed 's|unsigned\ int|var|' \
     44  | sed 's|var\ yych|case 1: case 1: var yych|' > Source/WebCore/inspector/front-end/SourceCSSTokenizer.js
    4445*/
    4546
     
    649650            ++cursor;
    650651            {
    651                     this.tokenType = null;
     652                    this.tokenType = "block-start";
    652653                    if (this._condition.parseCondition === this._parseConditions.AT_MEDIA_RULE)
    653654                        this._condition.parseCondition = this._parseConditions.INITIAL;
     
    659660            ++cursor;
    660661            {
    661                     this.tokenType = null;
     662                    this.tokenType = "block-end";
    662663                    this._condition.parseCondition = this._parseConditions.INITIAL;
    663664                    return cursor;
  • trunk/Source/WebCore/inspector/front-end/SourceCSSTokenizer.re2js

    r114880 r122114  
    3333/*
    3434re2c -isc Source/WebCore/inspector/front-end/SourceCSSTokenizer.re2js \
    35  | sed 's|^yy\([^:]*\)*\:|case \1:|' \
    36  | sed 's|[*]cursor[+][+]|this._charAt(cursor++)|' \
    37  | sed 's|[[*][+][+]cursor|this._charAt(++cursor)|' \
    38  | sed 's|[*]cursor|this._charAt(cursor)|' \
    39  | sed 's|yych = \*\([^;]*\)|yych = this._charAt\1|' \
    40  | sed 's|goto case \([^;]*\)|{ gotoCase = \1; continue; }|' \
    41  | sed 's|unsigned\ int|var|' \
    42  | sed 's|var\ yych|case 1: var yych|' > Source/WebCore/inspector/front-end/SourceCSSTokenizer.js
     35  | sed 's|^yy\([^:]*\)*\:|case \1:|' \
     36  | sed 's|[*]cursor[+][+]|this._charAt(cursor++)|' \
     37  | sed 's|[[*][+][+]cursor|this._charAt(++cursor)|' \
     38  | sed 's|[*]cursor|this._charAt(cursor)|' \
     39  | sed 's|yych = \*\([^;]*\)|yych = this._charAt\1|' \
     40  | sed 's|goto case \([^;]*\)|{ gotoCase = \1; continue; }|' \
     41  | sed 's|yych <= \(0x[0-9a-fA-F]*\)|yych \<\= String.fromCharCode(\1)|' \
     42  | sed 's|unsigned\ int|var|' \
     43  | sed 's|var\ yych|case 1: var yych|' > Source/WebCore/inspector/front-end/SourceCSSTokenizer.js
    4344*/
    4445
     
    212213                <INITIAL> OpenCurlyBracket
    213214                {
    214                     this.tokenType = null;
     215                    this.tokenType = "block-start";
    215216                    if (this._condition.parseCondition === this._parseConditions.AT_MEDIA_RULE)
    216217                        this._condition.parseCondition = this._parseConditions.INITIAL;
     
    222223                <INITIAL> CloseCurlyBracket
    223224                {
    224                     this.tokenType = null;
     225                    this.tokenType = "block-end";
    225226                    this._condition.parseCondition = this._parseConditions.INITIAL;
    226227                    return cursor;
  • trunk/Source/WebCore/inspector/front-end/SourceFrame.js

    r121957 r122114  
    170170        this._lineToHighlight = line;
    171171        this._innerHighlightLineIfNeeded();
     172        this._textEditor.setSelection(WebInspector.TextRange.createFromLocation(line, 0));
    172173    },
    173174
  • trunk/Source/WebCore/inspector/front-end/SourceJavaScriptTokenizer.js

    r108331 r122114  
    1 /* Generated by re2c 0.13.5 on Fri May 13 20:01:13 2011 */
     1/* Generated by re2c 0.13.5 on Mon Jul  9 18:23:02 2012 */
    22/*
    33 * Copyright (C) 2009 Google Inc. All rights reserved.
     
    3030 */
    3131
    32 // Generate js file as follows:
    33 //
    34 // re2c -isc WebCore/inspector/front-end/SourceJavaScriptTokenizer.re2js \
    35 // | sed 's|^yy\([^:]*\)*\:|case \1:|' \
    36 // | sed 's|[*]cursor[+][+]|this._charAt(cursor++)|' \
    37 // | sed 's|[[*][+][+]cursor|this._charAt(++cursor)|' \
    38 // | sed 's|[*]cursor|this._charAt(cursor)|' \
    39 // | sed 's|yych = \*\([^;]*\)|yych = this._charAt\1|' \
    40 // | sed 's|{ gotoCase = \([^; continue; };]*\)|{ gotoCase = \1; continue; }|' \
    41 // | sed 's|yych <= \(0x[0-9a-fA-f]+\)|yych <= String.fromCharCode(\1)|' \
    42 // | sed 's|unsigned\ int|var|' \
    43 // | sed 's|var\ yych|case 1: case 1: var yych|'
     32/*
     33 * Generate js file as follows:
     34re2c -isc Source/WebCore/inspector/front-end/SourceJavaScriptTokenizer.re2js \
     35  | sed 's|^yy\([^:]*\)*\:|case \1:|' \
     36  | sed 's|[*]cursor[+][+]|this._charAt(cursor++)|' \
     37  | sed 's|[[*][+][+]cursor|this._charAt(++cursor)|' \
     38  | sed 's|[*]cursor|this._charAt(cursor)|' \
     39  | sed 's|yych = \*\([^;]*\)|yych = this._charAt\1|' \
     40  | sed 's|{ gotoCase = \([^; continue; };]*\)|{ gotoCase = \1; continue; }|' \
     41  | sed 's|yych <= \(0x[0-9a-fA-F]*\)|yych \<\= String.fromCharCode(\1)|' \
     42  | sed 's|unsigned\ int|var|' \
     43  | sed 's|var\ yych|case 1: case 1: var yych|'
     44 */
    4445
    4546/**
     
    9192            switch (gotoCase)
    9293            // Following comment is replaced with generated state machine.
    93 
     94           
    9495        {
    9596            case 1: var yych;
     
    244245case 18:
    245246            this.setLexCondition(this._lexConditions.NODIV);
    246             { this.tokenType = null; return cursor; }
     247            {
     248                    var token = this._line.charAt(cursorOnEnter);
     249                    if (token === "{")
     250                        this.tokenType = "block-start";
     251                    else if (token === "}")
     252                        this.tokenType = "block-end";
     253                    else this.tokenType = null;
     254                    return cursor;
     255                }
    247256case 19:
    248257            yyaccept = 0;
     
    11751184            if ((yych = this._charAt(cursor)) == '=') { gotoCase = 260; continue; };
    11761185case 139:
    1177             { this.tokenType = null; return cursor; }
     1186            {
     1187                    var token = this._line.charAt(cursorOnEnter);
     1188                    if (token === "{")
     1189                        this.tokenType = "block-start";
     1190                    else if (token === "}")
     1191                        this.tokenType = "block-end";
     1192                    else this.tokenType = null;
     1193                    return cursor;
     1194                }
    11781195case 140:
    11791196            yyaccept = 0;
  • trunk/Source/WebCore/inspector/front-end/SourceJavaScriptTokenizer.re2js

    r108331 r122114  
    2929 */
    3030
    31 // Generate js file as follows:
    32 //
    33 // re2c -isc Source/WebCore/inspector/front-end/SourceJavaScriptTokenizer.re2js \
    34 // | sed 's|^yy\([^:]*\)*\:|case \1:|' \
    35 // | sed 's|[*]cursor[+][+]|this._charAt(cursor++)|' \
    36 // | sed 's|[[*][+][+]cursor|this._charAt(++cursor)|' \
    37 // | sed 's|[*]cursor|this._charAt(cursor)|' \
    38 // | sed 's|yych = \*\([^;]*\)|yych = this._charAt\1|' \
    39 // | sed 's|goto case \([^;]*\)|{ gotoCase = \1; continue; }|' \
    40 // | sed 's|yych <= \(0x[0-9a-fA-f]*\)|yych <= String.fromCharCode(\1)|' \
    41 // | sed 's|unsigned\ int|var|' \
    42 // | sed 's|var\ yych|case 1: var yych|'
     31/*
     32 * Generate js file as follows:
     33re2c -isc Source/WebCore/inspector/front-end/SourceJavaScriptTokenizer.re2js \
     34  | sed 's|^yy\([^:]*\)*\:|case \1:|' \
     35  | sed 's|[*]cursor[+][+]|this._charAt(cursor++)|' \
     36  | sed 's|[[*][+][+]cursor|this._charAt(++cursor)|' \
     37  | sed 's|[*]cursor|this._charAt(cursor)|' \
     38  | sed 's|yych = \*\([^;]*\)|yych = this._charAt\1|' \
     39  | sed 's|goto case \([^;]*\)|{ gotoCase = \1; continue; }|' \
     40  | sed 's|yych <= \(0x[0-9a-fA-F]*\)|yych \<\= String.fromCharCode(\1)|' \
     41  | sed 's|unsigned\ int|var|' \
     42  | sed 's|var\ yych|case 1: var yych|' > Source/WebCore/inspector/front-end/SourceJavaScriptTokenizer.js
     43 */
    4344
    4445/**
     
    178179                }
    179180                <DIV,NODIV> RightParen => DIV { this.tokenType = null; return cursor; }
    180                 <DIV,NODIV> Punctuation => NODIV { this.tokenType = null; return cursor; }
     181                <DIV,NODIV> Punctuation => NODIV
     182                {
     183                    var token = this._line.charAt(cursorOnEnter);
     184                    if (token === "{")
     185                        this.tokenType = "block-start";
     186                    else if (token === "}")
     187                        this.tokenType = "block-end";
     188                    else this.tokenType = null;
     189                    return cursor;
     190                }
    181191                <DIV> Division => NODIV { this.tokenType = null; return cursor; }
    182192                <*> [^] { this.tokenType = null; return cursor; }
  • trunk/Source/WebCore/inspector/front-end/TextEditor.js

    r121984 r122114  
    21922192        }
    21932193
     2194        if (lines.length === 1 && lines[0] === "}" && oldRange.isEmpty() && selection.isEmpty() && !this._textModel.line(oldRange.endLine).trim())
     2195            this._unindentAfterBlock(oldRange, selection);
     2196       
    21942197        // This is a "foreign" call outside of this class. Should be before we delete the dirty lines flag.
    21952198        this._enterTextChangeMode();
     
    22032206
    22042207        this._exitTextChangeMode(oldRange, newRange);
     2208    },
     2209
     2210    /**
     2211     * @param {WebInspector.TextRange} oldRange
     2212     * @param {WebInspector.TextRange} selection
     2213     */
     2214    _unindentAfterBlock: function(oldRange, selection)
     2215    {
     2216        var nestingLevel = 1;
     2217        for (var i = oldRange.endLine; i >= 0; --i) {
     2218            var attribute = this._textModel.getAttribute(i, "highlight");
     2219            if (!attribute)
     2220                continue;
     2221            var columnNumbers = Object.keys(attribute).reverse();
     2222            for (var j = 0; j < columnNumbers.length; ++j) {
     2223                var column = columnNumbers[j];
     2224                if (attribute[column].tokenType === "block-start") {
     2225                    if (!(--nestingLevel)) {
     2226                        var lineContent = this._textModel.line(i);
     2227                        var blockOffset = lineContent.length - lineContent.trimLeft().length;
     2228                        if (blockOffset < oldRange.startColumn) {
     2229                            oldRange.startColumn = blockOffset;
     2230                            selection.startColumn = blockOffset + 1;
     2231                            selection.endColumn = blockOffset + 1;
     2232                        }
     2233                        return;
     2234                    }
     2235                }
     2236                if (attribute[column].tokenType === "block-end")
     2237                    ++nestingLevel;
     2238            }
     2239        }
    22052240    },
    22062241
Note: See TracChangeset for help on using the changeset viewer.