Changeset 156728 in webkit


Ignore:
Timestamp:
Oct 1, 2013 12:55:21 PM (10 years ago)
Author:
Antoine Quint
Message:

Web Inspector: evaluate and show a popover for selected text in JS source when paused
https://bugs.webkit.org/show_bug.cgi?id=122151

Reviewed by Joseph Pecoraro.

Identify if the hovered token is contained within the text selection (if any) and use
the selection as the hovered expression to allow the user to select text and hover it
to see what it evaluates to.

  • UserInterface/CodeMirrorTokenTrackingController.js:

(WebInspector.CodeMirrorTokenTrackingController.prototype.highlightRange):
Check we're trying to highlight a different range before removing the highlight
and applying the new one, this prevents the marked text from flashing if it's
being re-hovered which would easily happen when hovering multiple tokens within
the same selection.

(WebInspector.CodeMirrorTokenTrackingController.prototype._processJavaScriptExpression):
In the case where there is selected text, check whether the hovered token is at least
partially contained within the selection, and if so use the selection text as the
hovered expression to evaluate.

Location:
trunk/Source/WebInspectorUI
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebInspectorUI/ChangeLog

    r156727 r156728  
     12013-10-01  Antoine Quint  <graouts@apple.com>
     2
     3        Web Inspector: evaluate and show a popover for selected text in JS source when paused
     4        https://bugs.webkit.org/show_bug.cgi?id=122151
     5
     6        Reviewed by Joseph Pecoraro.
     7
     8        Identify if the hovered token is contained within the text selection (if any) and use
     9        the selection as the hovered expression to allow the user to select text and hover it
     10        to see what it evaluates to.
     11
     12        * UserInterface/CodeMirrorTokenTrackingController.js:
     13        (WebInspector.CodeMirrorTokenTrackingController.prototype.highlightRange):
     14        Check we're trying to highlight a different range before removing the highlight
     15        and applying the new one, this prevents the marked text from flashing if it's
     16        being re-hovered which would easily happen when hovering multiple tokens within
     17        the same selection.
     18
     19        (WebInspector.CodeMirrorTokenTrackingController.prototype._processJavaScriptExpression):
     20        In the case where there is selected text, check whether the hovered token is at least
     21        partially contained within the selection, and if so use the selection text as the
     22        hovered expression to evaluate.
     23
    1242013-10-01  Antoine Quint  <graouts@apple.com>
    225
  • trunk/Source/WebInspectorUI/UserInterface/CodeMirrorTokenTrackingController.js

    r151453 r156728  
    160160    highlightRange: function(range)
    161161    {
     162        // Nothing to do if we're trying to highlight the same range.
     163        if (this._codeMirrorMarkedText && this._codeMirrorMarkedText.className === this._classNameForHighlightedRange) {
     164            var highlightedRange = this._codeMirrorMarkedText.find();
     165            if (WebInspector.compareCodeMirrorPositions(highlightedRange.from, range.start) === 0 &&
     166                WebInspector.compareCodeMirrorPositions(highlightedRange.to, range.end) === 0)
     167                return;
     168        }
     169
    162170        this.removeHighlightedRange();
    163171
     
    361369            return null;
    362370
     371        var startPosition = {line: this._hoveredTokenInfo.position.line, ch: this._hoveredTokenInfo.token.start};
     372        var endPosition = {line: this._hoveredTokenInfo.position.line, ch: this._hoveredTokenInfo.token.end};
     373
     374        // If the hovered token is within a selection, use the selection as our expression.
     375        if (this._codeMirror.somethingSelected()) {
     376            var selectionRange = {
     377                start: this._codeMirror.getCursor("start"),
     378                end: this._codeMirror.getCursor("end")
     379            };
     380       
     381            function tokenIsInRange(token, range)
     382            {
     383                return token.line >= range.start.line && token.ch >= range.start.ch &&
     384                       token.line <= range.end.line && token.ch <= range.end.ch;
     385            }
     386       
     387            if (tokenIsInRange(startPosition, selectionRange) || tokenIsInRange(endPosition, selectionRange)) {
     388                return {
     389                    hoveredToken: this._hoveredTokenInfo.token,
     390                    hoveredTokenRange: selectionRange,
     391                    expression: this._codeMirror.getSelection(),
     392                    expressionRange: selectionRange,
     393                };
     394            }
     395        }
     396
    363397        // We only handle vars, definitions, properties, and the keyword 'this'.
    364398        var type = this._hoveredTokenInfo.token.type;
     
    380414        var expression = this._hoveredTokenInfo.token.string;
    381415        var expressionStartPosition = {line: this._hoveredTokenInfo.position.line, ch: this._hoveredTokenInfo.token.start};
    382         var startPosition = {line: this._hoveredTokenInfo.position.line, ch: this._hoveredTokenInfo.token.start};
    383         var endPosition = {line: this._hoveredTokenInfo.position.line, ch: this._hoveredTokenInfo.token.end};
    384416        while (true) {
    385417            var token = this._codeMirror.getTokenAt(expressionStartPosition);
Note: See TracChangeset for help on using the changeset viewer.