Skip to content

Commit

Permalink
reset holdMode when losing window focus (#203368)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken authored Jan 25, 2024
1 parent 3dea5cb commit a87e69f
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/vs/workbench/services/keybinding/browser/keybindingService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -405,10 +402,23 @@ export class WorkbenchKeybindingService extends AbstractKeybindingService {
return undefined;
}
this._keybindingHoldMode = new DeferredPromise<void>();
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;
}
Expand Down

0 comments on commit a87e69f

Please sign in to comment.