Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there any contexts when specified WebView panel is active in VSCode extension keybinding contribution points?

I saw the when-clause-contexts document but I can't find something like that... Is there any conditions WebView panel is active or alternatives?

I'm now making copy & paste feature in my extension but if when is not specified, some default keybindings may be blocked.

like image 636
henoc Avatar asked Oct 14 '25 08:10

henoc


2 Answers

I believe this new context value is what you need:

New activeWebviewPanelId context key

The new activeWebviewPanelId context key tracks the viewType of the currently focused webview panel. You can use it in when clauses to enable commands or menu items when your webview is focused

"when": "activeWebviewPanelId == 'markdown.preview'"

from v1.71 Release Notes: active webview panel context key

like image 78
Mark Avatar answered Oct 19 '25 13:10

Mark


There is not a generic context key for when a webview is active. However using the setContext command, you can create a custom context that tracks just when one of your webviews is active

Here's what VS code's markdown preview (which also uses a webview) does to create a custom context key that is set when the preview is active:

https://github.com/Microsoft/vscode/blob/cd7c7c5fa2c16c6e8281436c35e9a7709cfbd89d/extensions/markdown-language-features/src/features/previewManager.ts#L152

like image 43
Matt Bierner Avatar answered Oct 19 '25 15:10

Matt Bierner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!