-
Notifications
You must be signed in to change notification settings - Fork 34.1k
Description
Test for #54285
- Mac @aeschli
- Linux @karthiknadig
- Windows @justschen
Complexity: 5
Summary
#54285 introduces a new contribution point for context menus on webviews. These menus can also use when
clauses that control when they are shown or hidden
"webview/context": [
{
"command": "gitlens.showSettingsPage",
"when": "webview == 'gitlens.welcome'"
}
],
The contents of the webview can change the when clauses by setting data-vscode-context
with json values of the new context. For example, if I right click inside of nav
with the following html:
<div class="menu" data-vscode-context='{"webviewSection": "menu", "countOfThing": 123}'>
...
<div class="nav" data-vscode-context='{"webviewSection": "nav", "preventDefaultContextMenuItems": true}'>
...
</div>
</div>
The set contexts would be:
webviewSection
="nav"
(overrides the value from the. menu
element)countOfThing
=123
(inherited from the parent.menu
element)preventDefaultContextMenuItems
=true
The preventDefaultContextMenuItems
context should prevent the default context menu items from showing up (copy, paste, ...)
Testing
Using the webview extension sample, try testing:
-
Context menus only show up if you set:
"enabledApiProposals": [ "contribWebviewContext" ],
-
You can register webview context menu items and use
webview == 'catCoding'
to register a new menu. For example:"contributes": { "menus": { "webview/context": [ { "command": "catCoding.doRefactor", "when": "webview == 'catCoding'" } ] },
-
Your html can suppress the default context menu items using
preventDefaultContextMenuItems
withdata-vscode-context
(see above) -
Your html can set custom context using
data-vscode-context
-
Any set contexts should override contexts set by parent element (the above example shows this for
webviewSection
)