Two realms of state, one timeline per scope
QuarkXPress lived in two state realms at once. The document realm held everything specific to a single open document — pages, text, boxes, style sheets local to that document. The application realm held everything shared — preferences, hyphenation rules, color profiles, font substitution policies, plug-in registry — settings that, when changed, took effect immediately in every currently- open document.
The engine modeled each realm with its own action stack. Each open document carried a per-document undo stack; the application carried a global app-state stack. The challenge was that some actions belonged to both realms — an app-wide preference change is one global action that produces a consequence in every document. The engine had to record one global action with N document-side consequences and route undo requests so the right slice of the change came back at the right moment.