From 7324bc17026df4f5128b5648b484d0565d604e24 Mon Sep 17 00:00:00 2001 From: SteVen Batten Date: Wed, 28 Aug 2019 15:17:19 -0700 Subject: [PATCH] prevent editor taking up more than its share fixes #79897 --- src/vs/workbench/browser/layout.ts | 17 +++++++++++++++++ .../browser/parts/editor/editorPart.ts | 7 ++++--- .../services/layout/browser/layoutService.ts | 5 +++++ src/vs/workbench/test/workbenchTestServices.ts | 2 ++ 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/vs/workbench/browser/layout.ts b/src/vs/workbench/browser/layout.ts index acf30a7669a..d49adbbaeb4 100644 --- a/src/vs/workbench/browser/layout.ts +++ b/src/vs/workbench/browser/layout.ts @@ -608,6 +608,23 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi return offset; } + getMaximumEditorDimensions(): Dimension { + const takenWidth = + (this.isVisible(Parts.ACTIVITYBAR_PART) ? this.activityBarPartView.minimumWidth : 0) + + (this.isVisible(Parts.SIDEBAR_PART) ? this.sideBarPartView.minimumWidth : 0) + + (this.isVisible(Parts.PANEL_PART) && this.state.panel.position === Position.RIGHT ? this.panelPartView.minimumWidth : 0); + + const takenHeight = + (this.isVisible(Parts.TITLEBAR_PART) ? this.titleBarPartView.minimumHeight : 0) + + (this.isVisible(Parts.STATUSBAR_PART) ? this.statusBarPartView.minimumHeight : 0) + + (this.isVisible(Parts.PANEL_PART) && this.state.panel.position === Position.BOTTOM ? this.panelPartView.minimumHeight : 0); + + const availableWidth = this.dimension.width - takenWidth; + const availableHeight = this.dimension.height - takenHeight; + + return { width: availableWidth, height: availableHeight }; + } + getWorkbenchContainer(): HTMLElement { return this.parent; } diff --git a/src/vs/workbench/browser/parts/editor/editorPart.ts b/src/vs/workbench/browser/parts/editor/editorPart.ts index 0f1888958a4..4ad7fe0de7b 100644 --- a/src/vs/workbench/browser/parts/editor/editorPart.ts +++ b/src/vs/workbench/browser/parts/editor/editorPart.ts @@ -140,7 +140,7 @@ export class EditorPart extends Part implements IEditorGroupsService, IEditorGro @IThemeService themeService: IThemeService, @IConfigurationService private readonly configurationService: IConfigurationService, @IStorageService storageService: IStorageService, - @IWorkbenchLayoutService layoutService: IWorkbenchLayoutService + @IWorkbenchLayoutService private readonly layoutService: IWorkbenchLayoutService ) { super(Parts.EDITOR_PART, { hasTitle: false }, themeService, storageService, layoutService); @@ -780,9 +780,10 @@ export class EditorPart extends Part implements IEditorGroupsService, IEditorGro //#region Part - get minimumWidth(): number { return this.centeredLayoutWidget.minimumWidth; } + // TODO @sbatten @joao find something better to prevent editor taking over #79897 + get minimumWidth(): number { return Math.min(this.centeredLayoutWidget.minimumWidth, this.layoutService.getMaximumEditorDimensions().width); } get maximumWidth(): number { return this.centeredLayoutWidget.maximumWidth; } - get minimumHeight(): number { return this.centeredLayoutWidget.minimumHeight; } + get minimumHeight(): number { return Math.min(this.centeredLayoutWidget.minimumHeight, this.layoutService.getMaximumEditorDimensions().height); } get maximumHeight(): number { return this.centeredLayoutWidget.maximumHeight; } readonly snap = true; diff --git a/src/vs/workbench/services/layout/browser/layoutService.ts b/src/vs/workbench/services/layout/browser/layoutService.ts index 344c7657de5..d59582f7421 100644 --- a/src/vs/workbench/services/layout/browser/layoutService.ts +++ b/src/vs/workbench/services/layout/browser/layoutService.ts @@ -144,6 +144,11 @@ export interface IWorkbenchLayoutService extends ILayoutService { */ setPanelPosition(position: Position): void; + /** + * Gets the maximum possible size for editor. + */ + getMaximumEditorDimensions(): Dimension; + /** * Returns the element that is parent of the workbench element. */ diff --git a/src/vs/workbench/test/workbenchTestServices.ts b/src/vs/workbench/test/workbenchTestServices.ts index e25eccdd4ad..af49603b3aa 100644 --- a/src/vs/workbench/test/workbenchTestServices.ts +++ b/src/vs/workbench/test/workbenchTestServices.ts @@ -541,6 +541,8 @@ export class TestLayoutService implements IWorkbenchLayoutService { public addClass(_clazz: string): void { } public removeClass(_clazz: string): void { } + public getMaximumEditorDimensions(): Dimension { throw new Error('not implemented'); } + public getWorkbenchContainer(): HTMLElement { throw new Error('not implemented'); } public getWorkbenchElement(): HTMLElement { throw new Error('not implemented'); } -- GitLab