diff --git a/src/vs/workbench/services/keybinding/browser/keybindingService.ts b/src/vs/workbench/services/keybinding/browser/keybindingService.ts index 1345094497c66..708268ba3c3d2 100644 --- a/src/vs/workbench/services/keybinding/browser/keybindingService.ts +++ b/src/vs/workbench/services/keybinding/browser/keybindingService.ts @@ -287,10 +287,7 @@ export class WorkbenchKeybindingService extends AbstractKeybindingService { // for single modifier chord keybindings (e.g. shift shift) disposables.add(dom.addDisposableListener(window, dom.EventType.KEY_UP, (e: KeyboardEvent) => { - if (this._keybindingHoldMode) { - this._keybindingHoldMode.complete(); - this._keybindingHoldMode = null; - } + this._resetKeybindingHoldMode(); this.isComposingGlobalContextKey.set(e.isComposing); const keyEvent = new StandardKeyboardEvent(e); const shouldPreventDefault = this._singleModifierDispatch(keyEvent, keyEvent.target); @@ -405,10 +402,23 @@ export class WorkbenchKeybindingService extends AbstractKeybindingService { return undefined; } this._keybindingHoldMode = new DeferredPromise(); + const focusTracker = dom.trackFocus(dom.getWindow(undefined)); + const listener = focusTracker.onDidBlur(() => this._resetKeybindingHoldMode()); + this._keybindingHoldMode.p.finally(() => { + listener.dispose(); + focusTracker.dispose(); + }); this._log(`+ Enabled hold-mode for ${commandId}.`); return this._keybindingHoldMode.p; } + private _resetKeybindingHoldMode(): void { + if (this._keybindingHoldMode) { + this._keybindingHoldMode?.complete(); + this._keybindingHoldMode = null; + } + } + public override customKeybindingsCount(): number { return this.userKeybindings.keybindings.length; }