Changeset 142983 in webkit


Ignore:
Timestamp:
Feb 15, 2013 4:30:27 AM (11 years ago)
Author:
commit-queue@webkit.org
Message:

Web Inspector: implement smart braces functionality
https://bugs.webkit.org/show_bug.cgi?id=109200

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

Source/WebCore:

  • implement SmartBraceController which will handle character insertions

and override them if brace character was inserted. Additionally it
should handle Backspace key and override it if a cursor is located
inside of a bracket pair.

  • guard smart brace functionality via experiment checkbox.

New test: inspector/editor/text-editor-smart-braces.html

  • inspector/front-end/DefaultTextEditor.js:

(WebInspector.TextEditorMainPanel):
(WebInspector.TextEditorMainPanel.prototype._registerShortcuts):
(WebInspector.TextEditorMainPanel.prototype._handleKeyPress):
(WebInspector.TextEditorMainPanel.SmartBraceController):
(WebInspector.TextEditorMainPanel.SmartBraceController.prototype.registerShortcuts):
(WebInspector.TextEditorMainPanel.SmartBraceController.prototype.registerCharOverrides):
(WebInspector.TextEditorMainPanel.SmartBraceController.prototype._handleBackspace):
(WebInspector.TextEditorMainPanel.SmartBraceController.prototype._handleBracePairInsertion):
(WebInspector.TextEditorMainPanel.SmartBraceController.prototype._handleClosingBraceOverride):

  • inspector/front-end/Settings.js:

(WebInspector.ExperimentsSettings):

Tools:

Fix eventSender.keyDown implementation to correctly process opening
round brace symbol.

  • DumpRenderTree/chromium/TestRunner/src/EventSender.cpp:

(WebTestRunner):
(WebTestRunner::EventSender::keyDown):

LayoutTests:

  • inspector/editor/text-editor-smart-braces-expected.txt: Added.
  • inspector/editor/text-editor-smart-braces.html: Added.
  • platform/efl/TestExpectations:
  • platform/mac/TestExpectations:
  • platform/qt/TestExpectations:
