@@ -171,8 +171,12 @@ export class YBaseCell<Metadata extends nbformat.IBaseCellMetadata>
171
171
this . _undoManager = null ;
172
172
if ( options . notebook ) {
173
173
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
+ }
176
180
} else {
177
181
// Standalone cell
178
182
const doc = new Y . Doc ( ) ;
@@ -187,7 +191,7 @@ export class YBaseCell<Metadata extends nbformat.IBaseCellMetadata>
187
191
}
188
192
189
193
/**
190
- * Cell notebook awareness or null if the cell is standalone .
194
+ * Cell notebook awareness or null.
191
195
*/
192
196
get awareness ( ) : Awareness | null {
193
197
return this . _awareness ?? this . notebook ?. awareness ?? null ;
@@ -288,22 +292,6 @@ export class YBaseCell<Metadata extends nbformat.IBaseCellMetadata>
288
292
: this . notebook . undoManager ;
289
293
}
290
294
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
-
307
295
readonly ymodel : Y . Map < any > ;
308
296
309
297
get ysource ( ) : Y . Text {
0 commit comments