Skip to main content

Class: SceneStateManager

Defined in: src/core/StateManager.ts:228

Manages undo/redo state for a collection of mobjects (typically a Scene).

Usage:

const mgr = new SceneStateManager(scene.mobjects);
mgr.save(); // push current state onto undo stack
// ... user makes edits ...
mgr.undo(); // restore previous state
mgr.redo(); // re-apply the undone edit

The manager does not own the mobjects -- it reads/writes them through a getter so that additions/removals from the scene are reflected.

Constructors​

Constructor​

new SceneStateManager(getMobjects, maxDepth): SceneStateManager

Defined in: src/core/StateManager.ts:249

Parameters​

getMobjects​

() => Mobject[]

Getter returning the current scene mobjects (ordered)

maxDepth​

number = 50

Maximum undo stack depth (default 50)

Returns​

SceneStateManager

Properties​

maxDepth​

readonly maxDepth: number

Defined in: src/core/StateManager.ts:230

Maximum number of undo entries. Oldest are discarded when exceeded.

Accessors​

canRedo​

Get Signature​

get canRedo(): boolean

Defined in: src/core/StateManager.ts:364

Whether redo is available

Returns​

boolean


canUndo​

Get Signature​

get canUndo(): boolean

Defined in: src/core/StateManager.ts:359

Whether undo is available

Returns​

boolean


redoCount​

Get Signature​

get redoCount(): number

Defined in: src/core/StateManager.ts:354

Number of available redo steps

Returns​

number


redoStack​

Get Signature​

get redoStack(): readonly SceneSnapshot[]

Defined in: src/core/StateManager.ts:374

Read-only view of the redo stack (newest last)

Returns​

readonly SceneSnapshot[]


undoCount​

Get Signature​

get undoCount(): number

Defined in: src/core/StateManager.ts:349

Number of available undo steps

Returns​

number


undoStack​

Get Signature​

get undoStack(): readonly SceneSnapshot[]

Defined in: src/core/StateManager.ts:369

Read-only view of the undo stack (newest last)

Returns​

readonly SceneSnapshot[]

Methods​

clearHistory()​

clearHistory(): void

Defined in: src/core/StateManager.ts:343

Clear both undo and redo stacks.

Returns​

void


getState()​

getState(label?): SceneSnapshot

Defined in: src/core/StateManager.ts:327

Get a snapshot of the current scene state without pushing it onto any stack.

Parameters​

label?​

string

Returns​

SceneSnapshot


redo()​

redo(): boolean

Defined in: src/core/StateManager.ts:306

Redo: re-apply the last undone state. Pushes the current state onto the undo stack first.

Returns​

boolean

true if redo was applied, false if nothing to redo


save()​

save(label?): SceneSnapshot

Defined in: src/core/StateManager.ts:265

Capture the current scene state and push it onto the undo stack. Clears the redo stack (new action branch).

Parameters​

label?​

string

Optional human-readable label for this snapshot

Returns​

SceneSnapshot

The captured SceneSnapshot (for inspection / persistence)


setState()​

setState(snapshot): void

Defined in: src/core/StateManager.ts:336

Apply a previously captured snapshot, overwriting the current scene state. Does NOT modify undo/redo stacks -- call save() first if you want the current state preserved.

Parameters​

snapshot​

SceneSnapshot

Returns​

void


undo()​

undo(): boolean

Defined in: src/core/StateManager.ts:286

Undo: restore the most recently saved state. Pushes the current state onto the redo stack first.

Returns​

boolean

true if undo was applied, false if nothing to undo