Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: persist grid gap #771

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/dockview-core/src/dockview/dockviewComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export interface SerializedDockview {
width: number;
orientation: Orientation;
};
gap?: number;
panels: Record<string, GroupviewPanelState>;
activeGroup?: string;
floatingGroups?: SerializedFloatingGroup[];
Expand Down Expand Up @@ -1216,6 +1217,12 @@ export class DockviewComponent
result.popoutGroups = popoutGroups;
}

const gap = this.gap;

if (gap !== 0) {
result.gap = gap;
}

return result;
}

Expand All @@ -1232,6 +1239,8 @@ export class DockviewComponent
throw new Error('root must be of type branch');
}

this.gridview.margin = data.gap ?? 0;

try {
// take note of the existing dimensions
const width = this.width;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ export const GridActions = (props: {
if (state) {
try {
props.api?.fromJSON(JSON.parse(state));

setGap(props.api?.gap ?? 0);
} catch (err) {
console.error('failed to load state', err);
localStorage.removeItem('dv-demo-state');
Expand Down Expand Up @@ -154,10 +156,6 @@ export const GridActions = (props: {

const [gap, setGap] = React.useState(0);

React.useEffect(() => {
props.api?.setGap(gap);
}, [gap, props.api]);

return (
<div className="action-container">
<div className="button-group">
Expand Down Expand Up @@ -208,7 +206,11 @@ export const GridActions = (props: {
max={99}
step={1}
value={gap}
onChange={(event) => setGap(Number(event.target.value))}
onChange={(event) => {
const value = Number(event.target.value);
setGap(value);
props.api?.setGap(value);
}}
/>
</div>
</div>
Expand Down