tl;dr: How can I disable a command keybinding while the Command Palette is open?
I'm developing an extension that makes a webview. When the webview is active, I have some commands that can be invoked by a single letter with no modifiers:
"keybindings": [
{
"command": "visual-scxml-editor.toggleEventDisplay",
"key": "e",
"when": "visual-scxml-editor.visualEditorActive"
},
This works well, except that if the user opens the Command Palette they can no longer type those characters.
Per that link, I feel this is a bug. However, I cannot wait for the bug to be fixed. (And, I can imagine a turtles-all-the-way-down argument that requires keybindings to be processed even when the command palette is open and has keyboard focus, such that the behavior won't ever be changed.)
I don't see a when clause context that would allow me to disable this binding when the command palette is open. Are there any events or callbacks or other tricks I can listen for to discover when the command palette is open vs. closed?
The only other workaround I can think of is to not use keybindings at all for such commands, instead processing these keyboard events myself in the webview:
document.body.addEventListener('keydown', evt => {
switch (evt.code) {
case 'KeyE':
this.toggleEventDisplay();
evt.preventDefault();
break;
}
});