UndoStack

class UndoStack(val limit: Int = DEFAULT_LIMIT)(source)

Per-document undo / redo stack used by the editor's master-pane operations (Add, Clone, Remove, Reorder, Enable/Disable, Rename per scenario workflow §6 — and any other reversible action). Bounded by limit (default 20 per §6); pushing past the cap discards the oldest entry.

The stack is caller-applies: the editor performs the user's change first, then pushes an operation that knows how to undo and redo it. This keeps the stack decoupled from the editor's data model — any reversible change shape works, not just scenarios-list ops.

Calling push clears the redo branch — a new edit after some undo invalidates the future the user diverged from. Calling clear empties both stacks (typically on document close).

Thread-safety: the underlying MutableStateFlow is safe for concurrent reads, but mutating methods are not synchronised. In practice the editor view-model is the sole mutator and lives on the Swing EDT.

Constructors

Link copied to clipboard
constructor(limit: Int = DEFAULT_LIMIT)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
val limit: Int
Link copied to clipboard

Test-only: depth of the redo stack.

Link copied to clipboard
val state: StateFlow<UndoState>

Observable state for menu enablement and label binding.

Link copied to clipboard

Test-only: depth of the undo stack. Public because the test lives in a separate Gradle module (KSLTesting) and internal doesn't reach across module boundaries.

Functions

Link copied to clipboard
fun clear()

Empties both stacks. Call on document close.

Link copied to clipboard
fun push(operation: UndoableOperation)

Records operation on the undo stack. The caller is expected to have already applied the change. Pushing always clears the redo branch. If the stack is at limit, the oldest entry is dropped to make room.

Link copied to clipboard
fun redo(): Boolean

Re-applies the most recently undone operation by invoking its redo callback, moving it back to the undo stack. Returns true when something was redone; false when the redo stack was empty.

Link copied to clipboard
fun undo(): Boolean

Reverts the most recently pushed operation by invoking its undo callback, moving it to the redo stack. Returns true when something was undone; false when the stack was empty.