feat(history): add undo redo stack

This commit is contained in:
syntaxbullet
2026-07-03 17:30:31 +02:00
parent fedeaffa57
commit 0ffbc4f68b
12 changed files with 139 additions and 7 deletions

29
commands/history.test.ts Normal file
View File

@@ -0,0 +1,29 @@
import { describe, expect, test } from "bun:test";
import { createInitialAppState } from "@editor/initial-state";
import { createAppStore } from "@editor/store";
import { documentAddArtboardCommand } from "./document";
import { historyCommands } from "./history";
import { commandIds } from "./ids";
import { createCommandRegistry } from "./registry";
const registry = createCommandRegistry([documentAddArtboardCommand, ...historyCommands]);
describe("history commands", () => {
test("records document changes and undoes/redoes them", () => {
const store = createAppStore(createInitialAppState("Test"), registry);
store.dispatch(commandIds.documentAddArtboard, { id: "a1", name: "Artboard", bounds: { x: 0, y: 0, w: 100, h: 100 } });
expect(store.getState().document.artboards.map((artboard) => artboard.id)).toEqual(["a1"]);
expect(store.getState().history.past).toHaveLength(1);
store.dispatch(commandIds.historyUndo, undefined);
expect(store.getState().document.artboards).toEqual([]);
expect(store.getState().history.future).toHaveLength(1);
store.dispatch(commandIds.historyRedo, undefined);
expect(store.getState().document.artboards.map((artboard) => artboard.id)).toEqual(["a1"]);
});
});