From 369d6d516cacf786a04f69809b40752d4ff02857 Mon Sep 17 00:00:00 2001 From: Jonah Iden Date: Thu, 12 Dec 2024 12:17:31 +0100 Subject: [PATCH] fixes for invisible cells Signed-off-by: Jonah Iden --- .../renderers/cell-output-webview.tsx | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/packages/plugin-ext/src/main/browser/notebooks/renderers/cell-output-webview.tsx b/packages/plugin-ext/src/main/browser/notebooks/renderers/cell-output-webview.tsx index 79aa098d41586..f265c996b4e4b 100644 --- a/packages/plugin-ext/src/main/browser/notebooks/renderers/cell-output-webview.tsx +++ b/packages/plugin-ext/src/main/browser/notebooks/renderers/cell-output-webview.tsx @@ -354,12 +354,13 @@ export class CellOutputWebviewImpl implements CellOutputWebview, Disposable { this.webviewWidget.show(); } - const visibleCells = new Set(this.notebook.getVisibleCells().map(cell => cell.handle)); + const visibleCells = this.notebook.getVisibleCells(); + const visibleCellHandleLookup = new Set(visibleCells.map(cell => cell.handle)); const updateOutputMessage: OutputChangedMessage = { type: 'outputChanged', changes: updates - .filter(update => visibleCells.has(update.cellHandle)) + .filter(update => visibleCellHandleLookup.has(update.cellHandle)) .map(update => ({ cellHandle: update.cellHandle, newOutputs: update.newOutputs.map(output => ({ @@ -367,7 +368,7 @@ export class CellOutputWebviewImpl implements CellOutputWebview, Disposable { items: output.outputs.map(item => ({ mime: item.mime, data: item.data.buffer })), metadata: output.metadata })), - start: update.start, + start: this.toVisibleCellIndex(update.start, visibleCells), deleteCount: update.deleteCount })) }; @@ -380,20 +381,21 @@ export class CellOutputWebviewImpl implements CellOutputWebview, Disposable { cellsChanged(cellEvents: NotebookContentChangedEvent[]): void { const changes: Array = []; + const visibleCells = this.notebook.getVisibleCells(); + const visibleCellLookup = new Set(visibleCells); for (const event of cellEvents) { if (event.kind === NotebookCellsChangeType.Move) { changes.push(...event.cells.map((cell, i) => ({ type: 'cellMoved', cellHandle: event.cells[0].handle, - toIndex: event.newIdx + i, + toIndex: event.newIdx, } 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, + start: this.toVisibleCellIndex(change.start, visibleCells), deleteCount: change.deleteCount, - newCells: change.newItems.filter(cell => visibleCells.has(cell as NotebookCellModel)).map(cell => cell.handle) + newCells: change.newItems.filter(cell => visibleCellLookup.has(cell as NotebookCellModel)).map(cell => cell.handle) } as CellsSpliced))); } } @@ -404,6 +406,10 @@ export class CellOutputWebviewImpl implements CellOutputWebview, Disposable { } as CellsChangedMessage); } + toVisibleCellIndex(index: number, visibleCells: Array): number { + return visibleCells.indexOf(this.notebook.cells[index]); + } + setCellHeight(cell: NotebookCellModel, height: number): void { if (!this.isDisposed) { this.webviewWidget.sendMessage({