diff --git a/packages/notebook/src/browser/view-model/notebook-model.ts b/packages/notebook/src/browser/view-model/notebook-model.ts index a80ce44e4e4ea..b007e1a793490 100644 --- a/packages/notebook/src/browser/view-model/notebook-model.ts +++ b/packages/notebook/src/browser/view-model/notebook-model.ts @@ -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; diff --git a/packages/notebook/src/browser/view/notebook-cell-list-view.tsx b/packages/notebook/src/browser/view/notebook-cell-list-view.tsx index 7753a74e97f3b..39eeada382d0d 100644 --- a/packages/notebook/src/browser/view/notebook-cell-list-view.tsx +++ b/packages/notebook/src/browser/view/notebook-cell-list-view.tsx @@ -120,7 +120,7 @@ export class NotebookCellListView extends React.Component this.onDragStart(e)}> - {this.props.notebookModel.cells + {this.props.notebookModel.getVisibleCells() .map((cell, index) => 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 { @@ -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))); } } @@ -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,