From c4347fce43229b954c9c5e0088e4d24b1aa0825a Mon Sep 17 00:00:00 2001 From: Charles Pierce Date: Thu, 22 Dec 2016 17:17:50 -0800 Subject: [PATCH 1/2] #14464 Preserve editor size when switching layout --- .../parts/editor/editorGroupsControl.ts | 60 +++++++++++++------ .../services/group/common/groupService.ts | 3 +- 2 files changed, 43 insertions(+), 20 deletions(-) diff --git a/src/vs/workbench/browser/parts/editor/editorGroupsControl.ts b/src/vs/workbench/browser/parts/editor/editorGroupsControl.ts index ce92c4c1a14..afa47d7ebac 100644 --- a/src/vs/workbench/browser/parts/editor/editorGroupsControl.ts +++ b/src/vs/workbench/browser/parts/editor/editorGroupsControl.ts @@ -758,7 +758,7 @@ export class EditorGroupsControl implements IEditorGroupsControl, IVerticalSashL this.sashTwo.setOrientation(this.layoutVertically ? Orientation.VERTICAL : Orientation.HORIZONTAL); // Trigger layout - this.arrangeGroups(GroupArrangement.EVEN); + this.arrangeGroups(GroupArrangement.KEEP_RATIO); } } @@ -778,27 +778,49 @@ export class EditorGroupsControl implements IEditorGroupsControl, IVerticalSashL return; // need more editors } - // Minimize Others - if (arrangement === GroupArrangement.MINIMIZE_OTHERS) { - POSITIONS.forEach(position => { - if (this.visibleEditors[position]) { - if (position !== this.lastActivePosition) { - this.silosSize[position] = this.minSize; - availableSize -= this.minSize; + switch (arrangement) { + case GroupArrangement.MINIMIZE_OTHERS: + // Minimize Others + POSITIONS.forEach(position => { + if (this.visibleEditors[position]) { + if (position !== this.lastActivePosition) { + this.silosSize[position] = this.minSize; + availableSize -= this.minSize; + } } - } - }); + }); - this.silosSize[this.lastActivePosition] = availableSize; - } + this.silosSize[this.lastActivePosition] = availableSize; + break; + case GroupArrangement.EVEN: + // Even Sizes + POSITIONS.forEach(position => { + if (this.visibleEditors[position]) { + this.silosSize[position] = availableSize / visibleEditors; + } + }); + break; + case GroupArrangement.KEEP_RATIO: + // Minimized editors should remain minimized, others should keep their relative Sizes + let oldNonMinimizedTotal = 0; + POSITIONS.forEach(position => { + if (this.visibleEditors[position]) { + if (this.silosMinimized[position]) { + this.silosSize[position] = this.minSize; + availableSize -= this.minSize; + } else { + oldNonMinimizedTotal += this.silosSize[position]; + } + } + }); - // Even Sizes - else if (arrangement === GroupArrangement.EVEN) { - POSITIONS.forEach(position => { - if (this.visibleEditors[position]) { - this.silosSize[position] = availableSize / visibleEditors; - } - }); + // Set size for non-minimized editors + const scaleFactor = availableSize / oldNonMinimizedTotal; + POSITIONS.forEach(position => { + if (this.visibleEditors[position] && !this.silosMinimized[position]) { + this.silosSize[position] *= scaleFactor; + } + }); } // Since we triggered a change in minimized/maximized editors, we need diff --git a/src/vs/workbench/services/group/common/groupService.ts b/src/vs/workbench/services/group/common/groupService.ts index 31829a11901..b27ab709b67 100644 --- a/src/vs/workbench/services/group/common/groupService.ts +++ b/src/vs/workbench/services/group/common/groupService.ts @@ -12,7 +12,8 @@ import Event from 'vs/base/common/event'; export enum GroupArrangement { MINIMIZE_OTHERS, - EVEN + EVEN, + KEEP_RATIO } export type GroupOrientation = 'vertical' | 'horizontal'; From 38038ba9c71aaa5b0e0f4228d257ceb36f908237 Mon Sep 17 00:00:00 2001 From: Charles Pierce Date: Wed, 4 Jan 2017 07:13:35 -0800 Subject: [PATCH 2/2] #14464 Remove KEEP_RATIO from the exposed API --- .../workbench/browser/parts/editor/editorGroupsControl.ts | 6 +++--- src/vs/workbench/services/group/common/groupService.ts | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/vs/workbench/browser/parts/editor/editorGroupsControl.ts b/src/vs/workbench/browser/parts/editor/editorGroupsControl.ts index afa47d7ebac..ebf4a30612c 100644 --- a/src/vs/workbench/browser/parts/editor/editorGroupsControl.ts +++ b/src/vs/workbench/browser/parts/editor/editorGroupsControl.ts @@ -758,7 +758,7 @@ export class EditorGroupsControl implements IEditorGroupsControl, IVerticalSashL this.sashTwo.setOrientation(this.layoutVertically ? Orientation.VERTICAL : Orientation.HORIZONTAL); // Trigger layout - this.arrangeGroups(GroupArrangement.KEEP_RATIO); + this.arrangeGroups(); } } @@ -766,7 +766,7 @@ export class EditorGroupsControl implements IEditorGroupsControl, IVerticalSashL return this.layoutVertically ? 'vertical' : 'horizontal'; } - public arrangeGroups(arrangement: GroupArrangement): void { + public arrangeGroups(arrangement?: GroupArrangement): void { if (!this.dimension) { return; // too early } @@ -800,7 +800,7 @@ export class EditorGroupsControl implements IEditorGroupsControl, IVerticalSashL } }); break; - case GroupArrangement.KEEP_RATIO: + default: // Minimized editors should remain minimized, others should keep their relative Sizes let oldNonMinimizedTotal = 0; POSITIONS.forEach(position => { diff --git a/src/vs/workbench/services/group/common/groupService.ts b/src/vs/workbench/services/group/common/groupService.ts index b27ab709b67..31829a11901 100644 --- a/src/vs/workbench/services/group/common/groupService.ts +++ b/src/vs/workbench/services/group/common/groupService.ts @@ -12,8 +12,7 @@ import Event from 'vs/base/common/event'; export enum GroupArrangement { MINIMIZE_OTHERS, - EVEN, - KEEP_RATIO + EVEN } export type GroupOrientation = 'vertical' | 'horizontal';