@@ -753,12 +753,38 @@ export class YCodeCell
753753 set outputs ( v : Array < nbformat . IOutput > ) {
754754 this . setOutputs ( v ) ;
755755 }
756+ get youtputs ( ) : Y . Array < any > {
757+ return this . _youtputs ;
758+ }
756759
757760 /**
758761 * Execution, display, or stream outputs.
759762 */
760763 getOutputs ( ) : Array < nbformat . IOutput > {
761- return JSONExt . deepCopy ( this . _youtputs . toArray ( ) ) ;
764+ return JSONExt . deepCopy ( this . _youtputs . toJSON ( ) ) ;
765+ }
766+
767+ createOutputs ( outputs : Array < nbformat . IOutput > ) : Array < any > {
768+ const newOutputs : Array < any > = [ ] ;
769+ for ( const output of outputs ) {
770+ let _newOutput : { [ id : string ] : any } ;
771+ const newOutput = new Y . Map ( ) ;
772+ if ( output . output_type === 'stream' ) {
773+ // Set the text field as a Y.Array
774+ const { text, ...outputWithoutText } = output ;
775+ _newOutput = outputWithoutText ;
776+ const newText = new Y . Array ( ) ;
777+ newText . push ( text as string [ ] ) ;
778+ _newOutput [ 'text' ] = newText ;
779+ } else {
780+ _newOutput = output ;
781+ }
782+ for ( const [ key , value ] of Object . entries ( _newOutput ) ) {
783+ newOutput . set ( key , value ) ;
784+ }
785+ newOutputs . push ( newOutput ) ;
786+ }
787+ return newOutputs ;
762788 }
763789
764790 /**
@@ -767,7 +793,8 @@ export class YCodeCell
767793 setOutputs ( outputs : Array < nbformat . IOutput > ) : void {
768794 this . transact ( ( ) => {
769795 this . _youtputs . delete ( 0 , this . _youtputs . length ) ;
770- this . _youtputs . insert ( 0 , outputs ) ;
796+ const newOutputs = this . createOutputs ( outputs ) ;
797+ this . _youtputs . insert ( 0 , newOutputs ) ;
771798 } , false ) ;
772799 }
773800
@@ -789,7 +816,8 @@ export class YCodeCell
789816 end < this . _youtputs . length ? end - start : this . _youtputs . length - start ;
790817 this . transact ( ( ) => {
791818 this . _youtputs . delete ( start , fin ) ;
792- this . _youtputs . insert ( start , outputs ) ;
819+ const newOutputs = this . createOutputs ( outputs ) ;
820+ this . _youtputs . insert ( start , newOutputs ) ;
793821 } , false ) ;
794822 }
795823
0 commit comments