diff --git a/src/vs/workbench/api/browser/mainThreadNotebookEditors.ts b/src/vs/workbench/api/browser/mainThreadNotebookEditors.ts index a1491d2e6ea..f9f94232feb 100644 --- a/src/vs/workbench/api/browser/mainThreadNotebookEditors.ts +++ b/src/vs/workbench/api/browser/mainThreadNotebookEditors.ts @@ -154,8 +154,7 @@ export class MainThreadNotebookEditors implements MainThreadNotebookEditorsShape if (!notebookEditor.hasModel()) { return; } - const viewModel = notebookEditor.viewModel; - const cell = viewModel.cellAt(range.start); + const cell = notebookEditor.cellAt(range.start); if (!cell) { return; } diff --git a/src/vs/workbench/contrib/interactive/browser/interactiveEditor.ts b/src/vs/workbench/contrib/interactive/browser/interactiveEditor.ts index bb8d0b21a6c..41b99129f49 100644 --- a/src/vs/workbench/contrib/interactive/browser/interactiveEditor.ts +++ b/src/vs/workbench/contrib/interactive/browser/interactiveEditor.ts @@ -401,10 +401,10 @@ export class InteractiveEditor extends EditorPane { */ #registerExecutionScrollListener(widget: NotebookEditorWidget & IActiveNotebookEditor) { this.#widgetDisposableStore.add(widget.textModel.onWillAddRemoveCells(e => { - const lastViewCell = widget.viewModel.viewCells[widget.viewModel.viewCells.length - 1]; + const lastViewCell = widget.cellAt(widget.getLength() - 1); // check if the last cell is at the bottom - if (this.#cellAtBottom(widget, lastViewCell)) { + if (lastViewCell && this.#cellAtBottom(widget, lastViewCell)) { this.#state = ScrollingState.StickyToBottom; } else { this.#state = ScrollingState.Initial; @@ -412,10 +412,10 @@ export class InteractiveEditor extends EditorPane { })); this.#widgetDisposableStore.add(widget.onDidScroll(() => { - const lastViewCell = widget.viewModel.viewCells[widget.viewModel.viewCells.length - 1]; + const lastViewCell = widget.cellAt(widget.getLength() - 1); // check if the last cell is at the bottom - if (this.#cellAtBottom(widget, lastViewCell)) { + if (lastViewCell && this.#cellAtBottom(widget, lastViewCell)) { this.#state = ScrollingState.StickyToBottom; } else { this.#state = ScrollingState.Initial; @@ -426,8 +426,8 @@ export class InteractiveEditor extends EditorPane { for (let i = 0; i < e.rawEvents.length; i++) { const event = e.rawEvents[i]; - if (event.kind === NotebookCellsChangeType.ModelChange && this.#notebookWidget.value?.viewModel) { - const lastViewCell = this.#notebookWidget.value.viewModel.viewCells[this.#notebookWidget.value.viewModel.viewCells.length - 1]; + if (event.kind === NotebookCellsChangeType.ModelChange && this.#notebookWidget.value?.hasModel()) { + const lastViewCell = this.#notebookWidget.value.cellAt(this.#notebookWidget.value.getLength() - 1); if (lastViewCell !== this.#lastCell) { this.#lastCellDisposable.clear(); this.#lastCell = lastViewCell; diff --git a/src/vs/workbench/contrib/notebook/browser/view/renderers/cellDnd.ts b/src/vs/workbench/contrib/notebook/browser/view/renderers/cellDnd.ts index c9dc2069e70..14d030064d8 100644 --- a/src/vs/workbench/contrib/notebook/browser/view/renderers/cellDnd.ts +++ b/src/vs/workbench/contrib/notebook/browser/view/renderers/cellDnd.ts @@ -307,7 +307,7 @@ export class CellDragAndDropController extends Disposable { dragHandle.setAttribute('draggable', 'true'); templateData.disposables.add(DOM.addDisposableListener(dragHandle, DOM.EventType.DRAG_END, () => { - if (!this.notebookEditor.notebookOptions.getLayoutConfiguration().dragAndDropEnabled || !!this.notebookEditor.viewModel?.options.isReadOnly) { + if (!this.notebookEditor.notebookOptions.getLayoutConfiguration().dragAndDropEnabled || !!this.notebookEditor.isReadOnly) { return; } @@ -321,7 +321,7 @@ export class CellDragAndDropController extends Disposable { return; } - if (!this.notebookEditor.notebookOptions.getLayoutConfiguration().dragAndDropEnabled || !!this.notebookEditor.viewModel?.options.isReadOnly) { + if (!this.notebookEditor.notebookOptions.getLayoutConfiguration().dragAndDropEnabled || !!this.notebookEditor.isReadOnly) { return; } @@ -338,7 +338,7 @@ export class CellDragAndDropController extends Disposable { } public startExplicitDrag(cell: ICellViewModel, _dragOffsetY: number) { - if (!this.notebookEditor.notebookOptions.getLayoutConfiguration().dragAndDropEnabled || !!this.notebookEditor.viewModel?.options.isReadOnly) { + if (!this.notebookEditor.notebookOptions.getLayoutConfiguration().dragAndDropEnabled || !!this.notebookEditor.isReadOnly) { return; } @@ -347,7 +347,7 @@ export class CellDragAndDropController extends Disposable { } public explicitDrag(cell: ICellViewModel, dragOffsetY: number) { - if (!this.notebookEditor.notebookOptions.getLayoutConfiguration().dragAndDropEnabled || !!this.notebookEditor.viewModel?.options.isReadOnly) { + if (!this.notebookEditor.notebookOptions.getLayoutConfiguration().dragAndDropEnabled || !!this.notebookEditor.isReadOnly) { return; }