Location:
trunk
Files:
2 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r142982 r142983  
     12013-02-15  Andrey Lushnikov  <lushnikov@chromium.org>
     2
     3        Web Inspector: implement smart braces functionality
     4        https://bugs.webkit.org/show_bug.cgi?id=109200
     5
     6        Reviewed by Pavel Feldman.
     7
     8        * inspector/editor/text-editor-smart-braces-expected.txt: Added.
     9        * inspector/editor/text-editor-smart-braces.html: Added.
     10        * platform/efl/TestExpectations:
     11        * platform/mac/TestExpectations:
     12        * platform/qt/TestExpectations:
     13
    1142013-02-15  Andrei Bucur  <abucur@adobe.com>
    215
  • trunk/LayoutTests/platform/efl/TestExpectations

    r142971 r142983  
    18321832inspector/editor/text-editor-word-jumps.html
    18331833inspector/editor/text-editor-home-button.html
     1834inspector/editor/text-editor-smart-braces.html
    18341835
    18351836# Remove from list after enabling CANVAS_PATH
  • trunk/LayoutTests/platform/mac/TestExpectations

    r142982 r142983  
    259259inspector/editor/text-editor-word-jumps.html [ Skip ]
    260260inspector/editor/text-editor-home-button.html [ Skip ]
     261inspector/editor/text-editor-smart-braces.html [ Skip ]
    261262
    262263# https://bugs.webkit.org/show_bug.cgi?id=71120
  • trunk/LayoutTests/platform/qt/TestExpectations

    r142955 r142983  
    26092609inspector/editor/text-editor-word-jumps.html
    26102610inspector/editor/text-editor-home-button.html
     2611inspector/editor/text-editor-smart-braces.html
    26112612
    26122613# [Qt] REGRESSION(r141634) test failing
  • trunk/Source/WebCore/ChangeLog

    r142982 r142983  
     12013-02-15  Andrey Lushnikov  <lushnikov@chromium.org>
     2
     3        Web Inspector: implement smart braces functionality
     4        https://bugs.webkit.org/show_bug.cgi?id=109200
     5
     6        Reviewed by Pavel Feldman.
     7
     8        - implement SmartBraceController which will handle character insertions
     9        and override them if brace character was inserted. Additionally it
     10        should handle Backspace key and override it if a cursor is located
     11        inside of a bracket pair.
     12        - guard smart brace functionality via experiment checkbox.
     13
     14        New test: inspector/editor/text-editor-smart-braces.html
     15
     16        * inspector/front-end/DefaultTextEditor.js:
     17        (WebInspector.TextEditorMainPanel):
     18        (WebInspector.TextEditorMainPanel.prototype._registerShortcuts):
     19        (WebInspector.TextEditorMainPanel.prototype._handleKeyPress):
     20        (WebInspector.TextEditorMainPanel.SmartBraceController):
     21        (WebInspector.TextEditorMainPanel.SmartBraceController.prototype.registerShortcuts):
     22        (WebInspector.TextEditorMainPanel.SmartBraceController.prototype.registerCharOverrides):
     23        (WebInspector.TextEditorMainPanel.SmartBraceController.prototype._handleBackspace):
     24        (WebInspector.TextEditorMainPanel.SmartBraceController.prototype._handleBracePairInsertion):
     25        (WebInspector.TextEditorMainPanel.SmartBraceController.prototype._handleClosingBraceOverride):
     26        * inspector/front-end/Settings.js:
     27        (WebInspector.ExperimentsSettings):
     28
    1292013-02-15  Andrei Bucur  <abucur@adobe.com>
    230
  • trunk/Source/WebCore/inspector/front-end/DefaultTextEditor.js

    r142621 r142983  
    13641364    this.element.addEventListener("textInput", this._handleTextInput.bind(this), false);
    13651365    this.element.addEventListener("cut", this._handleCut.bind(this), false);
     1366    this.element.addEventListener("keypress", this._handleKeyPress.bind(this), false);
    13661367
    13671368    this._showWhitespace = WebInspector.experimentsSettings.showWhitespaceInEditor.isEnabled();
     
    13741375    this._braceMatcher = new WebInspector.TextEditorModel.BraceMatcher(textModel);
    13751376    this._braceHighlighter = new WebInspector.TextEditorMainPanel.BraceHighlightController(this, textModel, this._braceMatcher);
     1377    this._smartBraceController = new WebInspector.TextEditorMainPanel.SmartBraceController(this, textModel, this._braceMatcher);
    13761378
    13771379    this._freeCachedElements();
     
    14131415        this._shortcuts[WebInspector.KeyboardShortcut.makeKey(homeKey.code, homeModifier)] = this._handleHomeKey.bind(this, false);
    14141416        this._shortcuts[WebInspector.KeyboardShortcut.makeKey(homeKey.code, homeModifier | modifiers.Shift)] = this._handleHomeKey.bind(this, true);
     1417
     1418        this._charOverrides = {};
     1419
     1420        this._smartBraceController.registerShortcuts(this._shortcuts);
     1421        this._smartBraceController.registerCharOverrides(this._charOverrides);
     1422    },
     1423
     1424    _handleKeyPress: function(event)
     1425    {
     1426        var char = String.fromCharCode(event.which);
     1427        var handler = this._charOverrides[char];
     1428        if (handler && handler()) {
     1429            event.consume(true);
     1430            return;
     1431        }
     1432        this._keyDownCode = event.keyCode;
    14151433    },
    14161434
     
    34683486}
    34693487
     3488/**
     3489 * @constructor
     3490 * @param {WebInspector.TextEditorMainPanel} mainPanel
     3491 * @param {WebInspector.TextEditorModel} textModel
     3492 * @param {WebInspector.TextEditorModel.BraceMatcher} braceMatcher
     3493 */
     3494WebInspector.TextEditorMainPanel.SmartBraceController = function(mainPanel, textModel, braceMatcher)
     3495{
     3496    this._mainPanel = mainPanel;
     3497    this._textModel = textModel;
     3498    this._braceMatcher = braceMatcher
     3499}
     3500
     3501WebInspector.TextEditorMainPanel.SmartBraceController.prototype = {
     3502    /**
     3503     * @param {Object.<number, function()>} shortcuts
     3504     */
     3505    registerShortcuts: function(shortcuts)
     3506    {
     3507        if (!WebInspector.experimentsSettings.textEditorSmartBraces.isEnabled())
     3508            return;
     3509
     3510        var keys = WebInspector.KeyboardShortcut.Keys;
     3511        var modifiers = WebInspector.KeyboardShortcut.Modifiers;
     3512
     3513        shortcuts[WebInspector.KeyboardShortcut.makeKey(keys.Backspace.code, modifiers.None)] = this._handleBackspace.bind(this);
     3514    },
     3515
     3516    /**
     3517     * @param {Object.<string, function()>} charOverrides
     3518     */
     3519    registerCharOverrides: function(charOverrides)
     3520    {
     3521        if (!WebInspector.experimentsSettings.textEditorSmartBraces.isEnabled())
     3522            return;
     3523        charOverrides["("] = this._handleBracePairInsertion.bind(this, "()");
     3524        charOverrides[")"] = this._handleClosingBraceOverride.bind(this, ")");
     3525        charOverrides["{"] = this._handleBracePairInsertion.bind(this, "{}");
     3526        charOverrides["}"] = this._handleClosingBraceOverride.bind(this, "}");
     3527    },
     3528
     3529    _handleBackspace: function()
     3530    {
     3531        var selection = this._mainPanel.lastSelection();
     3532        if (!selection || !selection.isEmpty())
     3533            return false;
     3534
     3535        var column = selection.startColumn;
     3536        if (column == 0)
     3537            return false;
     3538
     3539        var lineNumber = selection.startLine;
     3540        var line = this._textModel.line(lineNumber);
     3541        if (column === line.length)
     3542            return false;
     3543
     3544        var pair = line.substr(column - 1, 2);
     3545        if (pair === "()" || pair === "{}") {
     3546            this._textModel.editRange(new WebInspector.TextRange(lineNumber, column - 1, lineNumber, column + 1), "");
     3547            this._mainPanel.setSelection(WebInspector.TextRange.createFromLocation(lineNumber, column - 1));
     3548            return true;
     3549        } else
     3550            return false;
     3551    },
     3552
     3553    /**
     3554     * @param {string} bracePair
     3555     * @return {boolean}
     3556     */
     3557    _handleBracePairInsertion: function(bracePair)
     3558    {
     3559        var selection = this._mainPanel.lastSelection().normalize();
     3560        if (selection.isEmpty()) {
     3561            var lineNumber = selection.startLine;
     3562            var column = selection.startColumn;
     3563            var line = this._textModel.line(lineNumber);
     3564            if (column < line.length) {
     3565                var char = line.charAt(column);
     3566                if (WebInspector.TextUtils.isWordChar(char) || (!WebInspector.TextUtils.isBraceChar(char) && WebInspector.TextUtils.isStopChar(char)))
     3567                    return false;
     3568            }
     3569        }
     3570        this._textModel.editRange(selection, bracePair);
     3571        this._mainPanel.setSelection(WebInspector.TextRange.createFromLocation(selection.startLine, selection.startColumn + 1));
     3572        return true;
     3573    },
     3574
     3575    /**
     3576     * @param {string} brace
     3577     * @return {boolean}
     3578     */
     3579    _handleClosingBraceOverride: function(brace)
     3580    {
     3581        var selection = this._mainPanel.lastSelection().normalize();
     3582        if (!selection || !selection.isEmpty())
     3583            return false;
     3584
     3585        var lineNumber = selection.startLine;
     3586        var column = selection.startColumn;
     3587        var line = this._textModel.line(lineNumber);
     3588        if (line.charAt(column) !== brace)
     3589            return false;
     3590
     3591        var braces = this._braceMatcher.enclosingBraces(lineNumber, column);
     3592        if (braces && braces.rightBrace.lineNumber === lineNumber && braces.rightBrace.column === column) {
     3593            this._mainPanel.setSelection(WebInspector.TextRange.createFromLocation(lineNumber, column + 1));
     3594            return true;
     3595        } else
     3596            return false;
     3597    },
     3598}
     3599
    34703600WebInspector.debugDefaultTextEditor = false;
  • trunk/Source/WebCore/inspector/front-end/Settings.js

    r142746 r142983  
    215215    this.horizontalPanelSplit = this._createExperiment("horizontalPanelSplit", "Allow horizontal split in Elements and Sources panels");
    216216    this.showWhitespaceInEditor = this._createExperiment("showWhitespaceInEditor", "Show whitespace characters in editor");
     217    this.textEditorSmartBraces = this._createExperiment("textEditorSmartBraces", "Enable smart braces in text editor");
    217218
    218219    this._cleanUpSetting();
  • trunk/Tools/ChangeLog

    r142973 r142983  
     12013-02-15  Andrey Lushnikov  <lushnikov@chromium.org>
     2
     3        Web Inspector: implement smart braces functionality
     4        https://bugs.webkit.org/show_bug.cgi?id=109200
     5
     6        Reviewed by Pavel Feldman.
     7
     8        Fix eventSender.keyDown implementation to correctly process opening
     9        round brace symbol.
     10
     11        * DumpRenderTree/chromium/TestRunner/src/EventSender.cpp:
     12        (WebTestRunner):
     13        (WebTestRunner::EventSender::keyDown):
     14
    1152013-02-15  Jochen Eisinger  <jochen@chromium.org>
    216
  • trunk/Tools/DumpRenderTree/chromium/TestRunner/src/EventSender.cpp

    r142437 r142983  
    615615            generateChar = true;
    616616        }
     617
     618        if ("(" == codeStr) {
     619            code = '9';
     620            needsShiftKeyModifier = true;
     621        }
    617622    }
    618623
Note: See TracChangeset for help on using the changeset viewer.