Changeset 140828 in webkit


Ignore:
Timestamp:
Jan 25, 2013 8:22:00 AM (11 years ago)
Author:
commit-queue@webkit.org
Message:

Web Inspector: highlight occurences of word in DefaultTextEditor
https://bugs.webkit.org/show_bug.cgi?id=105523

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

Source/WebCore:

Highlight occurrences of selected word in DefaultTextEditor by the means of new highlight regex API.

Test: inspector/editor/text-editor-highlight-token.html

  • inspector/front-end/DefaultTextEditor.js:

(WebInspector.TextEditorMainPanel):
(WebInspector.TextEditorMainPanel.prototype._handleSelectionChange):
(WebInspector.TextEditorMainPanel.TokenHighlighter): Added.
(WebInspector.TextEditorMainPanel.TokenHighlighter.prototype.handleSelectionChange):
(WebInspector.TextEditorMainPanel.TokenHighlighter.prototype._regexString):
(WebInspector.TextEditorMainPanel.TokenHighlighter.prototype._highlight):
(WebInspector.TextEditorMainPanel.TokenHighlighter.prototype._removeHighlight):
(WebInspector.TextEditorMainPanel.TokenHighlighter.prototype._isWord):

  • inspector/front-end/textEditor.css:

(.text-editor-token-highlight):

LayoutTests:

Add new test to verify token highlightning functionality.

  • inspector/editor/editor-test.js:

(initialize_EditorTests.InspectorTest.createTestEditor): Added optional TextEditorDelegate argument.

  • inspector/editor/text-editor-highlight-token-expected.txt: Added.
  • inspector/editor/text-editor-highlight-token.html: Added.
