Changeset 259929 in webkit


Ignore:
Timestamp:
Apr 11, 2020 8:14:34 AM (4 years ago)
Author:
Devin Rousso
Message:

Web Inspector: CSS: variables should have a go-to arrow to quickly jump to the definition
https://bugs.webkit.org/show_bug.cgi?id=195775
<rdar://problem/48905785>

Reviewed by Timothy Hatcher.

Often when debugging/editing styles that use CSS variables, the desired workflow is to
modify the variable itself, not that specific usage. This is especially helpful when editing
colors saved in CSS variables.

Add an always visible go-to arrow immediately after the variable (e.g. --XYZ (->)) that
will jump to the declaration of the variable elsewhere in the style cascade.

  • UserInterface/Views/SpreadsheetStyleProperty.js:

(WI.SpreadsheetStyleProperty.prototype._addVariableTokens):

  • UserInterface/Views/SpreadsheetCSSStyleDeclarationEditor.css:

(.spreadsheet-style-declaration-editor .property .select-variable-property): Added.

  • UserInterface/Base/Setting.js:
  • UserInterface/Views/SettingsTabContentView.js:

(WI.SettingsTabContentView.prototype._createExperimentalSettingsView):

  • Localizations/en.lproj/localizedStrings.js:
Location:
trunk/Source/WebInspectorUI
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebInspectorUI/ChangeLog

    r259842 r259929  
     12020-04-11  Devin Rousso  <drousso@apple.com>
     2
     3        Web Inspector: CSS: variables should have a go-to arrow to quickly jump to the definition
     4        https://bugs.webkit.org/show_bug.cgi?id=195775
     5        <rdar://problem/48905785>
     6
     7        Reviewed by Timothy Hatcher.
     8
     9        Often when debugging/editing styles that use CSS variables, the desired workflow is to
     10        modify the variable itself, not that specific usage. This is especially helpful when editing
     11        colors saved in CSS variables.
     12
     13        Add an always visible go-to arrow immediately after the variable (e.g. `--XYZ (->)`) that
     14        will jump to the declaration of the variable elsewhere in the style cascade.
     15
     16        * UserInterface/Views/SpreadsheetStyleProperty.js:
     17        (WI.SpreadsheetStyleProperty.prototype._addVariableTokens):
     18        * UserInterface/Views/SpreadsheetCSSStyleDeclarationEditor.css:
     19        (.spreadsheet-style-declaration-editor .property .select-variable-property): Added.
     20
     21        * UserInterface/Base/Setting.js:
     22        * UserInterface/Views/SettingsTabContentView.js:
     23        (WI.SettingsTabContentView.prototype._createExperimentalSettingsView):
     24
     25        * Localizations/en.lproj/localizedStrings.js:
     26
    1272020-04-09  Devin Rousso  <drousso@apple.com>
    228
  • trunk/Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js

    r259748 r259929  
    619619localizedStrings["Global Search From Selection @ Settings"] = "%s from selection";
    620620localizedStrings["Global Variables"] = "Global Variables";
     621localizedStrings["Go to variable"] = "Go to variable";
    621622localizedStrings["Grammar"] = "Grammar";
    622623/* Name of Graphics Tab */
     
    11231124localizedStrings["Show Console tab"] = "Show Console tab";
    11241125localizedStrings["Show Elements"] = "Show Elements";
    1125 localizedStrings["Show Jump to Effective Property Button"] = "Show Jump to Effective Property Button";
    11261126localizedStrings["Show Path"] = "Show Path";
    11271127localizedStrings["Show Remaining (%d)"] = "Show Remaining (%d)";
     
    11321132localizedStrings["Show full certificate"] = "Show full certificate";
    11331133localizedStrings["Show hidden tabs"] = "Show hidden tabs";
     1134localizedStrings["Show jump to effective property button"] = "Show jump to effective property button";
     1135localizedStrings["Show jump to variable declaration button"] = "Show jump to variable declaration button";
    11341136localizedStrings["Show only for selected node"] = "Show only for selected node";
    11351137localizedStrings["Show page rulers and node border lines"] = "Show page rulers and node border lines";
  • trunk/Source/WebInspectorUI/UserInterface/Base/Setting.js

    r259748 r259929  
    221221    experimentalEnablePreviewFeatures: new WI.Setting("experimental-enable-preview-features", true),
    222222    experimentalEnableStylesJumpToEffective: new WI.Setting("experimental-styles-jump-to-effective", false),
     223    experimentalEnableStyelsJumpToVariableDeclaration: new WI.Setting("experimental-styles-jump-to-variable-declaration", false),
    223224
    224225    // Protocol
  • trunk/Source/WebInspectorUI/UserInterface/Views/SettingsTabContentView.js

    r259748 r259929  
    370370    _createExperimentalSettingsView()
    371371    {
     372        let canShowPreviewFeatures = WI.canShowPreviewFeatures();
     373        let hasCSSDomain = InspectorBackend.hasDomain("CSS");
     374        if (!canShowPreviewFeatures && !hasCSSDomain)
     375            return;
     376
    372377        let experimentalSettingsView = new WI.SettingsView("experimental", WI.UIString("Experimental"));
    373378
    374379        let initialValues = new Map;
    375380
    376         if (WI.canShowPreviewFeatures()) {
     381        if (canShowPreviewFeatures) {
    377382            experimentalSettingsView.addSetting(WI.UIString("Staging:"), WI.settings.experimentalEnablePreviewFeatures, WI.UIString("Enable Preview Features"));
    378383            experimentalSettingsView.addSeparator();
    379384        }
    380385
    381         if (InspectorBackend.hasDomain("CSS")) {
     386        if (hasCSSDomain) {
    382387            let stylesGroup = experimentalSettingsView.addGroup(WI.UIString("Styles:"));
    383             stylesGroup.addSetting(WI.settings.experimentalEnableStylesJumpToEffective, WI.UIString("Show Jump to Effective Property Button"));
     388            stylesGroup.addSetting(WI.settings.experimentalEnableStylesJumpToEffective, WI.UIString("Show jump to effective property button"));
     389            stylesGroup.addSetting(WI.settings.experimentalEnableStyelsJumpToVariableDeclaration, WI.UIString("Show jump to variable declaration button"));
     390
    384391            experimentalSettingsView.addSeparator();
    385392        }
     
    403410        listenForChange(WI.settings.experimentalEnablePreviewFeatures);
    404411
    405         if (InspectorBackend.hasDomain("CSS"))
     412        if (hasCSSDomain) {
    406413            listenForChange(WI.settings.experimentalEnableStylesJumpToEffective);
     414            listenForChange(WI.settings.experimentalEnableStyelsJumpToVariableDeclaration);
     415        }
    407416
    408417        this._createReferenceLink(experimentalSettingsView);
  • trunk/Source/WebInspectorUI/UserInterface/Views/SpreadsheetCSSStyleDeclarationEditor.css

    r253405 r259929  
    195195}
    196196
     197.spreadsheet-style-declaration-editor .property .select-variable-property {
     198    display: inline-block;
     199    width: 10px;
     200    height: 10px;
     201    -webkit-margin-start: 2px;
     202    vertical-align: -1px;
     203    cursor: pointer;
     204}
     205
    197206.spreadsheet-style-declaration-editor .property .select-effective-property {
    198207    display: none;
  • trunk/Source/WebInspectorUI/UserInterface/Views/SpreadsheetStyleProperty.js

    r259170 r259929  
    784784                let variableNameIndex = rawTokens.findIndex((token) => token.value.startsWith("--") && /\bvariable-2\b/.test(token.type));
    785785                if (variableNameIndex !== -1) {
    786                     let contents = [];
     786                    let contents = rawTokens.slice(0, variableNameIndex + 1);
     787
     788                    if (WI.settings.experimentalEnableStyelsJumpToVariableDeclaration.value && this._property.ownerStyle.type !== WI.CSSStyleDeclaration.Type.Computed && this._delegate && this._delegate.spreadsheetStylePropertySelectByProperty) {
     789                        const dontCreateIfMissing = true;
     790                        let effectiveVariableProperty = this._property.ownerStyle.nodeStyles.effectivePropertyForName(rawTokens[variableNameIndex].value, dontCreateIfMissing);
     791                        if (effectiveVariableProperty) {
     792                            let arrowElement = WI.createGoToArrowButton();
     793                            arrowElement.classList.add("select-variable-property");
     794                            arrowElement.title = WI.UIString("Go to variable");
     795                            arrowElement.addEventListener("click", (event) => {
     796                                event.stop();
     797                                this._delegate.spreadsheetStylePropertySelectByProperty(effectiveVariableProperty);
     798                            });
     799                            contents.push(arrowElement);
     800                        }
     801                    }
     802
    787803                    let fallbackStartIndex = rawTokens.findIndex((value, i) => i > variableNameIndex + 1 && /\bm-css\b/.test(value.type));
    788804                    if (fallbackStartIndex !== -1) {
    789                         contents.pushAll(rawTokens.slice(0, fallbackStartIndex));
     805                        contents.pushAll(rawTokens.slice(variableNameIndex + 1, fallbackStartIndex));
    790806                        contents.pushAll(this._replaceSpecialTokens(rawTokens.slice(fallbackStartIndex, i)));
    791807                    } else
    792                         contents.pushAll(rawTokens.slice(0, i));
     808                        contents.pushAll(rawTokens.slice(variableNameIndex + 1, i));
    793809                    contents.push(token);
    794810
Note: See TracChangeset for help on using the changeset viewer.