feat(app): editor store, undo, recovery copy and geometry accept rules

This commit is contained in:
bchanot committed 2026-11-04 12:13:10 +01:00
1 parent f7e7bf4ee1
commit 7f1d44065b
20 files changed
+2538 -5

No files matched your search

+38
View File
@@ -0,0 +1,38 @@
/** Lot D: the history's byte bound and its steps. */
import { describe, expect, it } from 'vitest'
import {
HISTORY_LIMIT_BYTES, emptyHistory, entryOf, recordCommit, stepBack, stepForward,
} from '@/editor/state/undo'
const chunk = (bytes: number, tag: string) => tag + 'x'.repeat(bytes - tag.length)
describe('history', () => {
it('measures the UTF-8 size of each entry once', () => {
expect(entryOf('é').bytes).toBe(2)
})
it('drops the oldest undo entries while both stacks exceed the bound', () => {
const third = Math.floor(HISTORY_LIMIT_BYTES / 3) + 1
let history = emptyHistory()
for (const tag of ['a', 'b', 'c', 'd']) history = recordCommit(history, chunk(third, tag))
expect(history.undo.map((e) => e.text[0])).toEqual(['c', 'd'])
const total = history.undo.reduce((sum, e) => sum + e.bytes, 0)
expect(total).toBeLessThanOrEqual(HISTORY_LIMIT_BYTES)
})
it('counts the redo stack in the bound and clears it on a commit', () => {
const half = Math.floor(HISTORY_LIMIT_BYTES / 2)
let history = recordCommit(recordCommit(emptyHistory(), chunk(half, 'a')), chunk(half, 'b'))
const back = stepBack(history, chunk(half, 'c'))
expect(back?.text[0]).toBe('b')
history = back!.history
expect(history.redo).toHaveLength(1)
expect(stepForward(history, 'now')?.text[0]).toBe('c')
expect(recordCommit(history, 'z').redo).toEqual([])
})
it('answers null with nothing to step to', () => {
expect(stepBack(emptyHistory(), 'x')).toBeNull()
expect(stepForward(emptyHistory(), 'x')).toBeNull()
})
})