The undo and redo stacks of steps (DOM-free): a new step clears the redo stack; at most maxSteps steps and maxCells cells (over both stacks) are kept – the oldest go first; a single step with more than maxCells cells empties the history and is not kept.

Example

const stack = new UndoStack<{ cellCount: number; label: string }>(100, 1_000_000);
stack.push({ cellCount: 1, label: "Edit" });
stack.undo()?.label; // "Edit" – now on the redo stack
stack.canRedo(); // true

Since

1.1.99

Type Parameters

  • T extends {
        cellCount: number;
    }

Hierarchy

  • UndoStack

Constructors

  • Type Parameters

    • T extends {
          cellCount: number;
      }

    Parameters

    • maxSteps: number

      steps kept on the undo stack

    • maxCells: number

      cells kept over both stacks

    Returns UndoStack<T>

Methods

  • Adds a step and clears the redo stack.

    Parameters

    • step: T

      the new step

    Returns boolean

    false if the step was too large (the history is empty now)

  • Takes the last undone step for redo (it moves back to the undo stack).

    Returns undefined | T

    the step, undefined if there is none

  • Takes the last step for undo (it moves to the redo stack).

    Returns undefined | T

    the step, undefined if there is none