feat: balance layout and kbd workspace navigation

This commit is contained in:
Alejandro Gómez
2025-12-18 13:47:40 +01:00
parent 1581e313f3
commit b57ff31907
7 changed files with 265 additions and 3 deletions

View File

@@ -2,7 +2,11 @@ import { v4 as uuidv4 } from "uuid";
import type { MosaicNode } from "react-mosaic-component";
import { GrimoireState, WindowInstance, UserRelays } from "@/types/app";
import { insertWindow } from "@/lib/layout-utils";
import { applyPresetToLayout, type LayoutPreset } from "@/lib/layout-presets";
import {
applyPresetToLayout,
balanceLayout,
type LayoutPreset,
} from "@/lib/layout-presets";
/**
* Finds the lowest available workspace number.
@@ -394,3 +398,28 @@ export const applyPresetLayout = (
return state;
}
};
/**
* Balances all split percentages in the active workspace to 50/50.
* Useful for equalizing splits after manual resizing.
*/
export const balanceLayoutInWorkspace = (
state: GrimoireState,
): GrimoireState => {
const activeId = state.activeWorkspaceId;
const ws = state.workspaces[activeId];
// Balance the layout tree
const balancedLayout = balanceLayout(ws.layout);
return {
...state,
workspaces: {
...state.workspaces,
[activeId]: {
...ws,
layout: balancedLayout,
},
},
};
};

View File

@@ -241,6 +241,11 @@ export const useGrimoire = () => {
[setState],
);
const balanceLayout = useCallback(
() => setState((prev) => Logic.balanceLayoutInWorkspace(prev)),
[setState],
);
return {
state,
locale: state.locale || browserLocale,
@@ -256,5 +261,6 @@ export const useGrimoire = () => {
setActiveAccountRelays,
updateLayoutConfig,
applyPresetLayout,
balanceLayout,
};
};