Simple JavaScript undo/redo command manager supporting transactions with no dependencies.

Fork Of JavaScript Undo Manager 1.0.0, by Alexey Grinko, licensed under MIT License.

Changes -

  1. Added presets commands
  2. Port to TypeScript
  3. Remove transactions, see SetValueUndoCommand for a replacement JSUndoManager

Constructors

Properties

enabled: boolean = true
limit: number
options: JSUndoManagerOptions = ...
presets: Record<string, (c: JSUndoManagerCommand2) => JSUndoManagerCommand1> = {}

Presets for commands, allows to define command types and their handlers. A preset maps from a JSUndoManagerCommand2 to a JSUndoManagerCommand1.

To add a preset, simply set it on this object, or using Object.assign.

sp: number

Methods

  • Bind 'undo' and 'redo' actions to 'Ctrl/Cmd+Z', 'Ctrl+Y' & 'Ctrl/Cmd+Shift+Z' hot keys. It is a basic implementation for quick testing and should be replaced with custom event handlers for more flexible processing.

    Returns JSUndoManager

  • Check whether redoing command is possible

    Returns boolean

  • Check whether undoing previous command is possible

    Returns boolean

  • Get number of commands in memory stack

    Returns number

  • Check whether the commands stack is empty

    Returns boolean

  • Check whether the commands stack size reaches its limit

    Returns boolean

  • Parameters

    • msg: string
    • ...args: any[]

    Returns void