Skip to content

Commit

Permalink
Fix createOutputs, rename 'modeldb' origin to 'silent-change'
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbrochart committed Jul 12, 2024
1 parent 5464226 commit 0b8016c
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions javascript/src/ycell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ export class YBaseCell<Metadata extends nbformat.IBaseCellMetadata>
events: Y.YEvent<any>[],
transaction: Y.Transaction
) => {
if (transaction.origin !== 'modeldb') {
if (transaction.origin !== 'silent-change') {
this._changed.emit(this.getChanges(events));
}
};
Expand Down Expand Up @@ -771,27 +771,28 @@ export class YCodeCell

createOutputs(outputs: Array<nbformat.IOutput>): Array<Y.Map<any>> {
const newOutputs: Array<Y.Map<any>> = [];
for (const output of outputs) {
let _newOutput: { [id: string]: any };
const newOutput = new Y.Map();
for (const output of JSONExt.deepCopy(outputs)) {
let _newOutput1: { [id: string]: any };
if (output.output_type === 'stream') {
// Set the text field as a Y.Text
const { text, ...outputWithoutText } = output;
_newOutput = outputWithoutText;
_newOutput1 = outputWithoutText;
const newText = new Y.Text();
let length = 0;
// text is a list of strings
for (const str of text as string[]) {
newText.insert(length, str);
length += str.length;
}
_newOutput['text'] = newText;
_newOutput1['text'] = newText;
} else {
_newOutput = output;
_newOutput1 = output;
}
for (const [key, value] of Object.entries(_newOutput)) {
newOutput.set(key, value);
const _newOutput2: [string, any][] = [];
for (const [key, value] of Object.entries(_newOutput1)) {
_newOutput2.push([key, value]);
}
const newOutput = new Y.Map(_newOutput2);
newOutputs.push(newOutput);
}
return newOutputs;
Expand Down

0 comments on commit 0b8016c

Please sign in to comment.