V. Rubinetti
V. Rubinetti

Reputation: 1766

Chrome extension keyboard shortcuts showing in wrong order

I'm developing a Chrome extension and testing it locally. I have a list of 10 or so keyboard shortcuts that I am establishing in the standard way in the extension's manifest as follows:

"commands":
    {
        "mute-all":
        {
            "description": "1 - Toggle \"Mute All Tabs\"",
            "suggested_key":
            {
                "default": "Ctrl+Shift+A",
                "mac": "Command+Shift+A"
            }
        },
        "unmute-all":
        {
            "description": "2 - Toggle \"Unmute All Tabs\"",
            "suggested_key":
            {
                "default": "Ctrl+Shift+Z",
                "mac": "Command+Shift+Z"
            }
        },
        "unmute-current":
        {
            "description": "3 - Toggle \"Always unmute current tab\"",
            "suggested_key":
            {
                "default": "Ctrl+Shift+S",
                "mac": "Command+Shift+S"
            }
        },
        "mute-others":
        {
            "description": "4 - Toggle \"Always mute all other tabs\"", 
            "suggested_key":
            {
                "default": "Ctrl+Shift+X",
                "mac": "Command+Shift+X"
            }
        },
        "use-black-list":
        {
            "description": "5 - Toggle \"Use Black/White List\""
        },
        "viewed-list":
        {
            "description": "6 - Aoggle viewed list"
        },
        "add-domain":
        {
            "description": "7 - Add domain to viewed list"
        },
        "remove-domain":
        {
            "description": "8 - Remove domain from viewed list"
        },
        "add-page":
        {
            "description": "9 - Add page to viewed list"
        },
        "remove-page":
        {
            "description": "10 - Remove page from viewed list"
        },
        "manual-override":
        {
            "description": "11 - Toggle manual override un/mute for current tab"
        }
    }

They show up in Chrome's extension keyboard shortcut menu (chrome://extensions/configureCommands), but in an unexpected order:

keyboard shortcuts

How can I get them to be in the order I want them to be in? Should they not be in alphabetical order of their descriptions? They seem to still be in the same order as they were several builds ago (roughly alphabetical by description) before I added the preceding numbers to try to force my desired order.

Upvotes: 2

Views: 281

Answers (1)

V. Rubinetti
V. Rubinetti

Reputation: 1766

It turns out, the order of the displayed shortcuts is based on the internal command name specified in the manifest file, not the description. This took me a while to realize, but if you look at the variable names I've given the commands and sort them alphabetically, it matches the order in the screenshot.

To solve this I've simply preceded the command names with numbers as follows:

"01-mute-all":
{ ... },
"02-unmute-all":
{ ... },
"03-unmute-current":
{ ... },
"04-mute-others":
{ ... },
etc.

While I think this behavior in Chrome is stupid (it links back-end variable names to front-end appearance), at least it is predictable.

I've submitted a feature request here: https://bugs.chromium.org/p/chromium/issues/detail?id=732578

Upvotes: 1

Related Questions