From 7bf0984698e43b9aa2dd879f65951318ed410390 Mon Sep 17 00:00:00 2001 From: Maze <167211895+mazeincoding@users.noreply.github.com> Date: Sat, 31 Jan 2026 00:20:04 +0100 Subject: codebase overhaul (#697) --- .../web/src/stores/keybindings/migrations/index.ts | 28 ++++++++++++++++++++++ .../src/stores/keybindings/migrations/v2-to-v3.ts | 26 ++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 apps/web/src/stores/keybindings/migrations/index.ts create mode 100644 apps/web/src/stores/keybindings/migrations/v2-to-v3.ts (limited to 'apps/web/src/stores/keybindings') diff --git a/apps/web/src/stores/keybindings/migrations/index.ts b/apps/web/src/stores/keybindings/migrations/index.ts new file mode 100644 index 00000000..1689802e --- /dev/null +++ b/apps/web/src/stores/keybindings/migrations/index.ts @@ -0,0 +1,28 @@ +import { v2ToV3 } from './v2-to-v3'; + +type MigrationFn = ({ state }: { state: unknown }) => unknown; + +/** + * key = version we're migrating from + * value = migration function + */ +const migrations: Record = { + 2: v2ToV3, +}; + +export const CURRENT_VERSION = 3; + +export function runMigrations({ + state, + fromVersion, +}: { + state: unknown; + fromVersion: number; +}): unknown { + let current = state; + for (let version = fromVersion; version < CURRENT_VERSION; version++) { + const migrate = migrations[version]; + if (migrate) current = migrate({ state: current }); + } + return current; +} diff --git a/apps/web/src/stores/keybindings/migrations/v2-to-v3.ts b/apps/web/src/stores/keybindings/migrations/v2-to-v3.ts new file mode 100644 index 00000000..1517b52b --- /dev/null +++ b/apps/web/src/stores/keybindings/migrations/v2-to-v3.ts @@ -0,0 +1,26 @@ +import type { KeybindingConfig, ShortcutKey } from "@/types/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 = { + "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 }; +} -- cgit v1.3.1