microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
164.41k stars 29.33k forks source link

Unmodified key binding intercepts typing in Command Palette #175485

Closed Phrogz closed 1 year ago

Phrogz commented 1 year ago

Does this issue occur when all extensions are disabled?: Yes

Steps to Reproduce:

  1. Preferences: Open Keyboard Shortcuts
  2. Modify a command to have a keyboard shortcut of Q
  3. Open the command palette (ctrl+shift+p or cmd+shift+p)
  4. Type the letters q and then u

EXPECTED: the text qu is shown in the command palette.
ACTUAL: only the text u is shown in the command palette.

I am writing an extension with a webview where I want to expose certain frequently-used commands using unmodified characters like q as the keybinding. The when clause only activates this binding when my webview is active; however, if I open the command palette when the webview is active I cannot type certain letters, as they invoke the command.

I believe the Command palette should be receiving key events when open and using stopPropagation() to prevent them from triggering commands.

The problem exists even in the latest Insiders build:

Version: 1.76.0-insider (Universal)
Commit: ead95b4a7014d12ddcb2dd6ddcb16e73f1e4cd67
Date: 2023-02-24T22:01:16.601Z
Electron: 19.1.10
Chromium: 102.0.5005.196
Node.js: 16.14.2
V8: 10.2.154.26-electron.0
OS: Darwin x64 20.6.0
Sandboxed: Yes
Phrogz commented 1 year ago

I apologize for the noise. I just discovered that the inputFocus context allows me to detect when the Command Palette is focused, and disable my keybinding:

"keybindings": [
    {
      "command": "visual-scxml-editor.toggleEventDisplay",
      "key": "e",
      "when": "visual-scxml-editor.visualEditorActive && !inputFocs"
    },

This seems like a sufficiently-elegant solution to an edge-case problem, that I'm withdrawing this as a bug report.