diff --git a/src/vs/workbench/api/browser/mainThreadNotebookKernels.ts b/src/vs/workbench/api/browser/mainThreadNotebookKernels.ts index 7c13b1808eb..fefd0ed8f24 100644 --- a/src/vs/workbench/api/browser/mainThreadNotebookKernels.ts +++ b/src/vs/workbench/api/browser/mainThreadNotebookKernels.ts @@ -21,7 +21,7 @@ import { CellExecuteEditDto, ExtHostContext, ExtHostNotebookKernelsShape, IExtHo abstract class MainThreadKernel implements INotebookKernel { private readonly _onDidChange = new Emitter(); - private readonly preloads: { uri: URI, provides: string[] }[]; + private readonly preloads: { uri: URI, provides: string[]; }[]; readonly onDidChange: Event = this._onDidChange.event; readonly id: string; @@ -128,7 +128,7 @@ export class MainThreadNotebookKernels implements MainThreadNotebookKernelsShape if (!editor.hasModel()) { return; } - const { selected } = this._notebookKernelService.getMatchingKernel(editor.viewModel.notebookDocument); + const { selected } = this._notebookKernelService.getMatchingKernel(editor.textModel); if (!selected) { return; } @@ -158,7 +158,7 @@ export class MainThreadNotebookKernels implements MainThreadNotebookKernelsShape if (!editor.hasModel()) { continue; } - if (this._notebookKernelService.getMatchingKernel(editor.viewModel.notebookDocument).selected !== kernel) { + if (this._notebookKernelService.getMatchingKernel(editor.textModel).selected !== kernel) { // different kernel continue; } diff --git a/src/vs/workbench/contrib/notebook/browser/contrib/cellOperations/cellOperations.ts b/src/vs/workbench/contrib/notebook/browser/contrib/cellOperations/cellOperations.ts index ffdc4b2e985..ee36707bee7 100644 --- a/src/vs/workbench/contrib/notebook/browser/contrib/cellOperations/cellOperations.ts +++ b/src/vs/workbench/contrib/notebook/browser/contrib/cellOperations/cellOperations.ts @@ -82,10 +82,11 @@ registerAction2(class extends NotebookCellAction { }); export async function moveCellRange(context: INotebookCellActionContext, direction: 'up' | 'down'): Promise { - const viewModel = context.notebookEditor.viewModel; - if (!viewModel) { + if (!context.notebookEditor.hasModel()) { return; } + const viewModel = context.notebookEditor.viewModel; + const textModel = context.notebookEditor.textModel; if (viewModel.options.isReadOnly) { return; @@ -107,7 +108,7 @@ export async function moveCellRange(context: INotebookCellActionContext, directi const finalSelection = { start: range.start - 1, end: range.end - 1 }; const focus = context.notebookEditor.getFocus(); const newFocus = cellRangeContains(range, focus) ? { start: focus.start - 1, end: focus.end - 1 } : { start: range.start - 1, end: range.start }; - viewModel.notebookDocument.applyEdits([ + textModel.applyEdits([ { editType: CellEditType.Move, index: indexAbove, @@ -135,7 +136,7 @@ export async function moveCellRange(context: INotebookCellActionContext, directi const focus = context.notebookEditor.getFocus(); const newFocus = cellRangeContains(range, focus) ? { start: focus.start + 1, end: focus.end + 1 } : { start: range.start + 1, end: range.start + 2 }; - viewModel.notebookDocument.applyEdits([ + textModel.applyEdits([ { editType: CellEditType.Move, index: indexBelow, @@ -202,10 +203,11 @@ registerAction2(class extends NotebookCellAction { }); export async function copyCellRange(context: INotebookCellActionContext, direction: 'up' | 'down'): Promise { - const viewModel = context.notebookEditor.viewModel; - if (!viewModel) { + if (!context.notebookEditor.hasModel()) { return; } + const viewModel = context.notebookEditor.viewModel; + const textModel = context.notebookEditor.textModel; if (viewModel.options.isReadOnly) { return; @@ -231,7 +233,7 @@ export async function copyCellRange(context: INotebookCellActionContext, directi // insert up, without changing focus and selections const focus = viewModel.getFocus(); const selections = viewModel.getSelections(); - viewModel.notebookDocument.applyEdits([ + textModel.applyEdits([ { editType: CellEditType.Replace, index: range.end, @@ -255,7 +257,7 @@ export async function copyCellRange(context: INotebookCellActionContext, directi const countDelta = newCells.length; const newFocus = context.ui ? focus : { start: focus.start + countDelta, end: focus.end + countDelta }; const newSelections = context.ui ? selections : [{ start: range.start + countDelta, end: range.end + countDelta }]; - viewModel.notebookDocument.applyEdits([ + textModel.applyEdits([ { editType: CellEditType.Replace, index: range.end, @@ -310,7 +312,7 @@ registerAction2(class extends NotebookCellAction { } }); -export async function joinNotebookCells(viewModel: NotebookViewModel, range: ICellRange, direction: 'above' | 'below', constraint?: CellKind): Promise<{ edits: ResourceEdit[], cell: ICellViewModel, endFocus: ICellRange, endSelections: ICellRange[] } | null> { +export async function joinNotebookCells(viewModel: NotebookViewModel, range: ICellRange, direction: 'above' | 'below', constraint?: CellKind): Promise<{ edits: ResourceEdit[], cell: ICellViewModel, endFocus: ICellRange, endSelections: ICellRange[]; } | null> { if (!viewModel || viewModel.options.isReadOnly) { return null; } diff --git a/src/vs/workbench/contrib/notebook/browser/contrib/cellOperations/test/cellOperations.test.ts b/src/vs/workbench/contrib/notebook/browser/contrib/cellOperations/test/cellOperations.test.ts index 8396257a6fc..fe8d8b22420 100644 --- a/src/vs/workbench/contrib/notebook/browser/contrib/cellOperations/test/cellOperations.test.ts +++ b/src/vs/workbench/contrib/notebook/browser/contrib/cellOperations/test/cellOperations.test.ts @@ -174,15 +174,14 @@ suite('CellOperations', () => { ['var b = 2;', 'javascript', CellKind.Code, [], {}], ['var c = 3;', 'javascript', CellKind.Code, [], {}] ], - async (editor, accessor) => { - const viewModel = editor.viewModel; + async (editor, viewModel, accessor) => { viewModel.updateSelectionsState({ kind: SelectionStateType.Index, focus: { start: 3, end: 4 }, selections: [{ start: 3, end: 4 }] }); - const ret = await joinNotebookCells(editor.viewModel, { start: 3, end: 4 }, 'below'); + const ret = await joinNotebookCells(viewModel, { start: 3, end: 4 }, 'below'); assert.strictEqual(ret?.edits.length, 2); assert.deepStrictEqual(ret?.edits[0], new ResourceTextEdit(viewModel.cellAt(3)!.uri, { range: new Range(1, 11, 1, 11), text: viewModel.cellAt(4)!.textBuffer.getEOL() + 'var c = 3;' })); - assert.deepStrictEqual(ret?.edits[1], new ResourceNotebookCellEdit(viewModel.notebookDocument.uri, + assert.deepStrictEqual(ret?.edits[1], new ResourceNotebookCellEdit(editor.textModel.uri, { editType: CellEditType.Replace, index: 4, @@ -202,15 +201,14 @@ suite('CellOperations', () => { ['var b = 2;', 'javascript', CellKind.Code, [], {}], ['var c = 3;', 'javascript', CellKind.Code, [], {}] ], - async (editor, accessor) => { - const viewModel = editor.viewModel; + async (editor, viewModel, accessor) => { viewModel.updateSelectionsState({ kind: SelectionStateType.Index, focus: { start: 3, end: 4 }, selections: [{ start: 3, end: 4 }] }); - const ret = await joinNotebookCells(editor.viewModel, { start: 4, end: 5 }, 'above'); + const ret = await joinNotebookCells(viewModel, { start: 4, end: 5 }, 'above'); assert.strictEqual(ret?.edits.length, 2); assert.deepStrictEqual(ret?.edits[0], new ResourceTextEdit(viewModel.cellAt(3)!.uri, { range: new Range(1, 11, 1, 11), text: viewModel.cellAt(4)!.textBuffer.getEOL() + 'var c = 3;' })); - assert.deepStrictEqual(ret?.edits[1], new ResourceNotebookCellEdit(viewModel.notebookDocument.uri, + assert.deepStrictEqual(ret?.edits[1], new ResourceNotebookCellEdit(editor.textModel.uri, { editType: CellEditType.Replace, index: 4, @@ -228,15 +226,14 @@ suite('CellOperations', () => { ['var b = 2;', 'javascript', CellKind.Code, [], {}], ['var c = 3;', 'javascript', CellKind.Code, [], {}] ], - async (editor, accessor) => { - const viewModel = editor.viewModel; + async (editor, viewModel, accessor) => { viewModel.updateSelectionsState({ kind: SelectionStateType.Index, focus: { start: 1, end: 2 }, selections: [{ start: 0, end: 2 }] }); - const ret = await joinNotebookCells(editor.viewModel, { start: 0, end: 2 }, 'below'); + const ret = await joinNotebookCells(viewModel, { start: 0, end: 2 }, 'below'); assert.strictEqual(ret?.edits.length, 2); assert.deepStrictEqual(ret?.edits[0], new ResourceTextEdit(viewModel.cellAt(0)!.uri, { range: new Range(1, 11, 1, 11), text: viewModel.cellAt(1)!.textBuffer.getEOL() + 'var b = 2;' + viewModel.cellAt(2)!.textBuffer.getEOL() + 'var c = 3;' })); - assert.deepStrictEqual(ret?.edits[1], new ResourceNotebookCellEdit(viewModel.notebookDocument.uri, + assert.deepStrictEqual(ret?.edits[1], new ResourceNotebookCellEdit(editor.textModel.uri, { editType: CellEditType.Replace, index: 1, @@ -254,15 +251,14 @@ suite('CellOperations', () => { ['var b = 2;', 'javascript', CellKind.Code, [], {}], ['var c = 3;', 'javascript', CellKind.Code, [], {}] ], - async (editor, accessor) => { - const viewModel = editor.viewModel; + async (editor, viewModel, accessor) => { viewModel.updateSelectionsState({ kind: SelectionStateType.Index, focus: { start: 2, end: 3 }, selections: [{ start: 1, end: 3 }] }); const ret = await joinNotebookCells(editor.viewModel, { start: 1, end: 3 }, 'above'); assert.strictEqual(ret?.edits.length, 2); assert.deepStrictEqual(ret?.edits[0], new ResourceTextEdit(viewModel.cellAt(0)!.uri, { range: new Range(1, 11, 1, 11), text: viewModel.cellAt(1)!.textBuffer.getEOL() + 'var b = 2;' + viewModel.cellAt(2)!.textBuffer.getEOL() + 'var c = 3;' })); - assert.deepStrictEqual(ret?.edits[1], new ResourceNotebookCellEdit(viewModel.notebookDocument.uri, + assert.deepStrictEqual(ret?.edits[1], new ResourceNotebookCellEdit(editor.textModel.uri, { editType: CellEditType.Replace, index: 1, diff --git a/src/vs/workbench/contrib/notebook/browser/contrib/coreActions.ts b/src/vs/workbench/contrib/notebook/browser/contrib/coreActions.ts index 60e34f9c059..bfed6ef00ef 100644 --- a/src/vs/workbench/contrib/notebook/browser/contrib/coreActions.ts +++ b/src/vs/workbench/contrib/notebook/browser/contrib/coreActions.ts @@ -973,7 +973,7 @@ export async function changeCellToKind(kind: CellKind, context: INotebookCellAct language = availableLanguages[0] ?? 'plaintext'; } - notebookEditor.viewModel.notebookDocument.applyEdits([ + notebookEditor.textModel.applyEdits([ { editType: CellEditType.Replace, index: idx, @@ -1464,21 +1464,21 @@ registerAction2(class ClearCellOutputsAction extends NotebookCellAction { async runWithContext(accessor: ServicesAccessor, context: INotebookCellActionContext): Promise { const editor = context.notebookEditor; - if (!editor.viewModel || !editor.viewModel.length) { + if (!editor.hasModel() || !editor.textModel.length) { return; } const cell = context.cell; - const index = editor.viewModel.notebookDocument.cells.indexOf(cell.model); + const index = editor.textModel.cells.indexOf(cell.model); if (index < 0) { return; } - editor.viewModel.notebookDocument.applyEdits([{ editType: CellEditType.Output, index, outputs: [] }], true, undefined, () => undefined, undefined); + editor.textModel.applyEdits([{ editType: CellEditType.Output, index, outputs: [] }], true, undefined, () => undefined, undefined); if (context.cell.internalMetadata.runState !== NotebookCellExecutionState.Executing) { - context.notebookEditor.viewModel.notebookDocument.applyEdits([{ + context.notebookEditor.textModel.applyEdits([{ editType: CellEditType.PartialInternalMetadata, index, internalMetadata: { runState: null, runStartTime: null, @@ -1695,16 +1695,16 @@ registerAction2(class ClearAllCellOutputsAction extends NotebookAction { async runWithContext(accessor: ServicesAccessor, context: INotebookActionContext): Promise { const editor = context.notebookEditor; - if (!editor.viewModel || !editor.viewModel.length) { + if (!editor.hasModel() || !editor.textModel.length) { return; } - editor.viewModel.notebookDocument.applyEdits( - editor.viewModel.notebookDocument.cells.map((cell, index) => ({ + editor.textModel.applyEdits( + editor.textModel.cells.map((cell, index) => ({ editType: CellEditType.Output, index, outputs: [] })), true, undefined, () => undefined, undefined); - const clearExecutionMetadataEdits = editor.viewModel.notebookDocument.cells.map((cell, index) => { + const clearExecutionMetadataEdits = editor.textModel.cells.map((cell, index) => { if (cell.internalMetadata.runState !== NotebookCellExecutionState.Executing) { return { editType: CellEditType.PartialInternalMetadata, index, internalMetadata: { @@ -1721,7 +1721,7 @@ registerAction2(class ClearAllCellOutputsAction extends NotebookAction { } }).filter(edit => !!edit) as ICellEditOperation[]; if (clearExecutionMetadataEdits.length) { - context.notebookEditor.viewModel.notebookDocument.applyEdits(clearExecutionMetadataEdits, true, undefined, () => undefined, undefined); + context.notebookEditor.textModel.applyEdits(clearExecutionMetadataEdits, true, undefined, () => undefined, undefined); } } }); diff --git a/src/vs/workbench/contrib/notebook/browser/contrib/undoRedo/test/notebookUndoRedo.test.ts b/src/vs/workbench/contrib/notebook/browser/contrib/undoRedo/test/notebookUndoRedo.test.ts index a9b0869f105..8b9239eb0a3 100644 --- a/src/vs/workbench/contrib/notebook/browser/contrib/undoRedo/test/notebookUndoRedo.test.ts +++ b/src/vs/workbench/contrib/notebook/browser/contrib/undoRedo/test/notebookUndoRedo.test.ts @@ -21,7 +21,7 @@ suite('Notebook Undo/Redo', () => { assert.strictEqual(viewModel.getVersionId(), 0); assert.strictEqual(viewModel.getAlternativeId(), '0_0,1;1,1'); - viewModel.notebookDocument.applyEdits([{ + editor.textModel.applyEdits([{ editType: CellEditType.Replace, index: 0, count: 2, cells: [] }], true, undefined, () => undefined, undefined, true); assert.strictEqual(viewModel.length, 0); @@ -38,7 +38,7 @@ suite('Notebook Undo/Redo', () => { assert.strictEqual(viewModel.getVersionId(), 3); assert.strictEqual(viewModel.getAlternativeId(), '1_'); - viewModel.notebookDocument.applyEdits([{ + editor.textModel.applyEdits([{ editType: CellEditType.Replace, index: 0, count: 0, cells: [ new TestCell(viewModel.viewType, 3, '# header 2', 'markdown', CellKind.Code, [], modeService), ] @@ -61,12 +61,12 @@ suite('Notebook Undo/Redo', () => { ], async (editor, viewModel, accessor) => { const modeService = accessor.get(IModeService); - viewModel.notebookDocument.applyEdits([{ + editor.textModel.applyEdits([{ editType: CellEditType.Replace, index: 0, count: 2, cells: [] }], true, undefined, () => undefined, undefined, true); assert.doesNotThrow(() => { - viewModel.notebookDocument.applyEdits([{ + editor.textModel.applyEdits([{ editType: CellEditType.Replace, index: 0, count: 2, cells: [ new TestCell(viewModel.viewType, 3, '# header 2', 'markdown', CellKind.Code, [], modeService), ] @@ -84,7 +84,7 @@ suite('Notebook Undo/Redo', () => { ], async (editor) => { const viewModel = editor.viewModel; - viewModel.notebookDocument.applyEdits([{ + editor.textModel.applyEdits([{ editType: CellEditType.Replace, index: 1, count: 2, cells: [] }], true, undefined, () => undefined, undefined, true); @@ -103,11 +103,11 @@ suite('Notebook Undo/Redo', () => { ], async (editor, viewModel, accessor) => { const modeService = accessor.get(IModeService); - viewModel.notebookDocument.applyEdits([{ + editor.textModel.applyEdits([{ editType: CellEditType.Replace, index: 0, count: 2, cells: [] }], true, undefined, () => undefined, undefined, true); - viewModel.notebookDocument.applyEdits([{ + editor.textModel.applyEdits([{ editType: CellEditType.Replace, index: 0, count: 2, cells: [ new TestCell(viewModel.viewType, 3, '# header 2', 'markdown', CellKind.Code, [], modeService), ] @@ -119,7 +119,7 @@ suite('Notebook Undo/Redo', () => { await viewModel.undo(); assert.deepStrictEqual(viewModel.length, 2); - viewModel.notebookDocument.applyEdits([{ + editor.textModel.applyEdits([{ editType: CellEditType.Replace, index: 1, count: 2, cells: [] }], true, undefined, () => undefined, undefined, true); assert.deepStrictEqual(viewModel.length, 1); diff --git a/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts b/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts index 778d884b9dc..bf41e656056 100644 --- a/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts +++ b/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts @@ -1858,7 +1858,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor if (!this.hasModel()) { return; } - const { selected } = this.notebookKernelService.getMatchingKernel(this.viewModel.notebookDocument); + const { selected } = this.notebookKernelService.getMatchingKernel(this.textModel); if (!this._webview?.isResolved()) { await this._resolveWebview(); } @@ -1866,7 +1866,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor } get activeKernel() { - return this.viewModel && this._kernelManger.getSelectedOrSuggestedKernel(this.viewModel.notebookDocument); + return this.textModel && this._kernelManger.getSelectedOrSuggestedKernel(this.textModel); } async cancelNotebookCells(cells?: Iterable): Promise { @@ -1876,7 +1876,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor if (!cells) { cells = this.viewModel.viewCells; } - return this._kernelManger.cancelNotebookCells(this.viewModel.notebookDocument, cells); + return this._kernelManger.cancelNotebookCells(this.textModel, cells); } async executeNotebookCells(cells?: Iterable): Promise { @@ -1886,7 +1886,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor if (!cells) { cells = this.viewModel.viewCells; } - return this._kernelManger.executeNotebookCells(this.viewModel.notebookDocument, cells); + return this._kernelManger.executeNotebookCells(this.textModel, cells); } //#endregion diff --git a/src/vs/workbench/contrib/notebook/browser/notebookEditorWidgetContextKeys.ts b/src/vs/workbench/contrib/notebook/browser/notebookEditorWidgetContextKeys.ts index c2cc2c763ab..dc45f1fc204 100644 --- a/src/vs/workbench/contrib/notebook/browser/notebookEditorWidgetContextKeys.ts +++ b/src/vs/workbench/contrib/notebook/browser/notebookEditorWidgetContextKeys.ts @@ -138,7 +138,7 @@ export class NotebookEditorContextKeys { return; } - const { selected, all } = this._notebookKernelService.getMatchingKernel(this._editor.viewModel.notebookDocument); + const { selected, all } = this._notebookKernelService.getMatchingKernel(this._editor.textModel); this._notebookKernelCount.set(all.length); this._interruptibleKernel.set(selected?.implementsInterrupt ?? false); this._notebookKernelSelected.set(Boolean(selected)); diff --git a/src/vs/workbench/contrib/notebook/test/cellOutput.test.ts b/src/vs/workbench/contrib/notebook/test/cellOutput.test.ts index 82cdaed81b6..b509ef2185d 100644 --- a/src/vs/workbench/contrib/notebook/test/cellOutput.test.ts +++ b/src/vs/workbench/contrib/notebook/test/cellOutput.test.ts @@ -87,8 +87,7 @@ suite('NotebookViewModel Outputs', async () => { { outputId: 'output_id_3', outputs: [{ mime: 'application/vnd.code.notebook.stdout', data: valueBytesFromString('3') }] }, ], {}] ], - (editor, accessor) => { - const viewModel = editor.viewModel; + (editor, viewModel, accessor) => { const container = new CellOutputContainer(editor, viewModel.viewCells[0] as CodeCellViewModel, { outputContainer: document.createElement('div'), outputShowMoreContainer: document.createElement('div'), @@ -108,7 +107,7 @@ suite('NotebookViewModel Outputs', async () => { assert.notStrictEqual(container.renderedOutputEntries[1].element.innerContainer, container.renderedOutputEntries[2].element.innerContainer); assert.notStrictEqual(container.renderedOutputEntries[2].element.innerContainer, container.renderedOutputEntries[3].element.innerContainer); - viewModel.notebookDocument.applyEdits([{ + editor.textModel.applyEdits([{ index: 0, editType: CellEditType.Output, outputs: [ @@ -127,7 +126,7 @@ suite('NotebookViewModel Outputs', async () => { // last one is merged with previous one assert.strictEqual(container.renderedOutputEntries[3].element.innerContainer, container.renderedOutputEntries[4].element.innerContainer); - viewModel.notebookDocument.applyEdits([{ + editor.textModel.applyEdits([{ index: 0, editType: CellEditType.Output, outputs: [ @@ -166,8 +165,7 @@ suite('NotebookViewModel Outputs', async () => { { outputId: 'output_id_6', outputs: [{ mime: 'application/vnd.code.notebook.stdout', data: valueBytesFromString('6') }] }, ], {}] ], - (editor, accessor) => { - const viewModel = editor.viewModel; + (editor, viewModel, accessor) => { const container = new CellOutputContainer(editor, viewModel.viewCells[0] as CodeCellViewModel, { outputContainer: document.createElement('div'), outputShowMoreContainer: document.createElement('div'), @@ -191,7 +189,7 @@ suite('NotebookViewModel Outputs', async () => { assert.strictEqual(container.renderedOutputEntries[3].element.innerContainer.innerText, '45'); - viewModel.notebookDocument.applyEdits([{ + editor.textModel.applyEdits([{ index: 0, editType: CellEditType.Output, outputs: [ diff --git a/src/vs/workbench/contrib/notebook/test/notebookSelection.test.ts b/src/vs/workbench/contrib/notebook/test/notebookSelection.test.ts index a4ff8d8428d..0580763ed93 100644 --- a/src/vs/workbench/contrib/notebook/test/notebookSelection.test.ts +++ b/src/vs/workbench/contrib/notebook/test/notebookSelection.test.ts @@ -200,7 +200,7 @@ suite('NotebookCellList focus/selection', () => { assert.strictEqual(cellList.getModelIndex2(0), 0); assert.strictEqual(cellList.getModelIndex2(1), 2); - viewModel.notebookDocument.applyEdits([{ + editor.textModel.applyEdits([{ editType: CellEditType.Replace, index: 0, count: 2, cells: [] }], true, undefined, () => undefined, undefined, false); viewModel.updateFoldingRanges(foldingModel.regions); @@ -210,7 +210,7 @@ suite('NotebookCellList focus/selection', () => { assert.strictEqual(cellList.getModelIndex2(1), 3); // mimic undo - viewModel.notebookDocument.applyEdits([{ + editor.textModel.applyEdits([{ editType: CellEditType.Replace, index: 0, count: 0, cells: [ new TestCell(viewModel.viewType, 7, '# header f', 'markdown', CellKind.Code, [], modeService), new TestCell(viewModel.viewType, 8, 'var g = 5;', 'javascript', CellKind.Code, [], modeService) @@ -314,7 +314,7 @@ suite('NotebookCellList focus/selection', () => { async (editor) => { const viewModel = editor.viewModel; viewModel.updateSelectionsState({ kind: SelectionStateType.Index, focus: { start: 1, end: 2 }, selections: [{ start: 1, end: 2 }] }); - viewModel.notebookDocument.applyEdits([{ + editor.textModel.applyEdits([{ editType: CellEditType.Replace, index: 1, count: 1, diff --git a/src/vs/workbench/contrib/notebook/test/notebookTextModel.test.ts b/src/vs/workbench/contrib/notebook/test/notebookTextModel.test.ts index a20405794b5..d252f016f14 100644 --- a/src/vs/workbench/contrib/notebook/test/notebookTextModel.test.ts +++ b/src/vs/workbench/contrib/notebook/test/notebookTextModel.test.ts @@ -25,7 +25,7 @@ suite('NotebookTextModel', () => { ], (editor) => { const viewModel = editor.viewModel; - const textModel = editor.viewModel.notebookDocument; + const textModel = editor.textModel; textModel.applyEdits([ { editType: CellEditType.Replace, index: 1, count: 0, cells: [new TestCell(viewModel.viewType, 5, 'var e = 5;', 'javascript', CellKind.Code, [], modeService)] }, { editType: CellEditType.Replace, index: 3, count: 0, cells: [new TestCell(viewModel.viewType, 6, 'var f = 6;', 'javascript', CellKind.Code, [], modeService)] }, @@ -49,7 +49,7 @@ suite('NotebookTextModel', () => { ], (editor) => { const viewModel = editor.viewModel; - const textModel = editor.viewModel.notebookDocument; + const textModel = editor.textModel; textModel.applyEdits([ { editType: CellEditType.Replace, index: 1, count: 0, cells: [new TestCell(viewModel.viewType, 5, 'var e = 5;', 'javascript', CellKind.Code, [], modeService)] }, { editType: CellEditType.Replace, index: 1, count: 0, cells: [new TestCell(viewModel.viewType, 6, 'var f = 6;', 'javascript', CellKind.Code, [], modeService)] }, @@ -72,7 +72,7 @@ suite('NotebookTextModel', () => { ['var d = 4;', 'javascript', CellKind.Code, [], {}] ], (editor) => { - const textModel = editor.viewModel.notebookDocument; + const textModel = editor.textModel; textModel.applyEdits([ { editType: CellEditType.Replace, index: 1, count: 1, cells: [] }, { editType: CellEditType.Replace, index: 3, count: 1, cells: [] }, @@ -94,7 +94,7 @@ suite('NotebookTextModel', () => { ], (editor) => { const viewModel = editor.viewModel; - const textModel = editor.viewModel.notebookDocument; + const textModel = editor.textModel; textModel.applyEdits([ { editType: CellEditType.Replace, index: 1, count: 1, cells: [] }, { editType: CellEditType.Replace, index: 3, count: 0, cells: [new TestCell(viewModel.viewType, 5, 'var e = 5;', 'javascript', CellKind.Code, [], modeService)] }, @@ -117,7 +117,7 @@ suite('NotebookTextModel', () => { ], (editor) => { const viewModel = editor.viewModel; - const textModel = editor.viewModel.notebookDocument; + const textModel = editor.textModel; textModel.applyEdits([ { editType: CellEditType.Replace, index: 1, count: 1, cells: [] }, { editType: CellEditType.Replace, index: 1, count: 0, cells: [new TestCell(viewModel.viewType, 5, 'var e = 5;', 'javascript', CellKind.Code, [], modeService)] }, @@ -141,7 +141,7 @@ suite('NotebookTextModel', () => { ], (editor) => { const viewModel = editor.viewModel; - const textModel = editor.viewModel.notebookDocument; + const textModel = editor.textModel; textModel.applyEdits([ { editType: CellEditType.Replace, index: 1, count: 1, cells: [new TestCell(viewModel.viewType, 5, 'var e = 5;', 'javascript', CellKind.Code, [], modeService)] }, ], true, undefined, () => undefined, undefined); @@ -160,7 +160,7 @@ suite('NotebookTextModel', () => { ['var a = 1;', 'javascript', CellKind.Code, [], {}], ], (editor) => { - const textModel = editor.viewModel.notebookDocument; + const textModel = editor.textModel; // invalid index 1 assert.throws(() => { @@ -233,7 +233,7 @@ suite('NotebookTextModel', () => { ['var a = 1;', 'javascript', CellKind.Code, [], {}], ], (editor) => { - const textModel = editor.viewModel.notebookDocument; + const textModel = editor.textModel; // append textModel.applyEdits([ @@ -272,7 +272,7 @@ suite('NotebookTextModel', () => { ['var a = 1;', 'javascript', CellKind.Code, [], {}], ], (editor) => { - const textModel = editor.viewModel.notebookDocument; + const textModel = editor.textModel; // invalid index 1 assert.throws(() => { @@ -316,7 +316,7 @@ suite('NotebookTextModel', () => { ['var a = 1;', 'javascript', CellKind.Code, [], {}], ], (editor) => { - const textModel = editor.viewModel.notebookDocument; + const textModel = editor.textModel; textModel.applyEdits([{ index: 0, @@ -346,7 +346,7 @@ suite('NotebookTextModel', () => { ], (editor) => { const viewModel = editor.viewModel; - const textModel = editor.viewModel.notebookDocument; + const textModel = editor.textModel; let changeEvent: NotebookTextModelChangedEvent | undefined = undefined; const eventListener = textModel.onDidChangeContent(e => { changeEvent = e; @@ -381,7 +381,7 @@ suite('NotebookTextModel', () => { ['var d = 4;', 'javascript', CellKind.Code, [], {}] ], (editor) => { - const textModel = editor.viewModel.notebookDocument; + const textModel = editor.textModel; let changeEvent: NotebookTextModelChangedEvent | undefined = undefined; const eventListener = textModel.onDidChangeContent(e => { changeEvent = e; @@ -411,7 +411,7 @@ suite('NotebookTextModel', () => { await withTestNotebook([ ['var a = 1;', 'javascript', CellKind.Code, [], {}] ], (editor) => { - const model = editor.viewModel.notebookDocument; + const model = editor.textModel; assert.strictEqual(model.cells.length, 1); assert.strictEqual(model.cells[0].outputs.length, 0); @@ -447,7 +447,7 @@ suite('NotebookTextModel', () => { ['var a = 1;', 'javascript', CellKind.Code, [], {}], ['var b = 2;', 'javascript', CellKind.Code, [], {}] ], (editor) => { - const model = editor.viewModel.notebookDocument; + const model = editor.textModel; let event: NotebookTextModelChangedEvent | undefined; @@ -520,7 +520,7 @@ suite('NotebookTextModel', () => { assert.strictEqual(editor.viewModel.getVersionId(), 0); const firstAltVersion = '0_0,1;1,1'; assert.strictEqual(editor.viewModel.getAlternativeId(), firstAltVersion); - editor.viewModel.notebookDocument.applyEdits([ + editor.textModel.applyEdits([ { index: 0, editType: CellEditType.Metadata, @@ -543,7 +543,7 @@ suite('NotebookTextModel', () => { assert.notStrictEqual(editor.viewModel.getAlternativeId(), firstAltVersion); assert.strictEqual(editor.viewModel.getAlternativeId(), secondAltVersion); - editor.viewModel.notebookDocument.applyEdits([ + editor.textModel.applyEdits([ { index: 1, editType: CellEditType.Metadata, @@ -567,7 +567,7 @@ suite('NotebookTextModel', () => { ['var a = 1;', 'javascript', CellKind.Code, [{ outputId: 'i42', outputs: [{ mime: 'm/ime', data: valueBytesFromString('test') }] }], {}] ], async (editor) => { - const notebook = editor.viewModel.notebookDocument; + const notebook = editor.textModel; assert.strictEqual(notebook.cells[0].outputs.length, 1); assert.strictEqual(notebook.cells[0].outputs[0].outputs.length, 1); @@ -585,7 +585,7 @@ suite('NotebookTextModel', () => { } ]; - editor.viewModel.notebookDocument.applyEdits(edits, true, undefined, () => undefined, undefined); + editor.textModel.applyEdits(edits, true, undefined, () => undefined, undefined); assert.strictEqual(notebook.cells[0].outputs.length, 1); assert.strictEqual(notebook.cells[0].outputs[0].outputs.length, 2); @@ -598,7 +598,7 @@ suite('NotebookTextModel', () => { ['var b = 2;', 'javascript', CellKind.Code, [{ outputId: 'i43', outputs: [{ mime: 'm/ime', data: valueBytesFromString('test') }] }], {}], ['var c = 3;', 'javascript', CellKind.Code, [{ outputId: 'i44', outputs: [{ mime: 'm/ime', data: valueBytesFromString('test') }] }], {}] ], async (editor) => { - const notebook = editor.viewModel.notebookDocument; + const notebook = editor.textModel; const edits: ICellEditOperation[] = [ { @@ -615,7 +615,7 @@ suite('NotebookTextModel', () => { } ]; - editor.viewModel.notebookDocument.applyEdits(edits, true, undefined, () => undefined, undefined); + editor.textModel.applyEdits(edits, true, undefined, () => undefined, undefined); assert.strictEqual(notebook.cells.length, 2); assert.strictEqual(notebook.cells[0].outputs.length, 0); @@ -631,7 +631,7 @@ suite('NotebookTextModel', () => { ['var b = 2;', 'javascript', CellKind.Code, [{ outputId: 'i43', outputs: [{ mime: 'm/ime', data: valueBytesFromString('test') }] }], {}], ['var c = 3;', 'javascript', CellKind.Code, [{ outputId: 'i44', outputs: [{ mime: 'm/ime', data: valueBytesFromString('test') }] }], {}] ], async (editor) => { - const notebook = editor.viewModel.notebookDocument; + const notebook = editor.textModel; const edits: ICellEditOperation[] = [ { @@ -651,7 +651,7 @@ suite('NotebookTextModel', () => { } ]; - editor.viewModel.notebookDocument.applyEdits(edits, true, undefined, () => undefined, undefined); + editor.textModel.applyEdits(edits, true, undefined, () => undefined, undefined); assert.strictEqual(notebook.cells.length, 2); assert.strictEqual(notebook.cells[0].outputs.length, 1); @@ -664,7 +664,7 @@ suite('NotebookTextModel', () => { await withTestNotebook([ ['var a = 1;', 'javascript', CellKind.Code, [], {}] ], (editor) => { - const model = editor.viewModel.notebookDocument; + const model = editor.textModel; assert.strictEqual(model.cells.length, 1); assert.strictEqual(model.cells[0].outputs.length, 0);