in src/vs/workbench/browser/legacyLayout.ts [222:393]
private registerSashListeners(): void {
let startX: number = 0;
let startY: number = 0;
let startXTwo: number = 0;
let startSidebarWidth: number;
let startPanelHeight: number;
let startPanelWidth: number;
this._register(this.sashXOne.onDidStart((e: ISashEvent) => {
startSidebarWidth = this.sidebarWidth;
startX = e.startX;
}));
this._register(this.sashY.onDidStart((e: ISashEvent) => {
startPanelHeight = this.panelHeight;
startY = e.startY;
}));
this._register(this.sashXTwo.onDidStart((e: ISashEvent) => {
startPanelWidth = this.panelWidth;
startXTwo = e.startX;
}));
this._register(this.sashXOne.onDidChange((e: ISashEvent) => {
let doLayout = false;
let sidebarPosition = this.layoutService.getSideBarPosition();
let isSidebarVisible = this.layoutService.isVisible(Parts.SIDEBAR_PART);
let newSashWidth = (sidebarPosition === Position.LEFT) ? startSidebarWidth + e.currentX - startX : startSidebarWidth - e.currentX + startX;
// Sidebar visible
if (isSidebarVisible) {
// Automatically hide side bar when a certain threshold is met
if (newSashWidth + HIDE_SIDEBAR_WIDTH_THRESHOLD < this.partLayoutInfo.sidebar.minWidth) {
let dragCompensation = this.partLayoutInfo.sidebar.minWidth - HIDE_SIDEBAR_WIDTH_THRESHOLD;
this.layoutService.setSideBarHidden(true);
startX = (sidebarPosition === Position.LEFT) ? Math.max(this.activitybarWidth, e.currentX - dragCompensation) : Math.min(e.currentX + dragCompensation, this.workbenchSize.width - this.activitybarWidth);
this.sidebarWidth = startSidebarWidth; // when restoring sidebar, restore to the sidebar width we started from
}
// Otherwise size the sidebar accordingly
else {
this.sidebarWidth = Math.max(this.partLayoutInfo.sidebar.minWidth, newSashWidth); // Sidebar can not become smaller than MIN_PART_WIDTH
doLayout = newSashWidth >= this.partLayoutInfo.sidebar.minWidth;
}
}
// Sidebar hidden
else {
if ((sidebarPosition === Position.LEFT && e.currentX - startX >= this.partLayoutInfo.sidebar.minWidth) ||
(sidebarPosition === Position.RIGHT && startX - e.currentX >= this.partLayoutInfo.sidebar.minWidth)) {
startSidebarWidth = this.partLayoutInfo.sidebar.minWidth - (sidebarPosition === Position.LEFT ? e.currentX - startX : startX - e.currentX);
this.sidebarWidth = this.partLayoutInfo.sidebar.minWidth;
this.layoutService.setSideBarHidden(false);
}
}
if (doLayout) {
this.layout({ source: Parts.SIDEBAR_PART });
}
}));
this._register(this.sashY.onDidChange((e: ISashEvent) => {
let doLayout = false;
let isPanelVisible = this.layoutService.isVisible(Parts.PANEL_PART);
let newSashHeight = startPanelHeight - (e.currentY - startY);
// Panel visible
if (isPanelVisible) {
// Automatically hide panel when a certain threshold is met
if (newSashHeight + HIDE_PANEL_HEIGHT_THRESHOLD < this.partLayoutInfo.panel.minHeight) {
let dragCompensation = this.partLayoutInfo.panel.minHeight - HIDE_PANEL_HEIGHT_THRESHOLD;
this.layoutService.setPanelHidden(true);
startY = Math.min(this.sidebarHeight - this.statusbarHeight - this.titlebarHeight, e.currentY + dragCompensation);
this.panelHeight = startPanelHeight; // when restoring panel, restore to the panel height we started from
}
// Otherwise size the panel accordingly
else {
this.panelHeight = Math.max(this.partLayoutInfo.panel.minHeight, newSashHeight); // Panel can not become smaller than MIN_PART_HEIGHT
doLayout = newSashHeight >= this.partLayoutInfo.panel.minHeight;
}
}
// Panel hidden
else {
if (startY - e.currentY >= this.partLayoutInfo.panel.minHeight) {
startPanelHeight = 0;
this.panelHeight = this.partLayoutInfo.panel.minHeight;
this.layoutService.setPanelHidden(false);
}
}
if (doLayout) {
this.layout({ source: Parts.PANEL_PART });
}
}));
this._register(this.sashXTwo.onDidChange((e: ISashEvent) => {
let doLayout = false;
let isPanelVisible = this.layoutService.isVisible(Parts.PANEL_PART);
let newSashWidth = startPanelWidth - (e.currentX - startXTwo);
// Panel visible
if (isPanelVisible) {
// Automatically hide panel when a certain threshold is met
if (newSashWidth + HIDE_PANEL_WIDTH_THRESHOLD < this.partLayoutInfo.panel.minWidth) {
let dragCompensation = this.partLayoutInfo.panel.minWidth - HIDE_PANEL_WIDTH_THRESHOLD;
this.layoutService.setPanelHidden(true);
startXTwo = Math.min(this.workbenchSize.width - this.activitybarWidth, e.currentX + dragCompensation);
this.panelWidth = startPanelWidth; // when restoring panel, restore to the panel height we started from
}
// Otherwise size the panel accordingly
else {
this.panelWidth = newSashWidth;
doLayout = newSashWidth >= this.partLayoutInfo.panel.minWidth;
}
}
// Panel hidden
else {
if (startXTwo - e.currentX >= this.partLayoutInfo.panel.minWidth) {
startPanelWidth = 0;
this.panelWidth = this.partLayoutInfo.panel.minWidth;
this.layoutService.setPanelHidden(false);
}
}
if (doLayout) {
this.layout({ source: Parts.PANEL_PART });
}
}));
this._register(this.sashXOne.onDidEnd(() => {
this.storageService.store(WorkbenchLegacyLayout.sashXOneWidthSettingsKey, this.sidebarWidth, StorageScope.GLOBAL);
}));
this._register(this.sashY.onDidEnd(() => {
this.storageService.store(WorkbenchLegacyLayout.sashYHeightSettingsKey, this.panelHeight, StorageScope.GLOBAL);
}));
this._register(this.sashXTwo.onDidEnd(() => {
this.storageService.store(WorkbenchLegacyLayout.sashXTwoWidthSettingsKey, this.panelWidth, StorageScope.GLOBAL);
}));
this._register(this.sashY.onDidReset(() => {
this.panelHeight = this.sidebarHeight * DEFAULT_PANEL_SIZE_COEFFICIENT;
this.storageService.store(WorkbenchLegacyLayout.sashYHeightSettingsKey, this.panelHeight, StorageScope.GLOBAL);
this.layout();
}));
this._register(this.sashXOne.onDidReset(() => {
const activeViewlet = this.viewletService.getActiveViewlet();
const optimalWidth = activeViewlet ? activeViewlet.getOptimalWidth() : null;
this.sidebarWidth = typeof optimalWidth === 'number' ? Math.max(optimalWidth, DEFAULT_SIDEBAR_PART_WIDTH) : DEFAULT_SIDEBAR_PART_WIDTH;
this.storageService.store(WorkbenchLegacyLayout.sashXOneWidthSettingsKey, this.sidebarWidth, StorageScope.GLOBAL);
this.layoutService.setSideBarHidden(false);
this.layout();
}));
this._register(this.sashXTwo.onDidReset(() => {
this.panelWidth = (this.workbenchSize.width - this.sidebarWidth - this.activitybarWidth) * DEFAULT_PANEL_SIZE_COEFFICIENT;
this.storageService.store(WorkbenchLegacyLayout.sashXTwoWidthSettingsKey, this.panelWidth, StorageScope.GLOBAL);
this.layout();
}));
}