[AttributionManager] implement acceptAllChanges and rejectAllChanges. closes #761

This commit is contained in:
Kevin Jahns
2025-12-30 18:59:48 +01:00
parent 8724af0b6e
commit 95638112d6

View File

@@ -24,7 +24,8 @@ import {
getItemCleanStart,
intersectSets,
ContentFormat,
StructStore, Transaction, ID, IdSet, Item, Snapshot, Doc, AbstractContent, IdMap // eslint-disable-line
StructStore, Transaction, ID, IdSet, Item, Snapshot, Doc, AbstractContent, IdMap, // eslint-disable-line
encodeStateAsUpdate
} from '../internals.js'
import * as error from 'lib0/error'
@@ -445,6 +446,20 @@ export class DiffAttributionManager extends ObservableV2 {
this._nextDoc.off('afterTransaction', this._afterTrListener)
}
acceptAllChanges () {
applyUpdate(this._prevDoc, encodeStateAsUpdate(this._nextDoc))
}
rejectAllChanges () {
this._prevDoc.transact(tr => {
applyUpdate(this._prevDoc, encodeStateAsUpdate(this._nextDoc))
const um = new UndoManager(this._prevDoc)
um.undoStack.push(new StackItem(tr.deleteSet, tr.insertSet))
um.undo()
um.destroy()
})
}
/**
* @param {ID} start
* @param {ID} end