Changeset 145530 in webkit


Ignore:
Timestamp:
Mar 12, 2013 5:15:21 AM (11 years ago)
Author:
commit-queue@webkit.org
Message:

Web Inspector: [CodeMirror] there are bugs in TokenHighlight feature
https://bugs.webkit.org/show_bug.cgi?id=112039

Patch by Andrey Lushnikov <lushnikov@chromium.org> on 2013-03-12
Reviewed by Vsevolod Vlasov.

Fix token highlight in codeMirror experiment

  • rewrite token highlight overlay mode to highlight words, not

substrings

  • add workaround to avoid selection of already selected word

No new tests.

  • inspector/front-end/CodeMirrorTextEditor.js:

(WebInspector.CodeMirrorTextEditor.TokenHighlighter.prototype._cursorChange):
(WebInspector.CodeMirrorTextEditor.TokenHighlighter.prototype._removeHighlight):
(WebInspector.CodeMirrorTextEditor.TokenHighlighter.prototype.nextToken):
(WebInspector.CodeMirrorTextEditor.TokenHighlighter.prototype._addHighlight):

  • inspector/front-end/cm/cmdevtools.css:

(.line-with-selection .cm-column-with-selection):

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r145524 r145530  
     12013-03-12  Andrey Lushnikov  <lushnikov@chromium.org>
     2
     3        Web Inspector: [CodeMirror] there are bugs in TokenHighlight feature
     4        https://bugs.webkit.org/show_bug.cgi?id=112039
     5
     6        Reviewed by Vsevolod Vlasov.
     7
     8        Fix token highlight in codeMirror experiment
     9        - rewrite token highlight overlay mode to highlight words, not
     10        substrings
     11        - add workaround to avoid selection of already selected word
     12
     13        No new tests.
     14
     15        * inspector/front-end/CodeMirrorTextEditor.js:
     16        (WebInspector.CodeMirrorTextEditor.TokenHighlighter.prototype._cursorChange):
     17        (WebInspector.CodeMirrorTextEditor.TokenHighlighter.prototype._removeHighlight):
     18        (WebInspector.CodeMirrorTextEditor.TokenHighlighter.prototype.nextToken):
     19        (WebInspector.CodeMirrorTextEditor.TokenHighlighter.prototype._addHighlight):
     20        * inspector/front-end/cm/cmdevtools.css:
     21        (.line-with-selection .cm-column-with-selection):
     22
    1232013-03-12  Sheriff Bot  <webkit.review.bot@gmail.com>
    224
  • trunk/Source/WebCore/inspector/front-end/CodeMirrorTextEditor.js

    r145520 r145530  
    442442        var selectedText = this._codeMirror.getSelection();
    443443        if (this._isWord(selectedText, selectionStart.line, selectionStart.ch, selectionEnd.ch))
    444             this._codeMirror.operation(this._addHighlight.bind(this, selectedText));
     444            this._codeMirror.operation(this._addHighlight.bind(this, selectedText, selectionStart));
    445445    },
    446446
     
    455455    _removeHighlight: function()
    456456    {
    457         if (this._overlayMode) {
    458             this._codeMirror.removeOverlay(this._overlayMode);
    459             delete this._overlayMode;
     457        if (this._highlightDescriptor) {
     458            this._codeMirror.removeOverlay(this._highlightDescriptor.overlay);
     459            this._codeMirror.removeLineClass(this._highlightDescriptor.selectionStart.line, "wrap", "cm-line-with-selection");
     460            delete this._highlightDescriptor;
    460461        }
    461462    },
    462463
    463     _addHighlight: function(token)
     464    _addHighlight: function(token, selectionStart)
    464465    {
    465466        const tokenFirstChar = token.charAt(0);
    466467        function nextToken(stream)
    467468        {
    468             if (stream.match(token))
    469                 return "token-highlight";
    470             stream.next();
    471             if (!stream.skipTo(tokenFirstChar))
    472                 stream.skipToEnd();
     469            if (stream.match(token) && (stream.eol() || !WebInspector.TextUtils.isWordChar(stream.peek())))
     470                return stream.column() === selectionStart.ch ? "token-highlight column-with-selection" : "token-highlight";
     471
     472            var eatenChar;
     473            do {
     474                eatenChar = stream.next();
     475            } while (eatenChar && (WebInspector.TextUtils.isWordChar(eatenChar) || stream.peek() !== tokenFirstChar));
    473476        }
    474477
    475         this._overlayMode = {
     478        var overlayMode = {
    476479            token: nextToken
    477480        };
    478         this._codeMirror.addOverlay(this._overlayMode);
     481        this._codeMirror.addOverlay(overlayMode);
     482        this._codeMirror.addLineClass(selectionStart.line, "wrap", "cm-line-with-selection")
     483        this._highlightDescriptor = {
     484            overlay: overlayMode,
     485            selectionStart: selectionStart
     486        };
    479487    }
    480488}
  • trunk/Source/WebCore/inspector/front-end/cm/cmdevtools.css

    r145520 r145530  
    5757}
    5858
     59.cm-line-with-selection .cm-column-with-selection {
     60    border: 0px;
     61    margin: 0px;
     62}
     63
    5964.cm-s-web-inspector-js span.cm-keyword {color: rgb(170, 13, 145);}
    6065.cm-s-web-inspector-js span.cm-number {color: rgb(28, 0, 207);}
Note: See TracChangeset for help on using the changeset viewer.