Skip to content

@fabwcie/free-drawing / components/tools/UndoRedo/History / History

Class: History ​

Defined in: packages/free-drawing/src/components/tools/UndoRedo/History.ts:50

Undo / redo history of the drawing: states of drawing shapes, at most historyLimit

Extended by ​

Constructors ​

Constructor ​

new History(drawer): History

Defined in: packages/free-drawing/src/components/tools/UndoRedo/History.ts:64

Create a history with an empty drawing as only state

Parameters ​

drawer ​

Drawer

Drawer whose shapes are saved and restored

Returns ​

History

Properties ​

appHistory ​

appHistory: string[]

Defined in: packages/free-drawing/src/components/tools/UndoRedo/History.ts:54

Drawing states, JSON of shapes array (string is lighter than objects and compared without serializing again)


appHistoryStep ​

appHistoryStep: number = 0

Defined in: packages/free-drawing/src/components/tools/UndoRedo/History.ts:56

Index of current state in appHistory: states before it are undone, states after it redone


drawer ​

drawer: Drawer

Defined in: packages/free-drawing/src/components/tools/UndoRedo/History.ts:58

Drawer whose shapes are saved and restored

Methods ​

_push() ​

private _push(state): void

Defined in: packages/free-drawing/src/components/tools/UndoRedo/History.ts:95

Add state after current one (removes redo states), keeps the last historyLimit states

Parameters ​

state ​

string

JSON array of drawing shape states, becomes the current state

Returns ​

void


_restoreState() ​

private _restoreState(state): void

Defined in: packages/free-drawing/src/components/tools/UndoRedo/History.ts:154

Replace drawing by given state

Parameters ​

state ​

string

JSON array of drawing shape states (an item of appHistory)

Returns ​

void


canRedo() ​

canRedo(): boolean

Defined in: packages/free-drawing/src/components/tools/UndoRedo/History.ts:136

A state undone is after the current one

Returns ​

boolean

True when redo can restore a next state


canUndo() ​

canUndo(): boolean

Defined in: packages/free-drawing/src/components/tools/UndoRedo/History.ts:118

A state is before the current one

Returns ​

boolean

True when undo can restore a previous state


redo() ​

redo(): void

Defined in: packages/free-drawing/src/components/tools/UndoRedo/History.ts:143

Restore next state, nothing when there is none

Returns ​

void


reset() ​

reset(): void

Defined in: packages/free-drawing/src/components/tools/UndoRedo/History.ts:109

Current drawing is the first state (e.g. loaded from storage): nothing to undo or redo

Returns ​

void


saveState() ​

saveState(fromSaved?): void

Defined in: packages/free-drawing/src/components/tools/UndoRedo/History.ts:72

Add current drawing as a new state (on each drawer change), skipped when identical to current state

Parameters ​

fromSaved? ​

boolean = false

drawing loaded from a save: one state per shape added, so that each one can be undone

Returns ​

void


undo() ​

undo(): void

Defined in: packages/free-drawing/src/components/tools/UndoRedo/History.ts:125

Restore previous state, nothing when there is none

Returns ​

void