Skip to content

Add clearOutputs() method to ISharedCodeCell #330

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions javascript/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,11 @@ export interface ISharedCodeCell
outputs: Array<nbformat.IOutput>
): void;

/**
* Clear all outputs from the cell.
*/
clearOutputs(): void;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing origin?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The origin parameter wasn’t exposed in the updateOutputs() method, so I followed the same pattern and didn’t expose it in clearOutputs() either.

updateOutputs(
start: number,
end: number,
outputs: Array<nbformat.IOutput>
): void;

I’m not entirely sure about the reasoning behind this, but if exposing it in the interface is something we should do, I’m happy to make that change.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do we need origin for in the first place? E.g. this one does not have origin:

setOutputs(outputs: Array<nbformat.IOutput>): void {
this.transact(() => {
this._youtputs.delete(0, this._youtputs.length);
const newOutputs = this.createOutputs(outputs);
this._youtputs.insert(0, newOutputs);
}, false);
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But this one does:

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,
origin
);
}


/**
* Serialize the model to JSON.
*/
Expand Down
13 changes: 13 additions & 0 deletions javascript/src/ycell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,19 @@ export class YCodeCell
);
}

/**
* Clear all outputs from the cell.
*/
clearOutputs(origin: any = null): void {
this.transact(
() => {
this._youtputs.delete(0, this._youtputs.length);
},
false,
origin
);
}

/**
* Serialize the model to JSON.
*/
Expand Down
Loading