Refactor stayWithinUndoStateBudget out from eventsChanged
Assign a regeneration cost to undo states
Spread out older undo states more to speed up undoing lots of events
Repair undo states rather than discarding them