如何在Visual Studio Code中自定义上下文菜单? [英] How to customize context menu in Visual Studio Code?
问题描述
是否可以在Visual Studio Code中自定义上下文菜单?
当前看起来像这样。
我需要为此添加两个菜单选项。
类似后退和前进。
可以做到吗?
是的,扩展程序可以将菜单项添加到上下文菜单:在 package.json
中,添加
Is it possible to customize context menu in Visual Studio Code ?
Currently it looks like this.
I need to add two more menu options to this.
Something like "Go Back" and "Go Forward".
Can this be done ?
Yes, an extension can add menu items to the context menu: in package.json
, add a contributes.menus
section. The text editor context menu is called editor/context
.
An example of an extension that does this is Bookmarks, which adds three context menu entries. The relevant parts of its package.json
are:
{
"name": "Bookmarks",
...
"contributes": {
...
"menus": {
...
"editor/context": [
{
"command": "bookmarks.toggle",
"group": "bookmarks",
"when": "editorTextFocus && config.bookmarks.showCommandsInContextMenu"
},
{
"command": "bookmarks.jumpToNext",
"group": "bookmarks@1",
"when": "editorTextFocus && config.bookmarks.showCommandsInContextMenu"
},
{
"command": "bookmarks.jumpToPrevious",
"group": "bookmarks@1",
"when": "editorTextFocus && config.bookmarks.showCommandsInContextMenu"
}
],
....
},
....
},
....
}
The API docs are a bit vague about the meaning of the group
attribute:
Last, a
group
property defines sorting and grouping of menu items.
Its meaning is described more fully under Sorting of groups. A word like "bookmarks" establishes a group of menu entries separated from other groups by a horizontal rule, with groups ordered alphabetically, and the "@<number>" suffix controls ordering within each group:
这篇关于如何在Visual Studio Code中自定义上下文菜单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!