Skip to content

BlockSuite API Documentation / @blocksuite/store / Y / UndoManager

Class: UndoManager

Fires 'stack-item-added' event when a stack item was added to either the undo- or the redo-stack. You may store additional stack information via the metadata property on event.stackItem.meta (it is a Map of metadata properties). Fires 'stack-item-popped' event when a stack item was popped from either the undo- or the redo-stack. You may restore the saved stack information from event.stackItem.meta.

Extends

  • ObservableV2<Object>

Constructors

new UndoManager(typeScope, options)

new UndoManager(typeScope, options?): UndoManager

Parameters

typeScope: AbstractType<any> | AbstractType<any>[]

Accepts either a single type, or an array of types

options?: UndoManagerOptions

Returns

UndoManager

Overrides

ObservableV2<{ 'stack-item-added': (arg0: StackItemEvent, arg1: UndoManager) => void; 'stack-item-popped': (arg0: StackItemEvent, arg1: UndoManager) => void; 'stack-cleared': (arg0: { undoStackCleared: boolean; redoStackCleared: boolean; }) => void; 'stack-item-updated': (arg0: StackItemEvent, arg1: UndoManager) => void; }>.constructor

Source

node_modules/.pnpm/yjs@13.6.14/node_modules/yjs/dist/src/utils/UndoManager.d.ts:55

Properties

_observers

_observers: Map<string, Set<any>>

Some desc.

Inherited from

ObservableV2._observers

Source

node_modules/.pnpm/lib0@0.2.91/node_modules/lib0/observable.d.ts:15


afterTransactionHandler

afterTransactionHandler: (transaction) => void

Parameters

transaction: Transaction

Returns

void

Source

node_modules/.pnpm/yjs@13.6.14/node_modules/yjs/dist/src/utils/UndoManager.d.ts:91


captureTimeout

captureTimeout: number

Source

node_modules/.pnpm/yjs@13.6.14/node_modules/yjs/dist/src/utils/UndoManager.d.ts:87


captureTransaction

captureTransaction: (arg0) => boolean

Parameters

arg0: Transaction

Returns

boolean

Source

node_modules/.pnpm/yjs@13.6.14/node_modules/yjs/dist/src/utils/UndoManager.d.ts:63


currStackItem

currStackItem: null | StackItem

The currently popped stack item if UndoManager.undoing or UndoManager.redoing

Source

node_modules/.pnpm/yjs@13.6.14/node_modules/yjs/dist/src/utils/UndoManager.d.ts:84


deleteFilter

deleteFilter: (arg0) => boolean

Parameters

arg0: Item

Returns

boolean

Source

node_modules/.pnpm/yjs@13.6.14/node_modules/yjs/dist/src/utils/UndoManager.d.ts:61


doc

doc: Doc

Source

node_modules/.pnpm/yjs@13.6.14/node_modules/yjs/dist/src/utils/UndoManager.d.ts:60


ignoreRemoteMapChanges

ignoreRemoteMapChanges: boolean

Source

node_modules/.pnpm/yjs@13.6.14/node_modules/yjs/dist/src/utils/UndoManager.d.ts:86


lastChange

lastChange: number

Source

node_modules/.pnpm/yjs@13.6.14/node_modules/yjs/dist/src/utils/UndoManager.d.ts:85


redoStack

redoStack: StackItem[]

Source

node_modules/.pnpm/yjs@13.6.14/node_modules/yjs/dist/src/utils/UndoManager.d.ts:71


redoing

redoing: boolean

Source

node_modules/.pnpm/yjs@13.6.14/node_modules/yjs/dist/src/utils/UndoManager.d.ts:78


scope

scope: AbstractType<any>[]

Source

node_modules/.pnpm/yjs@13.6.14/node_modules/yjs/dist/src/utils/UndoManager.d.ts:59


trackedOrigins

trackedOrigins: Set<any>

Source

node_modules/.pnpm/yjs@13.6.14/node_modules/yjs/dist/src/utils/UndoManager.d.ts:62


undoStack

undoStack: StackItem[]

Source

node_modules/.pnpm/yjs@13.6.14/node_modules/yjs/dist/src/utils/UndoManager.d.ts:67


undoing

undoing: boolean

Whether the client is currently undoing (calling UndoManager.undo)

Source

node_modules/.pnpm/yjs@13.6.14/node_modules/yjs/dist/src/utils/UndoManager.d.ts:77

Methods

addToScope()

addToScope(ytypes): void

Parameters

ytypes: AbstractType<any> | AbstractType<any>[]

Returns

void

Source

