UndoHistory class

Public static variables

static size_t kMaxTransactions constexpr
Entries are field deltas (a few dozen bytes each), so depth is cheap.

Public functions

void Begin(std::string name, const SelectionSnapshot& selection)
Open a transaction (or a nested scope inside the open one; only the outermost name counts).
void End()
Close one nesting level; the outermost End commits the transaction unless it is empty.
auto IsOpen() const -> bool
void Push(std::unique_ptr<UndoCommand> cmd, std::string name, const SelectionSnapshot& selection)
Record an already-applied command: into the open transaction, or as its own transaction.
auto Undo() -> const Transaction*
auto Redo() -> const Transaction*
auto CanUndo() const -> bool
auto CanRedo() const -> bool
auto GetUndoName() const -> const char*
Name of the transaction Undo/Redo would apply, or nullptr.
auto GetRedoName() const -> const char*
void Clear()
Forget everything without discarding (the world it referred to is being reset).
auto Position() const -> uint64_t
auto HasPending() const -> bool
An open transaction already holds changes.

Function documentation

const Transaction* UndoHistory::Undo()

Undo/redo one transaction; an open transaction is committed first. Returns the transaction that was applied (for selection restore), or nullptr if there was none.

uint64_t UndoHistory::Position() const

Where the history stands: the newest applied transaction's serial, 0 before the first. Kept at a save; the document is unsaved while this differs or HasPending.