Skip to content

Commit c43059c

Browse files
authored
Merge pull request microsoft#17760 from charlespierce/preserve_layout
microsoft#14464 Preserve editor size when switching layout
2 parents da49345 + 38038ba commit c43059c

1 file changed

Lines changed: 42 additions & 20 deletions

File tree

src/vs/workbench/browser/parts/editor/editorGroupsControl.ts

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -758,15 +758,15 @@ export class EditorGroupsControl implements IEditorGroupsControl, IVerticalSashL
758758
this.sashTwo.setOrientation(this.layoutVertically ? Orientation.VERTICAL : Orientation.HORIZONTAL);
759759

760760
// Trigger layout
761-
this.arrangeGroups(GroupArrangement.EVEN);
761+
this.arrangeGroups();
762762
}
763763
}
764764

765765
public getGroupOrientation(): GroupOrientation {
766766
return this.layoutVertically ? 'vertical' : 'horizontal';
767767
}
768768

769-
public arrangeGroups(arrangement: GroupArrangement): void {
769+
public arrangeGroups(arrangement?: GroupArrangement): void {
770770
if (!this.dimension) {
771771
return; // too early
772772
}
@@ -778,27 +778,49 @@ export class EditorGroupsControl implements IEditorGroupsControl, IVerticalSashL
778778
return; // need more editors
779779
}
780780

781-
// Minimize Others
782-
if (arrangement === GroupArrangement.MINIMIZE_OTHERS) {
783-
POSITIONS.forEach(position => {
784-
if (this.visibleEditors[position]) {
785-
if (position !== this.lastActivePosition) {
786-
this.silosSize[position] = this.minSize;
787-
availableSize -= this.minSize;
781+
switch (arrangement) {
782+
case GroupArrangement.MINIMIZE_OTHERS:
783+
// Minimize Others
784+
POSITIONS.forEach(position => {
785+
if (this.visibleEditors[position]) {
786+
if (position !== this.lastActivePosition) {
787+
this.silosSize[position] = this.minSize;
788+
availableSize -= this.minSize;
789+
}
788790
}
789-
}
790-
});
791+
});
791792

792-
this.silosSize[this.lastActivePosition] = availableSize;
793-
}
793+
this.silosSize[this.lastActivePosition] = availableSize;
794+
break;
795+
case GroupArrangement.EVEN:
796+
// Even Sizes
797+
POSITIONS.forEach(position => {
798+
if (this.visibleEditors[position]) {
799+
this.silosSize[position] = availableSize / visibleEditors;
800+
}
801+
});
802+
break;
803+
default:
804+
// Minimized editors should remain minimized, others should keep their relative Sizes
805+
let oldNonMinimizedTotal = 0;
806+
POSITIONS.forEach(position => {
807+
if (this.visibleEditors[position]) {
808+
if (this.silosMinimized[position]) {
809+
this.silosSize[position] = this.minSize;
810+
availableSize -= this.minSize;
811+
} else {
812+
oldNonMinimizedTotal += this.silosSize[position];
813+
}
814+
}
815+
});
794816

795-
// Even Sizes
796-
else if (arrangement === GroupArrangement.EVEN) {
797-
POSITIONS.forEach(position => {
798-
if (this.visibleEditors[position]) {
799-
this.silosSize[position] = availableSize / visibleEditors;
800-
}
801-
});
817+
// Set size for non-minimized editors
818+
const scaleFactor = availableSize / oldNonMinimizedTotal;
819+
POSITIONS.forEach(position => {
820+
if (this.visibleEditors[position] && !this.silosMinimized[position]) {
821+
this.silosSize[position] *= scaleFactor;
822+
}
823+
});
802824
}
803825

804826
// Since we triggered a change in minimized/maximized editors, we need

0 commit comments

Comments
 (0)