History class

Undo/redo stacks for a Document, implemented with inverted deltas.

Every local change is inverted against the document state it applied to and pushed on the undo stack; undoing composes that inverse back into the document (as ChangeSource.history, so it does not re-enter the stacks) and pushes the counter-inverse on the redo stack. Remote changes do not clear the stacks — they transform every stacked delta so history stays valid against the new document state, which is what makes undo safe under collaborative editing.

The now clock is injectable so merge-interval coalescing is testable without real waiting.

Constructors

History({HistoryOptions options = const HistoryOptions(), DateTime now()?})
Creates an empty history.

Properties

hashCode int
The hash code for this object.
no setterinherited
hasRedo bool
Whether a redo would apply a change.
no setter
hasUndo bool
Whether an undo would apply a change.
no setter
options HistoryOptions
The stack size and coalescing configuration.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

clear() → void
Discards both stacks.
handleChange(DocumentChange change) → void
Routes a document change into the history: local changes are recorded, remote changes transform the stacks, history-sourced changes (produced by undo/redo themselves) are ignored.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
record(Delta change, Delta before) → void
Records a local change applied to the document state before, clearing the redo stack.
redo(Document document) Delta?
Applies the top redo entry to document and returns the change that was composed, or null when the redo stack is empty.
toString() String
A string representation of this object.
inherited
transform(Delta change) → void
Rebases both stacks over a remote change using operational transformation, dropping entries that transform to nothing.
undo(Document document) Delta?
Applies the top undo entry to document and returns the change that was composed, or null when the undo stack is empty.

Operators

operator ==(Object other) bool
The equality operator.
inherited