Merge 9d2d812ea1e8741407503484101a9ec23dba9cf6 into 8fb73edd97abf7bb4ec5869cebff1c0d9248810e

This commit is contained in:
lixw 2022-10-08 12:33:27 -05:00 committed by GitHub
commit 38360396ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -139,6 +139,9 @@ const popStackItem = (undoManager, stack, eventType) => {
* undo/redo scope. * undo/redo scope.
* @property {Set<any>} [UndoManagerOptions.trackedOrigins=new Set([null])] * @property {Set<any>} [UndoManagerOptions.trackedOrigins=new Set([null])]
* @property {boolean} [ignoreRemoteMapChanges] Experimental. By default, the UndoManager will never overwrite remote changes. Enable this property to enable overwriting remote changes on key-value changes (Y.Map, properties on Y.Xml, etc..). * @property {boolean} [ignoreRemoteMapChanges] Experimental. By default, the UndoManager will never overwrite remote changes. Enable this property to enable overwriting remote changes on key-value changes (Y.Map, properties on Y.Xml, etc..).
* @property {boolean} [UndoManagerOptions.shouldDestroyUndoManager=true] Disable default destroy behavior if false. Sometimes
* when use undoManager to manage multiply components globally, each component (like y-prosemirror.yUndoPlugin...) may call destroy once being removed, then cause the global undoManager being destoryed.
* In this case, disable this option maybe be a choice to get the control back to yourself.
* @property {Doc} [doc] The document that this UndoManager operates on. Only needed if typeScope is empty. * @property {Doc} [doc] The document that this UndoManager operates on. Only needed if typeScope is empty.
*/ */
@ -162,6 +165,7 @@ export class UndoManager extends Observable {
deleteFilter = () => true, deleteFilter = () => true,
trackedOrigins = new Set([null]), trackedOrigins = new Set([null]),
ignoreRemoteMapChanges = false, ignoreRemoteMapChanges = false,
shouldDestroyUndoManager = true
doc = /** @type {Doc} */ (array.isArray(typeScope) ? typeScope[0].doc : typeScope.doc) doc = /** @type {Doc} */ (array.isArray(typeScope) ? typeScope[0].doc : typeScope.doc)
} = {}) { } = {}) {
super() super()
@ -174,6 +178,7 @@ export class UndoManager extends Observable {
trackedOrigins.add(this) trackedOrigins.add(this)
this.trackedOrigins = trackedOrigins this.trackedOrigins = trackedOrigins
this.captureTransaction = captureTransaction this.captureTransaction = captureTransaction
this.shouldDestoryUndoManager = shouldDestroyUndoManager
/** /**
* @type {Array<StackItem>} * @type {Array<StackItem>}
*/ */
@ -373,6 +378,8 @@ export class UndoManager extends Observable {
} }
destroy () { destroy () {
if (!this.shouldDestoryUndoManager) return
this.trackedOrigins.delete(this) this.trackedOrigins.delete(this)
this.doc.off('afterTransaction', this.afterTransactionHandler) this.doc.off('afterTransaction', this.afterTransactionHandler)
super.destroy() super.destroy()