Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switching menubar display position failed with error (fix #205836) #227242

Merged
merged 1 commit into from
Aug 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading