Changeset 196746 in webkit


Ignore:
Timestamp:
Feb 17, 2016 10:37:45 PM (8 years ago)
Author:
commit-queue@webkit.org
Message:

Web Inspector: In the styles sidebar, Option-clicking on --css-variable should jump to its definition
https://bugs.webkit.org/show_bug.cgi?id=154082
<rdar://problem/24593361>

Patch by Devin Rousso <Devin Rousso> on 2016-02-17
Reviewed by Timothy Hatcher.

  • UserInterface/Views/CSSStyleDeclarationTextEditor.js:

(WebInspector.CSSStyleDeclarationTextEditor.prototype.tokenTrackingControllerHighlightedRangeWasClicked.showRangeInSourceCode):
(WebInspector.CSSStyleDeclarationTextEditor.prototype.tokenTrackingControllerHighlightedRangeWasClicked):
Now tests to see if the highlighted token was a CSS variable and if
so, attempts to show the declaration of the CSS variable instead of
the location where it is used.

Location:
trunk/Source/WebInspectorUI
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebInspectorUI/ChangeLog

    r196743 r196746  
     12016-02-17  Devin Rousso  <dcrousso+webkit@gmail.com>
     2
     3        Web Inspector: In the styles sidebar, Option-clicking on --css-variable should jump to its definition
     4        https://bugs.webkit.org/show_bug.cgi?id=154082
     5        <rdar://problem/24593361>
     6
     7        Reviewed by Timothy Hatcher.
     8
     9        * UserInterface/Views/CSSStyleDeclarationTextEditor.js:
     10        (WebInspector.CSSStyleDeclarationTextEditor.prototype.tokenTrackingControllerHighlightedRangeWasClicked.showRangeInSourceCode):
     11        (WebInspector.CSSStyleDeclarationTextEditor.prototype.tokenTrackingControllerHighlightedRangeWasClicked):
     12        Now tests to see if the highlighted token was a CSS variable and if
     13        so, attempts to show the declaration of the CSS variable instead of
     14        the location where it is used.
     15
    1162016-02-17  Nikita Vasilyev  <nvasilyev@apple.com>
    217
  • trunk/Source/WebInspectorUI/UserInterface/Views/CSSStyleDeclarationTextEditor.js

    r196184 r196746  
    16231623    tokenTrackingControllerHighlightedRangeWasClicked(tokenTrackingController)
    16241624    {
    1625         console.assert(this._style.ownerRule.sourceCodeLocation);
    1626         if (!this._style.ownerRule.sourceCodeLocation)
    1627             return;
     1625        let sourceCodeLocation = this._style.ownerRule.sourceCodeLocation;
     1626        console.assert(sourceCodeLocation);
     1627        if (!sourceCodeLocation)
     1628            return;
     1629
     1630        let candidate = tokenTrackingController.candidate;
     1631        console.assert(candidate);
     1632        if (!candidate)
     1633            return;
     1634
     1635        let token = candidate.hoveredToken;
    16281636
    16291637        // Special case command clicking url(...) links.
    1630         var token = this._tokenTrackingController.candidate.hoveredToken;
    1631         if (/\blink\b/.test(token.type)) {
    1632             var url = token.string;
    1633             var baseURL = this._style.ownerRule.sourceCodeLocation.sourceCode.url;
     1638        if (token && /\blink\b/.test(token.type)) {
     1639            let url = token.string;
     1640            let baseURL = sourceCodeLocation.sourceCode.url;
    16341641            WebInspector.openURL(absoluteURL(url, baseURL));
    16351642            return;
     1643        }
     1644
     1645        function showRangeInSourceCode(sourceCode, range)
     1646        {
     1647            if (!sourceCode || !range)
     1648                return false;
     1649
     1650            WebInspector.showSourceCodeLocation(sourceCode.createSourceCodeLocation(range.startLine, range.startColumn));
     1651            return true;
     1652        }
     1653
     1654        // Special case option clicking CSS variables.
     1655        if (token && /\bvariable-2\b/.test(token.type)) {
     1656            let property = this._style.nodeStyles.effectivePropertyForName(token.string);
     1657            if (property && showRangeInSourceCode(property.ownerStyle.ownerRule.sourceCodeLocation.sourceCode, property.styleSheetTextRange))
     1658                return;
    16361659        }
    16371660
    16381661        // Jump to the rule if we can't find a property.
    16391662        // Find a better source code location from the property that was clicked.
    1640         var sourceCodeLocation = this._style.ownerRule.sourceCodeLocation;
    1641         var marks = this._codeMirror.findMarksAt(this._tokenTrackingController.candidate.hoveredTokenRange.start);
    1642         for (var i = 0; i < marks.length; ++i) {
    1643             var mark = marks[i];
    1644             var property = mark.__cssProperty;
    1645             if (property) {
    1646                 var sourceCode = sourceCodeLocation.sourceCode;
    1647                 var styleSheetTextRange = property.styleSheetTextRange;
    1648                 sourceCodeLocation = sourceCode.createSourceCodeLocation(styleSheetTextRange.startLine, styleSheetTextRange.startColumn);
    1649             }
    1650         }
    1651 
    1652         WebInspector.showSourceCodeLocation(sourceCodeLocation);
     1663        let marks = this._codeMirror.findMarksAt(candidate.hoveredTokenRange.start);
     1664        for (let mark of marks) {
     1665            let property = mark.__cssProperty;
     1666            if (property && showRangeInSourceCode(sourceCodeLocation.sourceCode, property.styleSheetTextRange))
     1667                return;
     1668        }
    16531669    }
    16541670
Note: See TracChangeset for help on using the changeset viewer.