Skip to content

Commit

Permalink
aux window - fix double action registration in title bar part (#202358)
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero authored Jan 12, 2024
1 parent 85afd44 commit ab2a8a0
Showing 1 changed file with 32 additions and 23 deletions.
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

0 comments on commit ab2a8a0

Please sign in to comment.