@@ -431,21 +431,23 @@ export class YBaseCell<Metadata extends nbformat.IBaseCellMetadata>
431
431
return ;
432
432
}
433
433
434
- this . _ymetadata . delete ( key ) ;
434
+ this . transact ( ( ) => {
435
+ this . _ymetadata . delete ( key ) ;
435
436
436
- const jupyter = this . getMetadata ( 'jupyter' ) as any ;
437
- if ( key === 'collapsed' && jupyter ) {
438
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
439
- const { outputs_hidden, ...others } = jupyter ;
437
+ const jupyter = this . getMetadata ( 'jupyter' ) as any ;
438
+ if ( key === 'collapsed' && jupyter ) {
439
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
440
+ const { outputs_hidden, ...others } = jupyter ;
440
441
441
- if ( Object . keys ( others ) . length === 0 ) {
442
- this . _ymetadata . delete ( 'jupyter' ) ;
443
- } else {
444
- this . _ymetadata . set ( 'jupyter' , others ) ;
442
+ if ( Object . keys ( others ) . length === 0 ) {
443
+ this . _ymetadata . delete ( 'jupyter' ) ;
444
+ } else {
445
+ this . _ymetadata . set ( 'jupyter' , others ) ;
446
+ }
447
+ } else if ( key === 'jupyter' ) {
448
+ this . _ymetadata . delete ( 'collapsed' ) ;
445
449
}
446
- } else if ( key === 'jupyter' ) {
447
- this . _ymetadata . delete ( 'collapsed' ) ;
448
- }
450
+ } , false ) ;
449
451
}
450
452
451
453
/**
@@ -524,7 +526,7 @@ export class YBaseCell<Metadata extends nbformat.IBaseCellMetadata>
524
526
this . deleteMetadata ( 'collapsed' ) ;
525
527
}
526
528
}
527
- } ) ;
529
+ } , false ) ;
528
530
} else {
529
531
const clone = JSONExt . deepCopy ( metadata ) as any ;
530
532
if ( clone . collapsed != null ) {
@@ -538,7 +540,7 @@ export class YBaseCell<Metadata extends nbformat.IBaseCellMetadata>
538
540
for ( const [ key , value ] of Object . entries ( clone ) ) {
539
541
this . _ymetadata . set ( key , value ) ;
540
542
}
541
- } ) ;
543
+ } , false ) ;
542
544
}
543
545
}
544
546
}
@@ -558,13 +560,16 @@ export class YBaseCell<Metadata extends nbformat.IBaseCellMetadata>
558
560
/**
559
561
* Perform a transaction. While the function f is called, all changes to the shared
560
562
* document are bundled into a single event.
563
+ *
564
+ * @param f Transaction to execute
565
+ * @param undoable Whether to track the change in the action history or not (default `true`)
561
566
*/
562
567
transact ( f : ( ) => void , undoable = true ) : void {
563
- this . notebook && undoable
564
- ? this . notebook . transact ( f )
565
- : this . ymodel . doc == null
566
- ? f ( )
567
- : this . ymodel . doc . transact ( f , this ) ;
568
+ ! this . notebook || this . notebook . disableDocumentWideUndoRedo
569
+ ? this . ymodel . doc == null
570
+ ? f ( )
571
+ : this . ymodel . doc . transact ( f , undoable ? this : null )
572
+ : this . notebook . transact ( f , undoable ) ;
568
573
}
569
574
570
575
/**
@@ -606,22 +611,24 @@ export class YBaseCell<Metadata extends nbformat.IBaseCellMetadata>
606
611
} ) ;
607
612
break ;
608
613
case 'update' :
609
- const newValue = this . _ymetadata . get ( key ) ;
610
- const oldValue = change . oldValue ;
611
- let equal = true ;
612
- if ( typeof oldValue == 'object' && typeof newValue == 'object' ) {
613
- equal = JSONExt . deepEqual ( oldValue , newValue ) ;
614
- } else {
615
- equal = oldValue === newValue ;
616
- }
617
-
618
- if ( ! equal ) {
619
- this . _metadataChanged . emit ( {
620
- key,
621
- type : 'change' ,
622
- oldValue,
623
- newValue
624
- } ) ;
614
+ {
615
+ const newValue = this . _ymetadata . get ( key ) ;
616
+ const oldValue = change . oldValue ;
617
+ let equal = true ;
618
+ if ( typeof oldValue == 'object' && typeof newValue == 'object' ) {
619
+ equal = JSONExt . deepEqual ( oldValue , newValue ) ;
620
+ } else {
621
+ equal = oldValue === newValue ;
622
+ }
623
+
624
+ if ( ! equal ) {
625
+ this . _metadataChanged . emit ( {
626
+ key,
627
+ type : 'change' ,
628
+ oldValue,
629
+ newValue
630
+ } ) ;
631
+ }
625
632
}
626
633
break ;
627
634
}
@@ -732,7 +739,7 @@ export class YCodeCell
732
739
if ( this . ymodel . get ( 'execution_count' ) !== count ) {
733
740
this . transact ( ( ) => {
734
741
this . ymodel . set ( 'execution_count' , count ) ;
735
- } ) ;
742
+ } , false ) ;
736
743
}
737
744
}
738
745
@@ -865,7 +872,7 @@ class YAttachmentCell
865
872
} else {
866
873
this . ymodel . set ( 'attachments' , attachments ) ;
867
874
}
868
- } ) ;
875
+ } , false ) ;
869
876
}
870
877
871
878
/**
0 commit comments