summaryrefslogtreecommitdiff
path: root/apps/web/src/stores/keybindings/migrations/v2-to-v3.ts
blob: 6ebff92cc99667888e8619302ac03cf796c37a8d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import type { KeybindingConfig, ShortcutKey } from "@/lib/actions/keybinding";
import type { TActionWithOptionalArgs } from "@/lib/actions";

interface V2State {
	keybindings: KeybindingConfig;
	isCustomized: boolean;
}

export function v2ToV3({ state }: { state: unknown }): unknown {
	const v2 = state as V2State;

	const renames: Record<string, string> = {
		"split-selected": "split",
		"split-selected-left": "split-left",
		"split-selected-right": "split-right",
	};

	const migrated = { ...v2.keybindings };
	for (const [key, action] of Object.entries(migrated)) {
		if (action && renames[action]) {
			migrated[key as ShortcutKey] = renames[action] as TActionWithOptionalArgs;
		}
	}

	return { ...v2, keybindings: migrated };
}