实际需求
随着VS Code 安装的插件越来越多,编辑器中的上下文的菜单选项变得臃肿,违背了菜单简单快捷的设计理念,冗长的菜单对笔记本用户不友好,因此开始需要 客制化 上下文菜单。
下图是 gitLens 添加到上下文菜单中的选项。
实现步骤
- 找到扩展安装路径: windows 打开
C:\Users\UserName\.vscode\extensions文件夹,打开package.json文件 - 修改
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"
},
...
]
}
}
}
- 针对
剪切/复制/粘贴等内置选项目前无法修改,之前在 Issue #57930 中提出 Issue,但到目前官方仍未给出有效的解决方案。