@@ -764,17 +764,22 @@ export class YCodeCell
764
764
return JSONExt . deepCopy ( this . _youtputs . toJSON ( ) ) ;
765
765
}
766
766
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 > > = [ ] ;
769
769
for ( const output of outputs ) {
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 ;
@@ -798,6 +803,29 @@ export class YCodeCell
798
803
} , false ) ;
799
804
}
800
805
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
+
801
829
/**
802
830
* Replace content from `start' to `end` with `outputs`.
803
831
*
@@ -863,7 +891,7 @@ export class YCodeCell
863
891
return changes ;
864
892
}
865
893
866
- private _youtputs : Y . Array < nbformat . IOutput > ;
894
+ private _youtputs : Y . Array < Y . Map < any > > ;
867
895
}
868
896
869
897
class YAttachmentCell
0 commit comments