From 95638112d6b5c5a7ced2cc2e41d16d1e7bcd9eb4 Mon Sep 17 00:00:00 2001 From: Kevin Jahns Date: Tue, 30 Dec 2025 18:59:48 +0100 Subject: [PATCH] [AttributionManager] implement acceptAllChanges and rejectAllChanges. closes #761 --- src/utils/AttributionManager.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/utils/AttributionManager.js b/src/utils/AttributionManager.js index f74e368f..b4cce013 100644 --- a/src/utils/AttributionManager.js +++ b/src/utils/AttributionManager.js @@ -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