Skip to content

Commit

Permalink
Add streamOutputChange
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbrochart committed Aug 21, 2024
1 parent 06dc63d commit 09e5990
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
4 changes: 4 additions & 0 deletions javascript/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,10 @@ export type CellChange = SourceChange & {
* Cell output changes
*/
outputsChange?: Delta<Y.Map<any>>;
/**
* Cell stream output text changes
*/
streamOutputChange?: Delta<Y.Text>;
/**
* Cell execution count change
*/
Expand Down
15 changes: 11 additions & 4 deletions javascript/src/ycell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -827,24 +827,24 @@ export class YCodeCell
/**
* Remove text from a stream output.
*/
removeStreamOutput(index: number, start: number): void {
removeStreamOutput(index: number, start: number, origin: any = null): void {
this.transact(() => {
const output = this._youtputs.get(index);
const prevText = output.get('text') as Y.Text;
const length = prevText.length - start;
prevText.delete(start, length);
}, false);
}, false, origin);
}

/**
* Append text to a stream output.
*/
appendStreamOutput(index: number, text: string): void {
appendStreamOutput(index: number, text: string, origin: any = null): void {
this.transact(() => {
const output = this._youtputs.get(index);
const prevText = output.get('text') as Y.Text;
prevText.insert(prevText.length, text);
}, false);
}, false, origin);
}

/**
Expand Down Expand Up @@ -895,6 +895,13 @@ export class YCodeCell
protected getChanges(events: Y.YEvent<any>[]): Partial<CellChange> {
const changes = super.getChanges(events);

const streamOutputEvent = events.find(
event => event.path.length === 3 && event.path[0] === 'outputs' && event.path[2] === 'text'
);
if (streamOutputEvent) {
changes.streamOutputChange = streamOutputEvent.changes.delta as any;
}

const outputEvent = events.find(
event => event.target === this.ymodel.get('outputs')
);
Expand Down

0 comments on commit 09e5990

Please sign in to comment.