summaryrefslogtreecommitdiff
path: root/apps/web/src/actions/keybindings/migrations/v3-to-v4.ts
blob: 3724f61c15dfb37c2cc515a5bf0b52fa16fa0552 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import { getPersistedKeybindingsState } from "../persisted-state";

export function v3ToV4({ state }: { state: unknown }): unknown {
	const v3 = getPersistedKeybindingsState({ state });
	if (!v3) return state;

	const renames: Record<string, string> = {
		"paste-selected": "paste-copied",
	};

	const migrated = { ...v3.keybindings };
	for (const [key, action] of Object.entries(migrated)) {
		const renamedAction = action ? renames[action] : undefined;
		if (renamedAction) {
			migrated[key] = renamedAction;
		}
	}

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