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

fixes for invisible cells #14617

Merged
merged 1 commit into from
Dec 12, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -354,20 +354,21 @@ 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 => ({
id: output.outputId,
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
}))
};
Expand All @@ -380,20 +381,21 @@ export class CellOutputWebviewImpl implements CellOutputWebview, Disposable {
cellsChanged(cellEvents: NotebookContentChangedEvent[]): void {
const changes: Array<CellsMoved | CellsSpliced> = [];

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)));
}
}
Expand All @@ -404,6 +406,10 @@ export class CellOutputWebviewImpl implements CellOutputWebview, Disposable {
} as CellsChangedMessage);
}

toVisibleCellIndex(index: number, visibleCells: Array<NotebookCellModel>): number {
return visibleCells.indexOf(this.notebook.cells[index]);
}

setCellHeight(cell: NotebookCellModel, height: number): void {
if (!this.isDisposed) {
this.webviewWidget.sendMessage({
Expand Down
Loading