Changeset 142621 in webkit


Ignore:
Timestamp:
Feb 12, 2013 7:18:20 AM (11 years ago)
Author:
commit-queue@webkit.org
Message:

Web Inspector: refactor some reusable functionality from BraceHighlighter
https://bugs.webkit.org/show_bug.cgi?id=109574

Patch by Andrey Lushnikov <lushnikov@chromium.org> on 2013-02-12
Reviewed by Pavel Feldman.

Source/WebCore:

New test: inspector/editor/text-editor-brace-highlighter.html

Extract functionality which, for given line and cursor position, will
return position for a brace that should be highlighted. Add a layout
test to verify brace highlighter funcionality.

  • inspector/front-end/DefaultTextEditor.js:

(WebInspector.TextEditorMainPanel.BraceHighlightController.prototype.activeBraceColumnForCursorPosition):
(WebInspector.TextEditorMainPanel.BraceHighlightController.prototype.handleSelectionChange):

  • inspector/front-end/TextUtils.js:

(WebInspector.TextUtils.isOpeningBraceChar):
(WebInspector.TextUtils.isClosingBraceChar):
(WebInspector.TextUtils.isBraceChar):

LayoutTests:

Add layout test to verify brace highlighter functionality.

  • inspector/editor/text-editor-brace-highlighter-expected.txt: Added.
  • inspector/editor/text-editor-brace-highlighter.html: Added.
Location:
trunk
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r142619 r142621  
     12013-02-12  Andrey Lushnikov  <lushnikov@chromium.org>
     2
     3        Web Inspector: refactor some reusable functionality from BraceHighlighter
     4        https://bugs.webkit.org/show_bug.cgi?id=109574
     5
     6        Reviewed by Pavel Feldman.
     7
     8        Add layout test to verify brace highlighter functionality.
     9
     10        * inspector/editor/text-editor-brace-highlighter-expected.txt: Added.
     11        * inspector/editor/text-editor-brace-highlighter.html: Added.
     12
    1132013-02-12  Andrew Wilson  <atwilson@chromium.org>
    214
  • trunk/Source/WebCore/ChangeLog

    r142618 r142621  
     12013-02-12  Andrey Lushnikov  <lushnikov@chromium.org>
     2
     3        Web Inspector: refactor some reusable functionality from BraceHighlighter
     4        https://bugs.webkit.org/show_bug.cgi?id=109574
     5
     6        Reviewed by Pavel Feldman.
     7
     8        New test: inspector/editor/text-editor-brace-highlighter.html
     9
     10        Extract functionality which, for given line and cursor position, will
     11        return position for a brace that should be highlighted. Add a layout
     12        test to verify brace highlighter funcionality.
     13
     14        * inspector/front-end/DefaultTextEditor.js:
     15        (WebInspector.TextEditorMainPanel.BraceHighlightController.prototype.activeBraceColumnForCursorPosition):
     16        (WebInspector.TextEditorMainPanel.BraceHighlightController.prototype.handleSelectionChange):
     17        * inspector/front-end/TextUtils.js:
     18        (WebInspector.TextUtils.isOpeningBraceChar):
     19        (WebInspector.TextUtils.isClosingBraceChar):
     20        (WebInspector.TextUtils.isBraceChar):
     21
    1222013-02-12  Ilya Tikhonovsky  <loislo@chromium.org>
    223
  • trunk/Source/WebCore/inspector/front-end/DefaultTextEditor.js

    r142597 r142621  
    34053405WebInspector.TextEditorMainPanel.BraceHighlightController.prototype = {
    34063406    /**
     3407     * @param {string} line
     3408     * @param {number} column
     3409     * @return {number}
     3410     */
     3411    activeBraceColumnForCursorPosition: function(line, column)
     3412    {
     3413        var char = line.charAt(column);
     3414        if (WebInspector.TextUtils.isOpeningBraceChar(char))
     3415            return column;
     3416
     3417        var previousChar = line.charAt(column - 1);
     3418        if (WebInspector.TextUtils.isBraceChar(previousChar))
     3419            return column - 1;
     3420
     3421        if (WebInspector.TextUtils.isBraceChar(char))
     3422            return column;
     3423        else
     3424            return -1;
     3425    },
     3426
     3427    /**
    34073428     * @param {WebInspector.TextRange} selectionRange
    34083429     */
     
    34213442        var column = selectionRange.startColumn;
    34223443        var line = this._textModel.line(lineNumber);
    3423         if (column > 0 && WebInspector.TextUtils.isBraceChar(line.charAt(column - 1)))
    3424             --column;
     3444        column = this.activeBraceColumnForCursorPosition(line, column);
     3445        if (column < 0)
     3446            return;
    34253447
    34263448        var enclosingBraces = this._braceMatcher.enclosingBraces(lineNumber, column);
  • trunk/Source/WebCore/inspector/front-end/TextUtils.js

    r142471 r142621  
    7878     * @return {boolean}
    7979     */
     80    isOpeningBraceChar: function(char)
     81    {
     82        return char === "(" || char === "{";
     83    },
     84
     85    /**
     86     * @param {string} char
     87     * @return {boolean}
     88     */
     89    isClosingBraceChar: function(char)
     90    {
     91        return char === ")" || char === "}";
     92    },
     93
     94    /**
     95     * @param {string} char
     96     * @return {boolean}
     97     */
    8098    isBraceChar: function(char)
    8199    {
    82         return char === "(" || char === ")" ||
    83             char === "{" || char === "}";
     100        return WebInspector.TextUtils.isOpeningBraceChar(char) || WebInspector.TextUtils.isClosingBraceChar(char);
    84101    }
    85102}
Note: See TracChangeset for help on using the changeset viewer.