HistoryManager

class HistoryManager(capacity: Int = 100)

The undo/redo stack. execute runs a Command and makes it undoable; undo/redo walk the history in either direction. canUndo/canRedo are exposed as StateFlow so a host UI can enable/disable undo/redo buttons reactively without polling.

Executing a new command after undoing clears the redo stack — the same behavior as a browser dropping its forward history once you navigate somewhere new after going back. capacity caps how many steps stay undoable; the oldest entry is dropped once exceeded.

Constructors

Link copied to clipboard
constructor(capacity: Int = 100)

Properties

Link copied to clipboard
val canRedo: StateFlow<Boolean>

Whether there is a step to redo; collect it to enable or disable a redo button.

Link copied to clipboard
val canUndo: StateFlow<Boolean>

Whether there is a step to undo; collect it to enable or disable an undo button.

Functions

Link copied to clipboard
fun clear()

Forgets every step, undoable and redoable.

Link copied to clipboard
fun redo()

Does again the step that was taken back last. Nothing happens if there is none (a new step clears what could be redone).

Link copied to clipboard
fun undo()

Takes back the last step; it can be redone. Nothing happens if there is none.