@@ -770,11 +770,16 @@ export class YCodeCell
770
770
let _newOutput : { [ id : string ] : any } ;
771
771
const newOutput = new Y . Map ( ) ;
772
772
if ( output . output_type === 'stream' ) {
773
- // Set the text field as a Y.Array
773
+ // Set the text field as a Y.Text
774
774
const { text, ...outputWithoutText } = output ;
775
775
_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
+ }
778
783
_newOutput [ 'text' ] = newText ;
779
784
} else {
780
785
_newOutput = output ;
@@ -799,13 +804,25 @@ export class YCodeCell
799
804
}
800
805
801
806
/**
802
- * Push text to a stream output.
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.
803
820
*/
804
- pushStreamOutput ( index : number , text : string ) : void {
821
+ appendStreamOutput ( index : number , text : string ) : void {
805
822
this . transact ( ( ) => {
806
823
const output = this . _youtputs . get ( index ) ;
807
- const prevText = output . get ( 'text' ) as Y . Array < string > ;
808
- prevText . push ( [ text ] ) ;
824
+ const prevText = output . get ( 'text' ) as Y . Text ;
825
+ prevText . insert ( prevText . length , text ) ;
809
826
} , false ) ;
810
827
}
811
828
0 commit comments