diff --git a/README.md b/README.md index cb60b50f..f167b199 100644 --- a/README.md +++ b/README.md @@ -873,6 +873,16 @@ undo- or the redo-stack. +on('stack-item-updated', { stackItem: { meta: Map<any,any> }, type: 'undo' +| 'redo' }) + + +
+Register an event that is called when an existing StackItem is updated. +This happens when two changes happen within a "captureInterval". +
+ + on('stack-item-popped', { stackItem: { meta: Map<any,any> }, type: 'undo' | 'redo' }) @@ -881,6 +891,14 @@ on('stack-item-popped', { stackItem: { meta: Map<any,any> }, type: 'undo' Register an event that is called when a StackItem is popped from the undo- or the redo-stack. + + +on('stack-cleared', { undoStackCleared: boolean, redoStackCleared: boolean }) + + +
+Register an event that is called when the undo- and/or the redo-stack is cleared. +
#### Example: Stop Capturing diff --git a/src/utils/UndoManager.js b/src/utils/UndoManager.js index 7b0c9cae..7089018c 100644 --- a/src/utils/UndoManager.js +++ b/src/utils/UndoManager.js @@ -146,7 +146,7 @@ const popStackItem = (undoManager, stack, eventType) => { * 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 {Observable<'stack-item-added'|'stack-item-popped'|'stack-cleared'>} + * @extends {Observable<'stack-item-added'|'stack-item-popped'|'stack-cleared'|'stack-item-updated'>} */ export class UndoManager extends Observable { /** @@ -223,8 +223,11 @@ export class UndoManager extends Observable { keepItem(item, true) } }) + const changeEvent = [{ stackItem: stack[stack.length - 1], origin: transaction.origin, type: undoing ? 'redo' : 'undo', changedParentTypes: transaction.changedParentTypes }, this] if (didAdd) { - this.emit('stack-item-added', [{ stackItem: stack[stack.length - 1], origin: transaction.origin, type: undoing ? 'redo' : 'undo', changedParentTypes: transaction.changedParentTypes }, this]) + this.emit('stack-item-added', changeEvent) + } else { + this.emit('stack-item-updated', changeEvent) } }) this.doc.on('destroy', () => {