Skip to content

Commit

Permalink
fix: can not track the first transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
lawvs committed Apr 15, 2024
1 parent d64a378 commit 899f4ef
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,21 @@ function createUndoManager(doc: Y.Doc) {
doc,
trackedOrigins: new Set([TRACK_ALL_ORIGINS]),
});
doc.on("update", () => {
const updateScope = () => {
// The UndoManager can only track shared types that are created
// See https://discuss.yjs.dev/t/global-document-undo-manager/2555
const keys = Array.from(doc.share.keys());
if (!keys.length) return;
const scope = keys.map((key) => doc.get(key));
undoManager.addToScope(scope);
// undoManager.addTrackedOrigin(origin);
});
};
doc.on("beforeTransaction", (transaction) => {
// Try to track all origins
// Workaround for https://github.com/yjs/yjs/issues/624
transaction.origin = TRACK_ALL_ORIGINS;
// Track all shared types before running UndoManager.afterTransactionHandler
updateScope();
});
return undoManager;
}
Expand Down

0 comments on commit 899f4ef

Please sign in to comment.