diff --git a/packages/notebook/src/browser/view-model/notebook-model.ts b/packages/notebook/src/browser/view-model/notebook-model.ts index fe44f00fd1a08..5c12186b4c403 100644 --- a/packages/notebook/src/browser/view-model/notebook-model.ts +++ b/packages/notebook/src/browser/view-model/notebook-model.ts @@ -314,7 +314,7 @@ export class NotebookModel implements Saveable, Disposable { // if selected cell is affected update it because it can potentially have been replaced if (cell === this.selectedCell) { - this.setSelectedCell(this.cells[cellIndex]); + this.setSelectedCell(this.cells[Math.min(cellIndex, this.cells.length - 1)]); } }