Chrome扩展程序键盘快捷键显示顺序错误

时间:2017-06-12 19:35:54

标签: javascript google-chrome-extension

我正在开发Chrome扩展程序并在本地进行测试。我有一个10个左右的键盘快捷键列表,我在扩展名清单中以标准方式建立如下:

"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"
        }
    }

它们显示在Chrome的扩展程序键盘快捷菜单(chrome:// extensions / configureCommands)中,但是出现意外顺序:

keyboard shortcuts

我怎样才能使它们符合我希望它们的顺序?它们是否应按字母顺序排列?在我添加前面的数字以试图强制我所需的顺序之前,它们似乎仍然与几个版本之前的顺序相同(大致按字母顺序排列)。

1 个答案:

答案 0 :(得分:1)

事实证明,显示的快捷方式的顺序基于清单文件中指定的内部命令名称,而不是描述。这花了我一段时间才意识到,但是如果你看一下变量名,我已经给出了命令并按字母顺序排序,它与截图中的顺序相符。

要解决这个问题,我只需在命令名前加上数字,如下所示:

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

虽然我认为Chrome中的这种行为很愚蠢(它将后端变量名称链接到前端外观),但至少它是可预测的。

我在这里提交了一项功能请求: https://bugs.chromium.org/p/chromium/issues/detail?id=732578