@@ -171,8 +171,12 @@ export class YBaseCell<Metadata extends nbformat.IBaseCellMetadata>
171171 this . _undoManager = null ;
172172 if ( options . notebook ) {
173173 this . _notebook = options . notebook as YNotebook ;
174- // We cannot create a undo manager with the cell not yet attached in the notebook
175- // so we defer that to the notebook insertCell method
174+ if ( this . _notebook . disableDocumentWideUndoRedo ) {
175+ this . _undoManager = new Y . UndoManager ( [ this . ymodel ] , {
176+ trackedOrigins : new Set ( [ this ] ) ,
177+ doc : this . _notebook . ydoc
178+ } ) ;
179+ }
176180 } else {
177181 // Standalone cell
178182 const doc = new Y . Doc ( ) ;
@@ -187,7 +191,7 @@ export class YBaseCell<Metadata extends nbformat.IBaseCellMetadata>
187191 }
188192
189193 /**
190- * Cell notebook awareness or null if the cell is standalone .
194+ * Cell notebook awareness or null.
191195 */
192196 get awareness ( ) : Awareness | null {
193197 return this . _awareness ?? this . notebook ?. awareness ?? null ;
@@ -288,22 +292,6 @@ export class YBaseCell<Metadata extends nbformat.IBaseCellMetadata>
288292 : this . notebook . undoManager ;
289293 }
290294
291- /**
292- * Defer setting the undo manager as it requires the
293- * cell to be attached to the notebook Y document.
294- */
295- setUndoManager ( ) : void {
296- if ( this . _undoManager ) {
297- throw new Error ( 'The cell undo manager is already set.' ) ;
298- }
299-
300- if ( this . _notebook && this . _notebook . disableDocumentWideUndoRedo ) {
301- this . _undoManager = new Y . UndoManager ( [ this . ymodel ] , {
302- trackedOrigins : new Set ( [ this ] )
303- } ) ;
304- }
305- }
306-
307295 readonly ymodel : Y . Map < any > ;
308296
309297 get ysource ( ) : Y . Text {
0 commit comments