VSCode 上下文菜单管理

786 阅读1分钟

实际需求

随着VS Code 安装的插件越来越多,编辑器中的上下文的菜单选项变得臃肿,违背了菜单简单快捷的设计理念,冗长的菜单对笔记本用户不友好,因此开始需要 客制化 上下文菜单。

下图是 gitLens 添加到上下文菜单中的选项。

gitLen添加的菜单选项

实现步骤

  1. 找到扩展安装路径: windows 打开 C:\Users\UserName\.vscode\extensions 文件夹,打开 package.json 文件
  2. 修改 editor/context 选项: 开发插件时,通过编写 editor/context 数组来添加选项到上下文菜单中,因此只要 注释 该选项就行,但 gitLens中还有 gitlens/editor/context/changes 选项需要注释才能去除菜单的 Open Changes 选项。
{
    "name": "gitlens",
    ...
    "contributes":{
        ...
        "menus":{
            "editor/context":[
                {
                    "command": "gitlens.openWorkingFile",
                    "when": "editorTextFocus && config.gitlens.menus.editor.compare && resourceScheme == gitlens",
                    "group": "1_z_gitlens@0"
                },
                {
                    "submenu": "gitlens/editor/context/changes",
                    "when": "editorTextFocus && config.gitlens.menus.editor.compare && isFileSystemResource && resourceScheme =~ /^(?!output$|vscode-(?!remote|vfs$)).*$/",
                    "group": "1_z_gitlens_open@1"
                },
                ...
            ]
        }
    }
}
  1. 针对 剪切/复制/粘贴 等内置选项目前无法修改,之前在 Issue #57930 中提出 Issue,但到目前官方仍未给出有效的解决方案。