diff --git a/src/vs/workbench/contrib/notebook/browser/view/notebookCellList.ts b/src/vs/workbench/contrib/notebook/browser/view/notebookCellList.ts index 26519f055d7..f40f28d3351 100644 --- a/src/vs/workbench/contrib/notebook/browser/view/notebookCellList.ts +++ b/src/vs/workbench/contrib/notebook/browser/view/notebookCellList.ts @@ -260,7 +260,7 @@ export class NotebookCellList extends WorkbenchList implements ID const bottomModelIndex = this._viewModel!.getCellIndex(bottomElement); if (bottomModelIndex - topModelIndex === bottomViewIndex - topViewIndex) { - this.visibleRanges = [{ start: topModelIndex, end: bottomModelIndex }]; + this.visibleRanges = [{ start: topModelIndex, end: bottomModelIndex + 1 }]; } else { this.visibleRanges = this._getVisibleRangesFromIndex(topViewIndex, topModelIndex, bottomViewIndex, bottomModelIndex); } @@ -568,9 +568,9 @@ export class NotebookCellList extends WorkbenchList implements ID // no hidden area after it if (stack.length) { if (stack[stack.length - 1] === modelIndex - 1) { - ranges.push({ start: stack[stack.length - 1], end: modelIndex }); + ranges.push({ start: stack[stack.length - 1], end: modelIndex + 1 }); } else { - ranges.push({ start: stack[stack.length - 1], end: stack[stack.length - 1] }); + ranges.push({ start: stack[stack.length - 1], end: stack[stack.length - 1] + 1 }); } } @@ -581,9 +581,9 @@ export class NotebookCellList extends WorkbenchList implements ID // there are hidden ranges after it if (stack.length) { if (stack[stack.length - 1] === modelIndex - 1) { - ranges.push({ start: stack[stack.length - 1], end: modelIndex }); + ranges.push({ start: stack[stack.length - 1], end: modelIndex + 1 }); } else { - ranges.push({ start: stack[stack.length - 1], end: stack[stack.length - 1] }); + ranges.push({ start: stack[stack.length - 1], end: stack[stack.length - 1] + 1 }); } } @@ -594,7 +594,7 @@ export class NotebookCellList extends WorkbenchList implements ID } if (stack.length) { - ranges.push({ start: stack[stack.length - 1], end: stack[stack.length - 1] }); + ranges.push({ start: stack[stack.length - 1], end: stack[stack.length - 1] + 1 }); } return reduceCellRanges(ranges); diff --git a/src/vs/workbench/contrib/notebook/test/browser/notebookCellList.test.ts b/src/vs/workbench/contrib/notebook/test/browser/notebookCellList.test.ts index 8cb9c0908bf..f3e849fe8a6 100644 --- a/src/vs/workbench/contrib/notebook/test/browser/notebookCellList.test.ts +++ b/src/vs/workbench/contrib/notebook/test/browser/notebookCellList.test.ts @@ -317,4 +317,43 @@ suite('NotebookCellList', () => { assert.deepStrictEqual(cellList.scrollTop, 60); }); }); + + test('visibleRanges should be exclusive of end', async function () { + await withTestNotebook( + [ + ], + async (editor, viewModel) => { + const cellList = createNotebookCellList(instantiationService); + cellList.attachViewModel(viewModel); + + // render height 210, it can render 3 full cells and 1 partial cell + cellList.layout(100, 100); + + assert.deepStrictEqual(cellList.visibleRanges, []); + }); + }); + + test('visibleRanges should be exclusive of end 2', async function () { + await withTestNotebook( + [ + ['# header a', 'markdown', CellKind.Markup, [], {}], + ], + async (editor, viewModel) => { + viewModel.restoreEditorViewState({ + editingCells: [false], + editorViewStates: [null], + cellTotalHeights: [50], + collapsedInputCells: {}, + collapsedOutputCells: {}, + }); + + const cellList = createNotebookCellList(instantiationService); + cellList.attachViewModel(viewModel); + + // render height 210, it can render 3 full cells and 1 partial cell + cellList.layout(100, 100); + + assert.deepStrictEqual(cellList.visibleRanges, [{ start: 0, end: 1 }]); + }); + }); });