Skip to content

Commit

Permalink
Switching menubar display position failed with error (fix microsoft#2…
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero committed Aug 30, 2024
1 parent 9b75e50 commit adb25cf
Showing 1 changed file with 30 additions and 27 deletions.
57 changes: 30 additions & 27 deletions src/vs/workbench/browser/parts/titlebar/menubarControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,35 @@ export abstract class MenubarControl extends Disposable {
}
}

// This is a bit complex due to the issue https://github.com/microsoft/vscode/issues/205836
let focusMenuBarEmitter: Emitter<void> | undefined = undefined;
function enableFocusMenuBarAction(): Emitter<void> {
if (!focusMenuBarEmitter) {
focusMenuBarEmitter = new Emitter<void>();

registerAction2(class extends Action2 {
constructor() {
super({
id: `workbench.actions.menubar.focus`,
title: localize2('focusMenu', 'Focus Application Menu'),
keybinding: {
primary: KeyMod.Alt | KeyCode.F10,
weight: KeybindingWeight.WorkbenchContrib,
when: IsWebContext
},
f1: true
});
}

async run(): Promise<void> {
focusMenuBarEmitter?.fire();
}
});
}

return focusMenuBarEmitter;
}

export class CustomMenubarControl extends MenubarControl {
private menubar: MenuBar | undefined;
private container: HTMLElement | undefined;
Expand Down Expand Up @@ -417,8 +446,6 @@ export class CustomMenubarControl extends MenubarControl {
});

this.registerListeners();

this.registerActions();
}

protected doUpdateMenubar(firstTime: boolean): void {
Expand All @@ -431,31 +458,6 @@ export class CustomMenubarControl extends MenubarControl {
}
}

private registerActions(): void {
const that = this;

if (isWeb) {
this._register(registerAction2(class extends Action2 {
constructor() {
super({
id: `workbench.actions.menubar.focus`,
title: localize2('focusMenu', 'Focus Application Menu'),
keybinding: {
primary: KeyMod.Alt | KeyCode.F10,
weight: KeybindingWeight.WorkbenchContrib,
when: IsWebContext
},
f1: true
});
}

async run(): Promise<void> {
that.menubar?.toggleFocus();
}
}));
}
}

private getUpdateAction(): IAction | null {
const state = this.updateService.state;

Expand Down Expand Up @@ -808,6 +810,7 @@ export class CustomMenubarControl extends MenubarControl {
}
}));
this._register(this.webNavigationMenu.onDidChange(() => this.updateMenubar()));
this._register(enableFocusMenuBarAction().event(() => this.menubar?.toggleFocus()));
}
}

Expand Down

0 comments on commit adb25cf

Please sign in to comment.