Push an action onto the undo stack.
(action: EditAction)
| 510 | |
| 511 | /** Push an action onto the undo stack. */ |
| 512 | push(action: EditAction): void { |
| 513 | // Group with previous action if within time window and same type |
| 514 | const lastAction = this.undoStack[this.undoStack.length - 1]; |
| 515 | if ( |
| 516 | lastAction && |
| 517 | action.timestamp - this.lastActionTime < UNDO_GROUP_WINDOW && |
| 518 | action.type === lastAction.type |
| 519 | ) { |
| 520 | // Merge actions |
| 521 | this.undoStack[this.undoStack.length - 1] = action; |
| 522 | } else { |
| 523 | this.undoStack.push(action); |
| 524 | if (this.undoStack.length > MAX_UNDO_STACK) { |
| 525 | this.undoStack.shift(); |
| 526 | } |
| 527 | } |
| 528 | |
| 529 | this.lastActionTime = action.timestamp; |
| 530 | this.redoStack.length = 0; // Clear redo stack on new action |
| 531 | } |
| 532 | |
| 533 | /** Pop and return the last undoable action. */ |
| 534 | undo(): EditAction | null { |
no outgoing calls