diff --git a/javascript/src/ycell.ts b/javascript/src/ycell.ts index 1178376..e5a23ec 100644 --- a/javascript/src/ycell.ts +++ b/javascript/src/ycell.ts @@ -171,8 +171,12 @@ export class YBaseCell this._undoManager = null; if (options.notebook) { this._notebook = options.notebook as YNotebook; - // We cannot create a undo manager with the cell not yet attached in the notebook - // so we defer that to the notebook insertCell method + if (this._notebook.disableDocumentWideUndoRedo) { + this._undoManager = new Y.UndoManager([this.ymodel], { + trackedOrigins: new Set([this]), + doc: this._notebook.ydoc + }); + } } else { // Standalone cell const doc = new Y.Doc(); @@ -187,7 +191,7 @@ export class YBaseCell } /** - * Cell notebook awareness or null if the cell is standalone. + * Cell notebook awareness or null. */ get awareness(): Awareness | null { return this._awareness ?? this.notebook?.awareness ?? null; @@ -288,22 +292,6 @@ export class YBaseCell : this.notebook.undoManager; } - /** - * Defer setting the undo manager as it requires the - * cell to be attached to the notebook Y document. - */ - setUndoManager(): void { - if (this._undoManager) { - throw new Error('The cell undo manager is already set.'); - } - - if (this._notebook && this._notebook.disableDocumentWideUndoRedo) { - this._undoManager = new Y.UndoManager([this.ymodel], { - trackedOrigins: new Set([this]) - }); - } - } - readonly ymodel: Y.Map; get ysource(): Y.Text { diff --git a/javascript/src/ynotebook.ts b/javascript/src/ynotebook.ts index 2e54b1f..0b843bd 100644 --- a/javascript/src/ynotebook.ts +++ b/javascript/src/ynotebook.ts @@ -227,10 +227,6 @@ export class YNotebook ); }); - yCells.forEach(c => { - c.setUndoManager(); - }); - return yCells; } @@ -592,7 +588,6 @@ export class YNotebook const type = (item.content as Y.ContentType).type as Y.Map; if (!this._ycellMapping.has(type)) { const c = createCellModelFromSharedType(type, { notebook: this }); - c!.setUndoManager(); this._ycellMapping.set(type, c); } });