@@ -764,17 +764,22 @@ export class YCodeCell
764764 return JSONExt . deepCopy ( this . _youtputs . toJSON ( ) ) ;
765765 }
766766
767- createOutputs ( outputs : Array < nbformat . IOutput > ) : Array < any > {
768- const newOutputs : Array < any > = [ ] ;
767+ createOutputs ( outputs : Array < nbformat . IOutput > ) : Array < Y . Map < any > > {
768+ const newOutputs : Array < Y . Map < any > > = [ ] ;
769769 for ( const output of outputs ) {
770770 let _newOutput : { [ id : string ] : any } ;
771771 const newOutput = new Y . Map ( ) ;
772772 if ( output . output_type === 'stream' ) {
773- // Set the text field as a Y.Array
773+ // Set the text field as a Y.Text
774774 const { text, ...outputWithoutText } = output ;
775775 _newOutput = outputWithoutText ;
776- const newText = new Y . Array ( ) ;
777- newText . push ( text as string [ ] ) ;
776+ const newText = new Y . Text ( ) ;
777+ let length = 0 ;
778+ // text is a list of strings
779+ for ( const str of text as string [ ] ) {
780+ newText . insert ( length , str ) ;
781+ length += str . length ;
782+ }
778783 _newOutput [ 'text' ] = newText ;
779784 } else {
780785 _newOutput = output ;
@@ -798,6 +803,29 @@ export class YCodeCell
798803 } , false ) ;
799804 }
800805
806+ /**
807+ * Remove text from a stream output.
808+ */
809+ removeStreamOutput ( index : number , start : number ) : void {
810+ this . transact ( ( ) => {
811+ const output = this . _youtputs . get ( index ) ;
812+ const prevText = output . get ( 'text' ) as Y . Text ;
813+ const length = prevText . length - start ;
814+ prevText . delete ( start , length ) ;
815+ } , false ) ;
816+ }
817+
818+ /**
819+ * Append text to a stream output.
820+ */
821+ appendStreamOutput ( index : number , text : string ) : void {
822+ this . transact ( ( ) => {
823+ const output = this . _youtputs . get ( index ) ;
824+ const prevText = output . get ( 'text' ) as Y . Text ;
825+ prevText . insert ( prevText . length , text ) ;
826+ } , false ) ;
827+ }
828+
801829 /**
802830 * Replace content from `start' to `end` with `outputs`.
803831 *
@@ -863,7 +891,7 @@ export class YCodeCell
863891 return changes ;
864892 }
865893
866- private _youtputs : Y . Array < nbformat . IOutput > ;
894+ private _youtputs : Y . Array < Y . Map < any > > ;
867895}
868896
869897class YAttachmentCell
0 commit comments