Skip to content

Commit

Permalink
fix: layout
Browse files Browse the repository at this point in the history
  • Loading branch information
bytemain committed Sep 23, 2024
1 parent aef7a97 commit 4837ef3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
22 changes: 20 additions & 2 deletions packages/core-browser/src/components/layout/default-layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { BoxPanel } from './box-panel';
import { SplitPanel } from './split-panel';

export interface ILayoutConfigCache {
[key: string]: { size: number; currentId: string };
[key: string]: { size?: number; currentId?: string };
}

export const getStorageValue = () => {
Expand All @@ -26,7 +26,7 @@ export const getStorageValue = () => {
} catch (err) {}

return {
layout: savedLayout,
layout: fixLayout(savedLayout),
colors: savedColors,
};
};
Expand Down Expand Up @@ -75,3 +75,21 @@ export function ToolbarActionBasedLayout(
</BoxPanel>
);
}

/**
* if layout has currentId, but its size is zero
* we cannot acknowledge the currentId, so we should remove it
*/
export function fixLayout(layout: ILayoutConfigCache) {
const newLayout = { ...layout };
for (const key in layout) {
if (!layout[key]) {
continue;
}

if (!layout[key].size) {
newLayout[key].currentId = '';
}
}
return newLayout;
}
3 changes: 2 additions & 1 deletion packages/main-layout/src/browser/layout.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
WithEventBus,
slotRendererRegistry,
} from '@opensumi/ide-core-browser';
import { fixLayout } from '@opensumi/ide-core-browser/lib/components';
import { LAYOUT_STATE, LayoutState } from '@opensumi/ide-core-browser/lib/layout/layout-state';
import { ComponentRegistryInfo } from '@opensumi/ide-core-browser/lib/layout/layout.interface';
import {
Expand Down Expand Up @@ -170,7 +171,7 @@ export class LayoutService extends WithEventBus implements IMainLayoutService {
}

restoreTabbarService = async (service: TabbarService) => {
this.state = this.layoutState.getState(LAYOUT_STATE.MAIN, defaultLayoutState);
this.state = fixLayout(this.layoutState.getState(LAYOUT_STATE.MAIN, defaultLayoutState));

const { currentId, size } = this.state[service.location] || {};
service.prevSize = size;
Expand Down

0 comments on commit 4837ef3

Please sign in to comment.