node_modules/.pnpm/yjs@13.6.14/node_modules/yjs/dist/src/utils/UndoManager.d.ts:95


addTrackedOrigin()

addTrackedOrigin(origin): void

Parameters

origin: any

Returns

void

Source

node_modules/.pnpm/yjs@13.6.14/node_modules/yjs/dist/src/utils/UndoManager.d.ts:99


canRedo()

canRedo(): boolean

Are redo steps available?

Returns

boolean

true if redo is possible

Source

node_modules/.pnpm/yjs@13.6.14/node_modules/yjs/dist/src/utils/UndoManager.d.ts:149


canUndo()

canUndo(): boolean

Are undo steps available?

Returns

boolean

true if undo is possible

Source

node_modules/.pnpm/yjs@13.6.14/node_modules/yjs/dist/src/utils/UndoManager.d.ts:143


clear()

clear(clearUndoStack?, clearRedoStack?): void

Parameters

clearUndoStack?: boolean

clearRedoStack?: boolean

Returns

void

Source

node_modules/.pnpm/yjs@13.6.14/node_modules/yjs/dist/src/utils/UndoManager.d.ts:104


destroy()

destroy(): void

Returns

void

Inherited from

ObservableV2.destroy

Source

node_modules/.pnpm/lib0@0.2.91/node_modules/lib0/observable.d.ts:45


emit()

emit<NAME_3>(name, args): void

Emit a named event. All registered event listeners that listen to the specified name will receive the event.

Type parameters

NAME_3 extends "stack-cleared" | "stack-item-added" | "stack-item-popped" | "stack-item-updated"

Parameters

name: NAME_3

The event name.

args: Parameters<Object[NAME_3]>

The arguments that are applied to the event listener.

Returns

void

Inherited from

ObservableV2.emit

Todo

This should catch exceptions

Source

node_modules/.pnpm/lib0@0.2.91/node_modules/lib0/observable.d.ts:44


off()

off<NAME_2>(name, f): void

Type parameters

NAME_2 extends "stack-cleared" | "stack-item-added" | "stack-item-popped" | "stack-item-updated"

Parameters

name: NAME_2

f: Object[NAME_2]

Returns

void

Inherited from

ObservableV2.off

Source

node_modules/.pnpm/lib0@0.2.91/node_modules/lib0/observable.d.ts:33


on()

on<NAME>(name, f): Object[NAME]

Type parameters

NAME extends "stack-cleared" | "stack-item-added" | "stack-item-popped" | "stack-item-updated"

Parameters

name: NAME

f: Object[NAME]

Returns

Object[NAME]

Inherited from

ObservableV2.on

Source

node_modules/.pnpm/lib0@0.2.91/node_modules/lib0/observable.d.ts:21


once()

once<NAME_1>(name, f): void

Type parameters

NAME_1 extends "stack-cleared" | "stack-item-added" | "stack-item-popped" | "stack-item-updated"

Parameters

name: NAME_1

f: Object[NAME_1]

Returns

void

Inherited from

ObservableV2.once

Source

node_modules/.pnpm/lib0@0.2.91/node_modules/lib0/observable.d.ts:27


redo()

redo(): null | StackItem

Redo last undo operation.

Returns

null | StackItem

Returns StackItem if a change was applied

Source

node_modules/.pnpm/yjs@13.6.14/node_modules/yjs/dist/src/utils/UndoManager.d.ts:137


removeTrackedOrigin()

removeTrackedOrigin(origin): void

Parameters

origin: any

Returns

void

Source

node_modules/.pnpm/yjs@13.6.14/node_modules/yjs/dist/src/utils/UndoManager.d.ts:103


stopCapturing()

stopCapturing(): void

UndoManager merges Undo-StackItem if they are created within time-gap smaller than options.captureTimeout. Call um.stopCapturing() so that the next StackItem won't be merged.

Returns

void

Example

ts
// without stopCapturing
    ytext.insert(0, 'a')
    ytext.insert(1, 'b')
    um.undo()
    ytext.toString() // => '' (note that 'ab' was removed)
    // with stopCapturing
    ytext.insert(0, 'a')
    um.stopCapturing()
    ytext.insert(0, 'b')
    um.undo()
    ytext.toString() // => 'a' (note that only 'b' was removed)

Source

node_modules/.pnpm/yjs@13.6.14/node_modules/yjs/dist/src/utils/UndoManager.d.ts:125


undo()

undo(): null | StackItem

Undo last changes on type.

Returns

null | StackItem

Returns StackItem if a change was applied

Source

node_modules/.pnpm/yjs@13.6.14/node_modules/yjs/dist/src/utils/UndoManager.d.ts:131