Skip to content

Commit 9ed28b5

Browse files
authored
Fix Activity Bar Position Bottom with Menu (microsoft#208767)
fix microsoft#207242
1 parent 9fcefcb commit 9ed28b5

File tree

3 files changed

+41
-18
lines changed

3 files changed

+41
-18
lines changed

src/vs/base/browser/ui/menu/menu.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,21 @@ export const MENU_ESCAPED_MNEMONIC_REGEX = /(&)?(&)([^\s&])/g;
3131

3232

3333

34-
export enum Direction {
34+
export enum HorizontalDirection {
3535
Right,
3636
Left
3737
}
3838

39+
export enum VerticalDirection {
40+
Above,
41+
Below
42+
}
43+
44+
export interface IMenuDirection {
45+
horizontal: HorizontalDirection;
46+
vertical: VerticalDirection;
47+
}
48+
3949
export interface IMenuOptions {
4050
context?: unknown;
4151
actionViewItemProvider?: IActionViewItemProvider;
@@ -44,7 +54,7 @@ export interface IMenuOptions {
4454
ariaLabel?: string;
4555
enableMnemonics?: boolean;
4656
anchorAlignment?: AnchorAlignment;
47-
expandDirection?: Direction;
57+
expandDirection?: IMenuDirection;
4858
useEventAsContext?: boolean;
4959
submenuIds?: Set<string>;
5060
}
@@ -725,7 +735,7 @@ class SubmenuMenuActionViewItem extends BaseMenuActionViewItem {
725735
private mouseOver: boolean = false;
726736
private showScheduler: RunOnceScheduler;
727737
private hideScheduler: RunOnceScheduler;
728-
private expandDirection: Direction;
738+
private expandDirection: IMenuDirection;
729739

730740
constructor(
731741
action: IAction,
@@ -736,7 +746,7 @@ class SubmenuMenuActionViewItem extends BaseMenuActionViewItem {
736746
) {
737747
super(action, action, submenuOptions, menuStyles);
738748

739-
this.expandDirection = submenuOptions && submenuOptions.expandDirection !== undefined ? submenuOptions.expandDirection : Direction.Right;
749+
this.expandDirection = submenuOptions && submenuOptions.expandDirection !== undefined ? submenuOptions.expandDirection : { horizontal: HorizontalDirection.Right, vertical: VerticalDirection.Below };
740750

741751
this.showScheduler = new RunOnceScheduler(() => {
742752
if (this.mouseOver) {
@@ -850,11 +860,11 @@ class SubmenuMenuActionViewItem extends BaseMenuActionViewItem {
850860
}
851861
}
852862

853-
private calculateSubmenuMenuLayout(windowDimensions: Dimension, submenu: Dimension, entry: IDomNodePagePosition, expandDirection: Direction): { top: number; left: number } {
863+
private calculateSubmenuMenuLayout(windowDimensions: Dimension, submenu: Dimension, entry: IDomNodePagePosition, expandDirection: IMenuDirection): { top: number; left: number } {
854864
const ret = { top: 0, left: 0 };
855865

856866
// Start with horizontal
857-
ret.left = layout(windowDimensions.width, submenu.width, { position: expandDirection === Direction.Right ? LayoutAnchorPosition.Before : LayoutAnchorPosition.After, offset: entry.left, size: entry.width });
867+
ret.left = layout(windowDimensions.width, submenu.width, { position: expandDirection.horizontal === HorizontalDirection.Right ? LayoutAnchorPosition.Before : LayoutAnchorPosition.After, offset: entry.left, size: entry.width });
858868

859869
// We don't have enough room to layout the menu fully, so we are overlapping the menu
860870
if (ret.left >= entry.left && ret.left < entry.left + entry.width) {

src/vs/base/browser/ui/menu/menubar.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import * as DOM from 'vs/base/browser/dom';
88
import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent';
99
import { StandardMouseEvent } from 'vs/base/browser/mouseEvent';
1010
import { EventType, Gesture, GestureEvent } from 'vs/base/browser/touch';
11-
import { cleanMnemonic, Direction, IMenuOptions, IMenuStyles, Menu, MENU_ESCAPED_MNEMONIC_REGEX, MENU_MNEMONIC_REGEX } from 'vs/base/browser/ui/menu/menu';
11+
import { cleanMnemonic, HorizontalDirection, IMenuDirection, IMenuOptions, IMenuStyles, Menu, MENU_ESCAPED_MNEMONIC_REGEX, MENU_MNEMONIC_REGEX, VerticalDirection } from 'vs/base/browser/ui/menu/menu';
1212
import { ActionRunner, IAction, IActionRunner, Separator, SubmenuAction } from 'vs/base/common/actions';
1313
import { asArray } from 'vs/base/common/arrays';
1414
import { RunOnceScheduler } from 'vs/base/common/async';
@@ -32,7 +32,7 @@ export interface IMenuBarOptions {
3232
visibility?: string;
3333
getKeybinding?: (action: IAction) => ResolvedKeybinding | undefined;
3434
alwaysOnMnemonics?: boolean;
35-
compactMode?: Direction;
35+
compactMode?: IMenuDirection;
3636
actionRunner?: IActionRunner;
3737
getCompactMenuActions?: () => IAction[];
3838
}
@@ -333,9 +333,9 @@ export class MenuBar extends Disposable {
333333
} else {
334334
triggerKeys.push(KeyCode.Space);
335335

336-
if (this.options.compactMode === Direction.Right) {
336+
if (this.options.compactMode?.horizontal === HorizontalDirection.Right) {
337337
triggerKeys.push(KeyCode.RightArrow);
338-
} else if (this.options.compactMode === Direction.Left) {
338+
} else if (this.options.compactMode?.horizontal === HorizontalDirection.Left) {
339339
triggerKeys.push(KeyCode.LeftArrow);
340340
}
341341
}
@@ -1007,26 +1007,33 @@ export class MenuBar extends Disposable {
10071007
const titleBoundingRect = customMenu.titleElement.getBoundingClientRect();
10081008
const titleBoundingRectZoom = DOM.getDomNodeZoomLevel(customMenu.titleElement);
10091009

1010-
if (this.options.compactMode === Direction.Right) {
1011-
menuHolder.style.top = `${titleBoundingRect.top}px`;
1010+
if (this.options.compactMode?.horizontal === HorizontalDirection.Right) {
10121011
menuHolder.style.left = `${titleBoundingRect.left + this.container.clientWidth}px`;
1013-
} else if (this.options.compactMode === Direction.Left) {
1012+
} else if (this.options.compactMode?.horizontal === HorizontalDirection.Left) {
10141013
menuHolder.style.top = `${titleBoundingRect.top}px`;
10151014
menuHolder.style.right = `${this.container.clientWidth}px`;
10161015
menuHolder.style.left = 'auto';
10171016
} else {
1018-
menuHolder.style.top = `${titleBoundingRect.bottom * titleBoundingRectZoom}px`;
10191017
menuHolder.style.left = `${titleBoundingRect.left * titleBoundingRectZoom}px`;
10201018
}
10211019

1020+
if (this.options.compactMode?.vertical === VerticalDirection.Above) {
1021+
// TODO@benibenj Do not hardcode the height of the menu holder
1022+
menuHolder.style.top = `${titleBoundingRect.top - this.menus.length * 30 + this.container.clientHeight}px`;
1023+
} else if (this.options.compactMode?.vertical === VerticalDirection.Below) {
1024+
menuHolder.style.top = `${titleBoundingRect.top}px`;
1025+
} else {
1026+
menuHolder.style.top = `${titleBoundingRect.bottom * titleBoundingRectZoom}px`;
1027+
}
1028+
10221029
customMenu.buttonElement.appendChild(menuHolder);
10231030

10241031
const menuOptions: IMenuOptions = {
10251032
getKeyBinding: this.options.getKeybinding,
10261033
actionRunner: this.actionRunner,
10271034
enableMnemonics: this.options.alwaysOnMnemonics || (this.mnemonicsInUse && this.options.enableMnemonics),
10281035
ariaLabel: customMenu.buttonElement.getAttribute('aria-label') ?? undefined,
1029-
expandDirection: this.isCompact ? this.options.compactMode : Direction.Right,
1036+
expandDirection: this.isCompact ? this.options.compactMode : { horizontal: HorizontalDirection.Right, vertical: VerticalDirection.Below },
10301037
useEventAsContext: true
10311038
};
10321039

src/vs/workbench/browser/parts/titlebar/menubarControl.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { INotificationService, Severity } from 'vs/platform/notification/common/
2525
import { IPreferencesService } from 'vs/workbench/services/preferences/common/preferences';
2626
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
2727
import { MenuBar, IMenuBarOptions } from 'vs/base/browser/ui/menu/menubar';
28-
import { Direction } from 'vs/base/browser/ui/menu/menu';
28+
import { HorizontalDirection, IMenuDirection, VerticalDirection } from 'vs/base/browser/ui/menu/menu';
2929
import { mnemonicMenuLabel, unmnemonicLabel } from 'vs/base/common/labels';
3030
import { IAccessibilityService } from 'vs/platform/accessibility/common/accessibility';
3131
import { isFullscreen, onDidChangeFullscreen } from 'vs/base/browser/browser';
@@ -41,6 +41,7 @@ import { isICommandActionToggleInfo } from 'vs/platform/action/common/action';
4141
import { createAndFillInContextMenuActions } from 'vs/platform/actions/browser/menuEntryActionViewItem';
4242
import { defaultMenuStyles } from 'vs/platform/theme/browser/defaultStyles';
4343
import { mainWindow } from 'vs/base/browser/window';
44+
import { ActivityBarPosition } from 'vs/workbench/services/layout/browser/layoutService';
4445

4546
export type IOpenRecentAction = IAction & { uri: URI; remoteAuthority?: string };
4647

@@ -536,14 +537,19 @@ export class CustomMenubarControl extends MenubarControl {
536537
return enableMenuBarMnemonics && (!isWeb || isFullscreen(mainWindow));
537538
}
538539

539-
private get currentCompactMenuMode(): Direction | undefined {
540+
private get currentCompactMenuMode(): IMenuDirection | undefined {
540541
if (this.currentMenubarVisibility !== 'compact') {
541542
return undefined;
542543
}
543544

544545
// Menu bar lives in activity bar and should flow based on its location
545546
const currentSidebarLocation = this.configurationService.getValue<string>('workbench.sideBar.location');
546-
return currentSidebarLocation === 'right' ? Direction.Left : Direction.Right;
547+
const horizontalDirection = currentSidebarLocation === 'right' ? HorizontalDirection.Left : HorizontalDirection.Right;
548+
549+
const activityBarLocation = this.configurationService.getValue<string>('workbench.activityBar.location');
550+
const verticalDirection = activityBarLocation === ActivityBarPosition.BOTTOM ? VerticalDirection.Above : VerticalDirection.Below;
551+
552+
return { horizontal: horizontalDirection, vertical: verticalDirection };
547553
}
548554

549555
private onDidVisibilityChange(visible: boolean): void {

0 commit comments

Comments
 (0)