@@ -431,21 +431,23 @@ export class YBaseCell<Metadata extends nbformat.IBaseCellMetadata>
431431 return ;
432432 }
433433
434- this . _ymetadata . delete ( key ) ;
434+ this . transact ( ( ) => {
435+ this . _ymetadata . delete ( key ) ;
435436
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 ;
440441
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' ) ;
445449 }
446- } else if ( key === 'jupyter' ) {
447- this . _ymetadata . delete ( 'collapsed' ) ;
448- }
450+ } , false ) ;
449451 }
450452
451453 /**
@@ -524,7 +526,7 @@ export class YBaseCell<Metadata extends nbformat.IBaseCellMetadata>
524526 this . deleteMetadata ( 'collapsed' ) ;
525527 }
526528 }
527- } ) ;
529+ } , false ) ;
528530 } else {
529531 const clone = JSONExt . deepCopy ( metadata ) as any ;
530532 if ( clone . collapsed != null ) {
@@ -538,7 +540,7 @@ export class YBaseCell<Metadata extends nbformat.IBaseCellMetadata>
538540 for ( const [ key , value ] of Object . entries ( clone ) ) {
539541 this . _ymetadata . set ( key , value ) ;
540542 }
541- } ) ;
543+ } , false ) ;
542544 }
543545 }
544546 }
@@ -558,13 +560,16 @@ export class YBaseCell<Metadata extends nbformat.IBaseCellMetadata>
558560 /**
559561 * Perform a transaction. While the function f is called, all changes to the shared
560562 * 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`)
561566 */
562567 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 ) ;
568573 }
569574
570575 /**
@@ -606,22 +611,24 @@ export class YBaseCell<Metadata extends nbformat.IBaseCellMetadata>
606611 } ) ;
607612 break ;
608613 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+ }
625632 }
626633 break ;
627634 }
@@ -732,7 +739,7 @@ export class YCodeCell
732739 if ( this . ymodel . get ( 'execution_count' ) !== count ) {
733740 this . transact ( ( ) => {
734741 this . ymodel . set ( 'execution_count' , count ) ;
735- } ) ;
742+ } , false ) ;
736743 }
737744 }
738745
@@ -865,7 +872,7 @@ class YAttachmentCell
865872 } else {
866873 this . ymodel . set ( 'attachments' , attachments ) ;
867874 }
868- } ) ;
875+ } , false ) ;
869876 }
870877
871878 /**
0 commit comments