interactive window read notebook editor directly.

This commit is contained in:
rebornix 2021-09-01 17:54:31 -07:00
parent aad574a153
commit e160a16de6
3 changed files with 11 additions and 12 deletions

View file

@ -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;
}

View file

@ -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;

View file

@ -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;
}