add destroy logic
This commit is contained in:
parent
b0b276d964
commit
e9a0dc4ed2
@ -180,7 +180,10 @@ export class UndoManager extends Observable {
|
|||||||
this.redoing = false
|
this.redoing = false
|
||||||
this.doc = /** @type {Doc} */ (this.scope[0].doc)
|
this.doc = /** @type {Doc} */ (this.scope[0].doc)
|
||||||
this.lastChange = 0
|
this.lastChange = 0
|
||||||
this.doc.on('afterTransaction', /** @param {Transaction} transaction */ transaction => {
|
/**
|
||||||
|
* @param {Transaction} transaction
|
||||||
|
*/
|
||||||
|
this.afterTransactionHandler = transaction => {
|
||||||
// Only track certain transactions
|
// Only track certain transactions
|
||||||
if (!this.scope.some(type => transaction.changedParentTypes.has(type)) || (!this.trackedOrigins.has(transaction.origin) && (!transaction.origin || !this.trackedOrigins.has(transaction.origin.constructor)))) {
|
if (!this.scope.some(type => transaction.changedParentTypes.has(type)) || (!this.trackedOrigins.has(transaction.origin) && (!transaction.origin || !this.trackedOrigins.has(transaction.origin.constructor)))) {
|
||||||
return
|
return
|
||||||
@ -229,7 +232,8 @@ export class UndoManager extends Observable {
|
|||||||
} else {
|
} else {
|
||||||
this.emit('stack-item-updated', changeEvent)
|
this.emit('stack-item-updated', changeEvent)
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
this.doc.on('afterTransaction', this.afterTransactionHandler)
|
||||||
this.doc.on('destroy', () => {
|
this.doc.on('destroy', () => {
|
||||||
this.destroy()
|
this.destroy()
|
||||||
})
|
})
|
||||||
@ -350,4 +354,10 @@ export class UndoManager extends Observable {
|
|||||||
canRedo () {
|
canRedo () {
|
||||||
return this.redoStack.length > 0
|
return this.redoStack.length > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
destroy () {
|
||||||
|
this.trackedOrigins.delete(this)
|
||||||
|
this.doc.off('afterTransaction', this.afterTransactionHandler)
|
||||||
|
super.destroy()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user