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

aux window - fix double action registration in title bar part #202358

Merged
merged 1 commit into from
Jan 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
55 changes: 32 additions & 23 deletions src/vs/workbench/browser/parts/titlebar/titlebarPart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { ThemeIcon } from 'vs/base/common/themables';
import { TITLE_BAR_ACTIVE_BACKGROUND, TITLE_BAR_ACTIVE_FOREGROUND, TITLE_BAR_INACTIVE_FOREGROUND, TITLE_BAR_INACTIVE_BACKGROUND, TITLE_BAR_BORDER, WORKBENCH_BACKGROUND } from 'vs/workbench/common/theme';
import { isMacintosh, isWindows, isLinux, isWeb, isNative, platformLocale } from 'vs/base/common/platform';
import { Color } from 'vs/base/common/color';
import { EventType, EventHelper, Dimension, append, $, addDisposableListener, prepend, reset, getWindow, getWindowId, isAncestor } from 'vs/base/browser/dom';
import { EventType, EventHelper, Dimension, append, $, addDisposableListener, prepend, reset, getWindow, getWindowId, isAncestor, getActiveDocument } from 'vs/base/browser/dom';
import { CustomMenubarControl } from 'vs/workbench/browser/parts/titlebar/menubarControl';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { Emitter, Event } from 'vs/base/common/event';
Expand Down Expand Up @@ -88,12 +88,35 @@ export class BrowserTitleService extends MultiWindowParts<BrowserTitlebarPart> i
super('workbench.titleService', themeService, storageService);

this._register(this.registerPart(this.mainPart));

this.registerActions();
}

protected createMainTitlebarPart(): BrowserTitlebarPart {
return this.instantiationService.createInstance(MainBrowserTitlebarPart);
}

private registerActions(): void {

// Focus action
const that = this;
registerAction2(class FocusTitleBar extends Action2 {

constructor() {
super({
id: `workbench.action.focusTitleBar`,
title: localize2('focusTitleBar', 'Focus Title Bar'),
category: Categories.View,
f1: true,
});
}

run(): void {
that.getPartByDocument(getActiveDocument()).focus();
}
});
}

//#region Auxiliary Titlebar Parts

createAuxiliaryTitlebarPart(container: HTMLElement, editorGroupsContainer: IEditorGroupsContainer): IAuxiliaryTitlebarPart {
Expand Down Expand Up @@ -451,28 +474,6 @@ export class BrowserTitlebarPart extends Part implements ITitlebarPart {
}
}

// Focus action
const that = this;
registerAction2(class FocusTitleBar extends Action2 {

constructor() {
super({
id: `workbench.action.focusTitleBar`,
title: localize2('focusTitleBar', 'Focus Title Bar'),
category: Categories.View,
f1: true,
});
}

run(): void {
if (that.customMenubar) {
that.customMenubar.toggleFocus();
} else {
(that.element.querySelector('[tabindex]:not([tabindex="-1"])') as HTMLElement).focus();
}
}
});

this.updateStyles();

return this.element;
Expand Down Expand Up @@ -747,6 +748,14 @@ export class BrowserTitlebarPart extends Part implements ITitlebarPart {
}
}

focus(): void {
if (this.customMenubar) {
this.customMenubar.toggleFocus();
} else {
(this.element.querySelector('[tabindex]:not([tabindex="-1"])') as HTMLElement).focus();
}
}

toJSON(): object {
return {
type: Parts.TITLEBAR_PART
Expand Down