Skip to content

Suppress keybindings and filtering during IME composition - #328269

Merged
Logan Ramos (lramos15) merged 2 commits into
mainfrom
lramos15/agents/investigate-issue-318977-fix
Jul 30, 2026
Merged

Logan Ramos (lramos15) merged 2 commits into
mainfrom
lramos15/agents/investigate-issue-318977-fix

Conversation

@lramos15

@lramos15 Logan Ramos (lramos15) commented Jul 30, 2026 •

Copy link
Copy Markdown
Member

Fixes #318977

Typing pinyin into the chat Model Picker search box and pressing Enter to commit the IME composition also accepted the highlighted model and closed the picker.

Root cause

During an IME composition browsers normally report keyCode: 229, which VS Code maps to KeyCode.KEY_IN_COMPOSITION — so equals(KeyCode.Enter) is false and nothing fires. But some platform/IME combinations report the real key code with isComposing: true, and in that case the keystroke reaches the application even though it belongs to the input method.

This isn't specific to the model picker. The same class of bug produced #272407 (macOS Japanese IME: committing a composition also submitted the Create Branch quick input) and #107154 (editor find widget). Each was fixed by adding ContextKeyExpr.not('isComposing') to one keybinding, so before this PR only 5 call sites in the entire codebase were guarded — every other Enter/Space/arrow handler was still exposed.

Fix

Rather than adding a 6th guard, this handles composition at the two points where a keystroke can turn into behavior.

1. Normalize the key code at the source — src/vs/base/browser/keyboardEvent.ts

this.keyCode = e.isComposing ? KeyCode.KEY_IN_COMPOSITION : extractKeyCode(e);

This makes the inconsistent browser behavior look like the consistent one, and gives "the IME owns this keystroke" a single representation — the one the editor already checks for. Because it happens in StandardKeyboardEvent, it fixes equals(), toKeyCodeChord() and the ~237 handlers that compare keyCode directly — including several that a guard on equals() alone would have missed (browserUrlBarWidget, chatInputPart, suggestEnabledInput).

No new members are added to either IKeyboardEvent interface: the normalized keyCode is the signal, so _dispatch and friends simply test keyCode === KeyCode.KEY_IN_COMPOSITION.

2. Make keybinding dispatch agree with itself — src/vs/platform/keybinding/common/abstractKeybindingService.ts

_dispatch, _singleModifierDispatch and softDispatch now apply the same policy. softDispatch matters: callers such as the terminal use it to ask "will the workbench claim this key?", and a yes there followed by a no in _dispatch would drop the keystroke entirely, preventing xterm from handing it to the IME.

3. Remove the now-dead per-command guards (−19 lines)

The 7 pre-existing not('isComposing') clauses in quickInputActions, contextScopedHistoryWidget, rename and findController are redundant: a composing event resolves to KEY_IN_COMPOSITION, matches no keybinding, and never reaches its when clause.

Removing them surfaced a latent bug: the rename and findController guards depended on a context key that only the workbench ever sets, so they were already no-ops in standalone Monaco. Standalone routes through _dispatch, so it now gets protection it never actually had.

The isComposing context key itself is kept — it is user-facing in keybindings.json.

4. Suppress search-as-you-type during composition — src/vs/platform/actionWidget/browser/actionList.ts

Separate from key dispatch: re-filtering on each intermediate input event splices the list and triggers a re-layout, which resizes and repositions the popup underneath the IME candidate window. Filtering now waits for compositionend, mirroring the existing checkImeCompletionState pattern used by the webview/terminal find widgets. Includes dedupe for the trailing input event, since browsers disagree on whether it fires before or after compositionend, and cancels any in-flight dynamic filter on compositionstart so a request issued for the previous value cannot resolve and re-layout mid-composition.

Behavior change worth calling out

Keybindings are suppressed for the whole composition, including modified chords — so Ctrl+S is inert while a composition is active. This is deliberate: isComposing is the browser telling us the IME owns the keystroke, and the risk is asymmetric — a missed Ctrl+S is retried in a second, whereas a spurious Enter creates a branch, sends a prompt or picks the wrong model.

Validation

  • tsc, hygiene, eslint and monaco-typecheck clean
  • 27986 unit tests passing, 0 failing
  • 9 new tests covering key-code normalization, dispatch/softDispatch agreement, and the filter suppression/cancellation
  • No public API change — no interface members were added, so the generated src/vs/monaco.d.ts is byte-identical
  • npm run monaco-compile-check and npm run gulp editor-distro (the Monaco Editor CI checks) pass

Copilot AI review requested due to automatic review settings July 30, 2026 20:24
@vs-code-engineering

Copy link
Copy Markdown
Contributor

📬 CODENOTIFY

The following users are being notified based on files changed in this PR:

TylerLeonhardt

Matched files:

  • src/vs/platform/quickinput/browser/quickInputActions.ts

@lramos15 Logan Ramos (lramos15) changed the title Fix keybinding handling during IME composition for issue #318977 Suppress keybindings and filtering during IME composition Jul 30, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes #318977 by preventing workbench keybindings and model-picker filtering from acting on IME composition keystrokes.

Changes:

  • Normalizes composing events and centrally suppresses keybinding dispatch.
  • Defers action-list filtering until composition commits.
  • Adds IME tests and updates keyboard-event fixtures.
Show a summary per file
File Description
src/vs/base/browser/keyboardEvent.ts Tracks and normalizes composing events.
src/vs/base/test/browser/keyboardEvent.test.ts Tests composition normalization.
src/vs/editor/contrib/find/browser/findController.ts Removes redundant composition guards.
src/vs/editor/contrib/rename/browser/rename.ts Removes redundant composition guards.
src/vs/editor/standalone/test/browser/standaloneServices.test.ts Updates keyboard-event fixture.
src/vs/platform/actionWidget/browser/actionList.ts Defers filtering and guards direct key handling.
src/vs/platform/actionWidget/test/browser/actionList.test.ts Tests deferred IME filtering.
src/vs/platform/history/browser/contextScopedHistoryWidget.ts Removes redundant composition guards.
src/vs/platform/keybinding/common/abstractKeybindingService.ts Suppresses dispatch during composition.
src/vs/platform/keybinding/common/keybinding.ts Adds composition state to keyboard events.
src/vs/platform/keybinding/test/common/abstractKeybindingService.test.ts Tests dispatch suppression.
src/vs/platform/quickinput/browser/quickInputActions.ts Relies on centralized suppression.
src/vs/workbench/services/keybinding/common/macLinuxKeyboardMapper.ts Initializes synthetic event composition state.
src/vs/workbench/services/keybinding/test/node/fallbackKeyboardMapper.test.ts Updates fallback mapper fixtures.
src/vs/workbench/services/keybinding/test/node/macLinuxKeyboardMapper.test.ts Updates macOS/Linux mapper fixtures.
src/vs/workbench/services/keybinding/test/node/windowsKeyboardMapper.test.ts Updates Windows mapper fixtures.

Review details

  • Files reviewed: 16/16 changed files
  • Comments generated: 1
  • Review effort level: Medium

Drop the `isComposing` member from both `IKeyboardEvent` interfaces and rely on
the normalized key code instead.

`StandardKeyboardEvent` already reports `KEY_IN_COMPOSITION` for every composing
keystroke, so a parallel `isComposing` flag was a second source of truth for the
same fact. It also broke the standalone editor build: `@internal` members are
stripped from `out-editor-src`, which left `base`'s interface without the
property while `platform`'s still required it, so the two `IKeyboardEvent` types
stopped being assignable (5 errors in editor-distro).

Using the key code fixes that build, keeps `monaco.d.ts` unchanged, and reverts
the `isComposing: false` churn from the keyboard mapper tests.

Also cancel any in-flight dynamic filter when a composition starts: a request
issued for the previous value could otherwise resolve mid-composition and splice
and re-layout the list underneath the IME candidate window.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: c4ba1417-a152-448b-af4b-1a5017b949e8
@lramos15
Logan Ramos (lramos15) merged commit fa6217e into main Jul 30, 2026
29 checks passed
@lramos15
Logan Ramos (lramos15) deleted the lramos15/agents/investigate-issue-318977-fix branch July 30, 2026 21:24
@vs-code-engineering vs-code-engineering Bot added this to the 1.132.0 milestone Jul 30, 2026
ContextKeyExpr.notEquals(quickInputTypeContextKeyValue, QuickInputType.QuickWidget),
inQuickInputContext,
ContextKeyExpr.not('isComposing')
inQuickInputContext

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was added to fix an IME issue:
#273453

#272407

how do you know this didn't regress?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Chinese IME Compatibility Issues in Model Picker Search

4 participants