# UndoRedo Class
Manages undo/redo stacks for all spreadsheet operations.
# oldData: Preserving Formula ASTs Across Irreversible Transformations
Some structural operations (e.g., removing rows/columns, moving cells) destroy
formula information that cannot be reconstructed from the transformation alone.
For example, when a row is removed, formulas referencing that row are rewritten
to #REF! — an irreversible change.
To support undo of such operations, oldData stores snapshots of formula AST
hashes keyed by the LazilyTransformingAstService version at which the irreversible
transformation was applied. Each entry maps a version number to an array of
[cellAddress, astHash] pairs that can be used to restore the original formula
from the parser cache.
# Memory Management
Without cleanup, oldData grows indefinitely as undo entries are evicted but
their oldData keys remain. Three mechanisms prevent this:
- Eviction cleanup: When undo entries are evicted (due to
undoLimit),cleanupOldDataForEntries()deletes their referenced oldData keys (unless still needed by entries on the other stack). - Orphan cleanup: Compaction may force lazy formula evaluation, which
writes new oldData entries for already-evicted undo entries. After compaction,
cleanupOrphanedOldData()removes any keys not referenced by entries on either stack or the in-progress batch. - Short-circuit: When
undoLimitis 0 (undo disabled),storeDataForVersion()returns immediately to avoid storing data that would never be used.
# Constructors
# constructor
+ new UndoRedo(config: Config, operations: Operations): UndoRedo
Defined in src/UndoRedo.ts:506 (opens new window)
Parameters:
| Name | Type |
|---|---|
config | Config |
operations | Operations |
Returns: UndoRedo
# Properties
# oldData
• oldData: Map‹number, [SimpleCellAddress, string][]› = new Map()
Defined in src/UndoRedo.ts:502 (opens new window)
# Methods
# beginBatchMode
▸ beginBatchMode(): void
Defined in src/UndoRedo.ts:523 (opens new window)
Returns: void
# cleanupOrphanedOldData
▸ cleanupOrphanedOldData(): void
Defined in src/UndoRedo.ts:887 (opens new window)
Removes oldData entries whose version keys are not referenced by any entry on the undo stack, redo stack, or in-progress batch. Called after compaction forces lazy formula evaluation, which may insert oldData for already-evicted entries.
Returns: void
# clearRedoStack
▸ clearRedoStack(): void
Defined in src/UndoRedo.ts:551 (opens new window)
Clears the redo stack and removes oldData entries no longer referenced by any remaining entry.
Returns: void
# clearUndoStack
▸ clearUndoStack(): void
Defined in src/UndoRedo.ts:557 (opens new window)
Clears the undo stack and removes oldData entries no longer referenced by any remaining entry.
Returns: void
# commitBatchMode
▸ commitBatchMode(): void
Defined in src/UndoRedo.ts:527 (opens new window)
Returns: void
# isRedoStackEmpty
▸ isRedoStackEmpty(): boolean
Defined in src/UndoRedo.ts:566 (opens new window)
Returns: boolean
# isUndoStackEmpty
▸ isUndoStackEmpty(): boolean
Defined in src/UndoRedo.ts:562 (opens new window)
Returns: boolean
# redo
▸ redo(): void
Defined in src/UndoRedo.ts:763 (opens new window)
Returns: void
# redoAddColumns
▸ redoAddColumns(operation: AddColumnsUndoEntry): void
Defined in src/UndoRedo.ts:815 (opens new window)
Parameters:
| Name | Type |
|---|---|
operation | AddColumnsUndoEntry |
Returns: void
# redoAddNamedExpression
▸ redoAddNamedExpression(operation: AddNamedExpressionUndoEntry): void
Defined in src/UndoRedo.ts:848 (opens new window)
Parameters:
| Name | Type |
|---|---|
operation | AddNamedExpressionUndoEntry |
Returns: void
# redoAddRows
▸ redoAddRows(operation: AddRowsUndoEntry): void
Defined in src/UndoRedo.ts:811 (opens new window)
Parameters:
| Name | Type |
|---|---|
operation | AddRowsUndoEntry |
Returns: void
# redoAddSheet
▸ redoAddSheet(operation: AddSheetUndoEntry): void
Defined in src/UndoRedo.ts:823 (opens new window)
Parameters:
| Name | Type |
|---|---|
operation | AddSheetUndoEntry |
Returns: void
# redoBatch
▸ redoBatch(batchOperation: BatchUndoEntry): void
Defined in src/UndoRedo.ts:775 (opens new window)
Parameters:
| Name | Type |
|---|---|
batchOperation | BatchUndoEntry |
Returns: void
# redoChangeNamedExpression
▸ redoChangeNamedExpression(operation: ChangeNamedExpressionUndoEntry): void
Defined in src/UndoRedo.ts:856 (opens new window)
Parameters:
| Name | Type |
|---|---|
operation | ChangeNamedExpressionUndoEntry |
Returns: void
# redoClearSheet
▸ redoClearSheet(operation: ClearSheetUndoEntry): void
Defined in src/UndoRedo.ts:839 (opens new window)
Parameters:
| Name | Type |
|---|---|
operation | ClearSheetUndoEntry |
Returns: void
# redoMoveCells
▸ redoMoveCells(operation: MoveCellsUndoEntry): void
Defined in src/UndoRedo.ts:785 (opens new window)
Parameters:
| Name | Type |
|---|---|
operation | MoveCellsUndoEntry |
Returns: void
# redoMoveColumns
▸ redoMoveColumns(operation: MoveColumnsUndoEntry): void
Defined in src/UndoRedo.ts:835 (opens new window)
Parameters:
| Name | Type |
|---|---|
operation | MoveColumnsUndoEntry |
Returns: void
# redoMoveRows
▸ redoMoveRows(operation: MoveRowsUndoEntry): void
Defined in src/UndoRedo.ts:831 (opens new window)
Parameters:
| Name | Type |
|---|---|
operation | MoveRowsUndoEntry |
Returns: void
# redoPaste
▸ redoPaste(operation: PasteUndoEntry): void
Defined in src/UndoRedo.ts:793 (opens new window)
Parameters:
| Name | Type |
|---|---|
operation | PasteUndoEntry |
Returns: void
# redoRemoveColumns
▸ redoRemoveColumns(operation: RemoveColumnsUndoEntry): void
Defined in src/UndoRedo.ts:789 (opens new window)
Parameters:
| Name | Type |
|---|---|
operation | RemoveColumnsUndoEntry |
Returns: void
# redoRemoveNamedExpression
▸ redoRemoveNamedExpression(operation: RemoveNamedExpressionUndoEntry): void
Defined in src/UndoRedo.ts:852 (opens new window)
Parameters:
| Name | Type |
|---|---|
operation | RemoveNamedExpressionUndoEntry |
Returns: void
# redoRemoveRows
▸ redoRemoveRows(operation: RemoveRowsUndoEntry): void
Defined in src/UndoRedo.ts:781 (opens new window)
Parameters:
| Name | Type |
|---|---|
operation | RemoveRowsUndoEntry |
Returns: void
# redoRemoveSheet
▸ redoRemoveSheet(operation: RemoveSheetUndoEntry): void
Defined in src/UndoRedo.ts:819 (opens new window)
Parameters:
| Name | Type |
|---|---|
operation | RemoveSheetUndoEntry |
Returns: void
# redoRenameSheet
▸ redoRenameSheet(operation: RenameSheetUndoEntry): void
Defined in src/UndoRedo.ts:827 (opens new window)
Parameters:
| Name | Type |
|---|---|
operation | RenameSheetUndoEntry |
Returns: void
# redoSetCellContents
▸ redoSetCellContents(operation: SetCellContentsUndoEntry): void
Defined in src/UndoRedo.ts:805 (opens new window)
Parameters:
| Name | Type |
|---|---|
operation | SetCellContentsUndoEntry |
Returns: void
# redoSetColumnOrder
▸ redoSetColumnOrder(operation: SetColumnOrderUndoEntry): void
Defined in src/UndoRedo.ts:864 (opens new window)
Parameters:
| Name | Type |
|---|---|
operation | SetColumnOrderUndoEntry |
Returns: void
# redoSetRowOrder
▸ redoSetRowOrder(operation: SetRowOrderUndoEntry): void
Defined in src/UndoRedo.ts:860 (opens new window)
Parameters:
| Name | Type |
|---|---|
operation | SetRowOrderUndoEntry |
Returns: void
# redoSetSheetContent
▸ redoSetSheetContent(operation: SetSheetContentUndoEntry): void
Defined in src/UndoRedo.ts:843 (opens new window)
Parameters:
| Name | Type |
|---|---|
operation | SetSheetContentUndoEntry |
Returns: void
# saveOperation
▸ saveOperation(operation: UndoEntry): void
Defined in src/UndoRedo.ts:515 (opens new window)
Parameters:
| Name | Type |
|---|---|
operation | UndoEntry |
Returns: void
# storeDataForVersion
▸ storeDataForVersion(version: number, address: SimpleCellAddress, astHash: string): void
Defined in src/UndoRedo.ts:539 (opens new window)
Stores a formula AST hash snapshot for the given LazilyTransformingAstService version.
Skipped when undoLimit is 0 (undo disabled) to avoid storing data that would never be used.
Parameters:
| Name | Type |
|---|---|
version | number |
address | SimpleCellAddress |
astHash | string |
Returns: void
# undo
▸ undo(): void
Defined in src/UndoRedo.ts:570 (opens new window)
Returns: void
# undoAddColumns
▸ undoAddColumns(operation: AddColumnsUndoEntry): void
Defined in src/UndoRedo.ts:627 (opens new window)
Parameters:
| Name | Type |
|---|---|
operation | AddColumnsUndoEntry |
Returns: void
# undoAddNamedExpression
▸ undoAddNamedExpression(operation: AddNamedExpressionUndoEntry): void
Defined in src/UndoRedo.ts:743 (opens new window)
Parameters:
| Name | Type |
|---|---|
operation | AddNamedExpressionUndoEntry |
Returns: void
# undoAddRows
▸ undoAddRows(operation: AddRowsUndoEntry): void
Defined in src/UndoRedo.ts:619 (opens new window)
Parameters:
| Name | Type |
|---|---|
operation | AddRowsUndoEntry |
Returns: void
# undoAddSheet
▸ undoAddSheet(operation: AddSheetUndoEntry): void
Defined in src/UndoRedo.ts:685 (opens new window)
Parameters:
| Name | Type |
|---|---|
operation | AddSheetUndoEntry |
Returns: void
# undoBatch
▸ undoBatch(batchOperation: BatchUndoEntry): void
Defined in src/UndoRedo.ts:581 (opens new window)
Parameters:
| Name | Type |
|---|---|
batchOperation | BatchUndoEntry |
Returns: void
# undoChangeNamedExpression
▸ undoChangeNamedExpression(operation: ChangeNamedExpressionUndoEntry): void
Defined in src/UndoRedo.ts:751 (opens new window)
Parameters:
| Name | Type |
|---|---|
operation | ChangeNamedExpressionUndoEntry |
Returns: void
# undoClearSheet
▸ undoClearSheet(operation: ClearSheetUndoEntry): void
Defined in src/UndoRedo.ts:718 (opens new window)
Parameters:
| Name | Type |
|---|---|
operation | ClearSheetUndoEntry |
Returns: void
# undoMoveCells
▸ undoMoveCells(operation: MoveCellsUndoEntry): void
Defined in src/UndoRedo.ts:673 (opens new window)
Parameters:
| Name | Type |
|---|---|
operation | MoveCellsUndoEntry |
Returns: void
# undoMoveColumns
▸ undoMoveColumns(operation: MoveColumnsUndoEntry): void
Defined in src/UndoRedo.ts:666 (opens new window)
Parameters:
| Name | Type |
|---|---|
operation | MoveColumnsUndoEntry |
Returns: void
# undoMoveRows
▸ undoMoveRows(operation: MoveRowsUndoEntry): void
Defined in src/UndoRedo.ts:659 (opens new window)
Parameters:
| Name | Type |
|---|---|
operation | MoveRowsUndoEntry |
Returns: void
# undoPaste
▸ undoPaste(operation: PasteUndoEntry): void
Defined in src/UndoRedo.ts:652 (opens new window)
Parameters:
| Name | Type |
|---|---|
operation | PasteUndoEntry |
Returns: void
# undoRemoveColumns
▸ undoRemoveColumns(operation: RemoveColumnsUndoEntry): void
Defined in src/UndoRedo.ts:603 (opens new window)
Parameters:
| Name | Type |
|---|---|
operation | RemoveColumnsUndoEntry |
Returns: void
# undoRemoveNamedExpression
▸ undoRemoveNamedExpression(operation: RemoveNamedExpressionUndoEntry): void
Defined in src/UndoRedo.ts:747 (opens new window)
Parameters:
| Name | Type |
|---|---|
operation | RemoveNamedExpressionUndoEntry |
Returns: void
# undoRemoveRows
▸ undoRemoveRows(operation: RemoveRowsUndoEntry): void
Defined in src/UndoRedo.ts:587 (opens new window)
Parameters:
| Name | Type |
|---|---|
operation | RemoveRowsUndoEntry |
Returns: void
# undoRemoveSheet
▸ undoRemoveSheet(operation: RemoveSheetUndoEntry): void
Defined in src/UndoRedo.ts:690 (opens new window)
Parameters:
| Name | Type |
|---|---|
operation | RemoveSheetUndoEntry |
Returns: void
# undoRenameSheet
▸ undoRenameSheet(operation: RenameSheetUndoEntry): void
Defined in src/UndoRedo.ts:708 (opens new window)
Parameters:
| Name | Type |
|---|---|
operation | RenameSheetUndoEntry |
Returns: void
# undoSetCellContents
▸ undoSetCellContents(operation: SetCellContentsUndoEntry): void
Defined in src/UndoRedo.ts:635 (opens new window)
Parameters:
| Name | Type |
|---|---|
operation | SetCellContentsUndoEntry |
Returns: void
# undoSetColumnOrder
▸ undoSetColumnOrder(operation: SetColumnOrderUndoEntry): void
Defined in src/UndoRedo.ts:759 (opens new window)
Parameters:
| Name | Type |
|---|---|
operation | SetColumnOrderUndoEntry |
Returns: void
# undoSetRowOrder
▸ undoSetRowOrder(operation: SetRowOrderUndoEntry): void
Defined in src/UndoRedo.ts:755 (opens new window)
Parameters:
| Name | Type |
|---|---|
operation | SetRowOrderUndoEntry |
Returns: void
# undoSetSheetContent
▸ undoSetSheetContent(operation: SetSheetContentUndoEntry): void
Defined in src/UndoRedo.ts:730 (opens new window)
Parameters:
| Name | Type |
|---|---|
operation | SetSheetContentUndoEntry |
Returns: void