Skip to content
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

basics to allow for hidden cells #14573

Merged
merged 2 commits into from
Dec 4, 2024
Merged
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
4 changes: 4 additions & 0 deletions packages/notebook/src/browser/view-model/notebook-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,10 @@ export class NotebookModel implements Saveable, Disposable {
}
}

getVisibleCells(): NotebookCellModel[] {
return this.cells;
}

applyEdits(rawEdits: CellEditOperation[], computeUndoRedo: boolean): void {
const editsWithDetails = rawEdits.map((edit, index) => {
let cellIndex: number = -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export class NotebookCellListView extends React.Component<CellListProps, Noteboo

override render(): React.ReactNode {
return <ul className='theia-notebook-cell-list' ref={this.cellListRef} onDragStart={e => this.onDragStart(e)}>
{this.props.notebookModel.cells
{this.props.notebookModel.getVisibleCells()
.map((cell, index) =>
<React.Fragment key={'cell-' + cell.handle}>
<NotebookCellDivider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,21 +354,27 @@ export class CellOutputWebviewImpl implements CellOutputWebview, Disposable {
this.webviewWidget.show();
}

const visibleCells = new Set(this.notebook.getVisibleCells().map(cell => cell.handle));

const updateOutputMessage: OutputChangedMessage = {
type: 'outputChanged',
changes: updates.map(update => ({
cellHandle: update.cellHandle,
newOutputs: update.newOutputs.map(output => ({
id: output.outputId,
items: output.outputs.map(item => ({ mime: item.mime, data: item.data.buffer })),
metadata: output.metadata
})),
start: update.start,
deleteCount: update.deleteCount
}))
changes: updates
.filter(update => visibleCells.has(update.cellHandle))
.map(update => ({
cellHandle: update.cellHandle,
newOutputs: update.newOutputs.map(output => ({
id: output.outputId,
items: output.outputs.map(item => ({ mime: item.mime, data: item.data.buffer })),
metadata: output.metadata
})),
start: update.start,
deleteCount: update.deleteCount
}))
};

this.webviewWidget.sendMessage(updateOutputMessage);
if (updateOutputMessage.changes.length > 0) {
this.webviewWidget.sendMessage(updateOutputMessage);
}
}

cellsChanged(cellEvents: NotebookContentChangedEvent[]): void {
Expand All @@ -382,11 +388,12 @@ export class CellOutputWebviewImpl implements CellOutputWebview, Disposable {
toIndex: event.newIdx + i,
} as CellsMoved)));
} else if (event.kind === NotebookCellsChangeType.ModelChange) {
const visibleCells = new Set(this.notebook.getVisibleCells());
changes.push(...event.changes.map(change => ({
type: 'cellsSpliced',
start: change.start,
deleteCount: change.deleteCount,
newCells: change.newItems.map(cell => cell.handle)
newCells: change.newItems.filter(cell => visibleCells.has(cell as NotebookCellModel)).map(cell => cell.handle)
} as CellsSpliced)));
}
}
Expand Down Expand Up @@ -429,7 +436,7 @@ export class CellOutputWebviewImpl implements CellOutputWebview, Disposable {

switch (message.type) {
case 'initialized':
this.updateOutputs(this.notebook.cells.map(cell => ({
this.updateOutputs(this.notebook.getVisibleCells().map(cell => ({
cellHandle: cell.handle,
newOutputs: cell.outputs,
start: 0,
Expand Down
Loading