Location:
trunk
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r140827 r140828  
     12013-01-25  Andrey Lushnikov  <lushnikov@chromium.org>
     2
     3        Web Inspector: highlight occurences of word in DefaultTextEditor
     4        https://bugs.webkit.org/show_bug.cgi?id=105523
     5
     6        Reviewed by Pavel Feldman.
     7
     8        Add new test to verify token highlightning functionality.
     9
     10        * inspector/editor/editor-test.js:
     11        (initialize_EditorTests.InspectorTest.createTestEditor): Added optional TextEditorDelegate argument.
     12        * inspector/editor/text-editor-highlight-token-expected.txt: Added.
     13        * inspector/editor/text-editor-highlight-token.html: Added.
     14
    1152013-01-25  Zan Dobersek  <zdobersek@igalia.com>
    216
  • trunk/LayoutTests/inspector/editor/editor-test.js

    r139881 r140828  
    22{
    33
    4 InspectorTest.createTestEditor = function(clientHeight, chunkSize)
     4InspectorTest.createTestEditor = function(clientHeight, chunkSize, textEditorDelegate)
    55{
    66    WebInspector.debugDefaultTextEditor = true;
    7     var textEditor = new WebInspector.DefaultTextEditor("", new WebInspector.TextEditorDelegate());
     7    var textEditor = new WebInspector.DefaultTextEditor("", textEditorDelegate || new WebInspector.TextEditorDelegate());
    88    textEditor.overrideViewportForTest(0, clientHeight || 100, chunkSize || 10);
    99    textEditor.show(WebInspector.inspectorView.element);
  • trunk/Source/WebCore/ChangeLog

    r140825 r140828  
     12013-01-25  Andrey Lushnikov  <lushnikov@chromium.org>
     2
     3        Web Inspector: highlight occurences of word in DefaultTextEditor
     4        https://bugs.webkit.org/show_bug.cgi?id=105523
     5
     6        Reviewed by Pavel Feldman.
     7
     8        Highlight occurrences of selected word in DefaultTextEditor by the means of new highlight regex API.
     9
     10        Test: inspector/editor/text-editor-highlight-token.html
     11
     12        * inspector/front-end/DefaultTextEditor.js:
     13        (WebInspector.TextEditorMainPanel):
     14        (WebInspector.TextEditorMainPanel.prototype._handleSelectionChange):
     15        (WebInspector.TextEditorMainPanel.TokenHighlighter): Added.
     16        (WebInspector.TextEditorMainPanel.TokenHighlighter.prototype.handleSelectionChange):
     17        (WebInspector.TextEditorMainPanel.TokenHighlighter.prototype._regexString):
     18        (WebInspector.TextEditorMainPanel.TokenHighlighter.prototype._highlight):
     19        (WebInspector.TextEditorMainPanel.TokenHighlighter.prototype._removeHighlight):
     20        (WebInspector.TextEditorMainPanel.TokenHighlighter.prototype._isWord):
     21        * inspector/front-end/textEditor.css:
     22        (.text-editor-token-highlight):
     23
    1242013-01-25  Alexander Paschenko  <alexander.pashenko@lge.com>
    225
  • trunk/Source/WebCore/inspector/front-end/DefaultTextEditor.js

    r140691 r140828  
    13631363    this._highlightRegexs = {};
    13641364
     1365    this._tokenHighlighter = new WebInspector.TextEditorMainPanel.TokenHighlighter(this, textModel);
     1366
    13651367    this._freeCachedElements();
    13661368    this.buildChunks();
     
    26232625        if (textRange)
    26242626            this._lastSelection = textRange;
     2627
     2628        this._tokenHighlighter.handleSelectionChange(textRange);
    26252629        this._delegate.selectionChanged(textRange);
    26262630    },
     
    29452949}
    29462950
     2951/**
     2952 * @constructor
     2953 * @param {WebInspector.TextEditorMainPanel} mainPanel
     2954 * @param {WebInspector.TextEditorModel} textModel
     2955 */
     2956WebInspector.TextEditorMainPanel.TokenHighlighter = function(mainPanel, textModel)
     2957{
     2958    this._mainPanel = mainPanel;
     2959    this._textModel = textModel;
     2960}
     2961
     2962WebInspector.TextEditorMainPanel.TokenHighlighter._NonWordCharRegex = /[^a-zA-Z0-9_]/;
     2963WebInspector.TextEditorMainPanel.TokenHighlighter._WordRegex = /^[a-zA-Z0-9_]+$/;
     2964
     2965WebInspector.TextEditorMainPanel.TokenHighlighter.prototype = {
     2966    /**
     2967     * @param {WebInspector.TextRange} range
     2968     */
     2969    handleSelectionChange: function(range)
     2970    {
     2971        if (!range) {
     2972            this._removeHighlight();
     2973            return;
     2974        }
     2975
     2976        if (range.startLine !== range.endLine) {
     2977            this._removeHighlight();
     2978            return;
     2979        }
     2980
     2981        range = range.normalize();
     2982        var selectedText = this._textModel.copyRange(range);
     2983        if (selectedText === this._selectedWord)
     2984            return;
     2985
     2986        if (selectedText === "") {
     2987            this._removeHighlight();
     2988            return;
     2989        }
     2990
     2991        if (this._isWord(range, selectedText))
     2992            this._highlight(selectedText);
     2993        else
     2994            this._removeHighlight();
     2995    },
     2996
     2997    /**
     2998     * @param {string} word
     2999     */
     3000    _regexString: function(word)
     3001    {
     3002        return "\\b" + word + "\\b";
     3003    },
     3004
     3005    /**
     3006     * @param {string} selectedWord
     3007     */
     3008    _highlight: function(selectedWord)
     3009    {
     3010        this._removeHighlight();
     3011        this._selectedWord = selectedWord;
     3012        this._mainPanel.highlightRegex(this._regexString(selectedWord), "text-editor-token-highlight")
     3013    },
     3014
     3015    _removeHighlight: function()
     3016    {
     3017        if (this._selectedWord) {
     3018            this._mainPanel.removeRegexHighlight(this._regexString(this._selectedWord));
     3019            delete this._selectedWord;
     3020        }
     3021    },
     3022
     3023    /**
     3024     * @param {WebInspector.TextRange} range
     3025     * @param {string} selectedText
     3026     * @return {boolean}
     3027     */
     3028    _isWord: function(range, selectedText)
     3029    {
     3030        const NonWordChar = WebInspector.TextEditorMainPanel.TokenHighlighter._NonWordCharRegex;
     3031        const WordRegex = WebInspector.TextEditorMainPanel.TokenHighlighter._WordRegex;
     3032        var line = this._textModel.line(range.startLine);
     3033        var leftBound = range.startColumn === 0 || NonWordChar.test(line.charAt(range.startColumn - 1));
     3034        var rightBound = range.endColumn === line.length - 1 || NonWordChar.test(line.charAt(range.endColumn));
     3035        return leftBound && rightBound && WordRegex.test(selectedText);
     3036    }
     3037}
     3038
    29473039WebInspector.debugDefaultTextEditor = false;
  • trunk/Source/WebCore/inspector/front-end/textEditor.css

    r139980 r140828  
    3636    -webkit-user-select: none;
    3737    z-index: -1;
     38}
     39
     40.text-editor-token-highlight {
     41    -webkit-border-radius: 3px;
     42    border: 1px solid gray;
    3843}
    3944
Note: See TracChangeset for help on using the changeset viewer.