Rich text / foldkit-richtext

Undo history

History is interaction state: snapshots of EditorState (document plus selection), kept beside the selection in the application Model, never in published content.

ts
let history = RichText.emptyHistory
history = RichText.commit(history, previousState, { group: RichText.groupFor(command) })
const back = RichText.undo(history, currentState) // → { history, state } | undefined
const forward = RichText.redo(back.history, back.state)

Grouping is explicit and clock-free: groupFor returns 'typing' for text insertion and deletion, so a typing burst collapses into one undo step, while every other command stands alone. undo/redo return undefined when there is nothing to do, and a new commit after an undo clears the redo stack. History is bounded (200 steps by default). Collaborative undo is a different operation and is not implemented.

In the harness, the parent Model owns the history and the child commits it, so one transition still commits document and interaction state together. Because undo replaces the document rather than editing it, the child reports a Replaced out-message with a whole-document ChangeSet (replaceChangeSet(previous, next)): every surviving identity is dirty and every departed one is removed, so the DOM cannot keep a stale element.