diff --git a/src/vs/workbench/api/browser/mainThreadNotebookDocumentsAndEditors.ts b/src/vs/workbench/api/browser/mainThreadNotebookDocumentsAndEditors.ts index 0e0e867b7f5..d51940002c3 100644 --- a/src/vs/workbench/api/browser/mainThreadNotebookDocumentsAndEditors.ts +++ b/src/vs/workbench/api/browser/mainThreadNotebookDocumentsAndEditors.ts @@ -237,7 +237,7 @@ export class MainThreadNotebooksAndEditors { return { id: add.getId(), - documentUri: add.viewModel.uri, + documentUri: add.textModel.uri, selections: add.getSelections(), visibleRanges: add.visibleRanges, viewColumn: pane && editorGroupToViewColumn(this._editorGroupService, pane.group) 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 fe8d8b22420..2d1b1fc422d 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 @@ -23,8 +23,7 @@ suite('CellOperations', () => { ['var b = 2;', 'javascript', CellKind.Code, [], {}], ['var c = 3;', 'javascript', CellKind.Code, [], {}] ], - async (editor) => { - const viewModel = editor.viewModel; + async (editor, viewModel) => { viewModel.updateSelectionsState({ kind: SelectionStateType.Index, focus: { start: 1, end: 2 }, selections: [{ start: 1, end: 2 }] }); await moveCellRange({ notebookEditor: editor, cell: viewModel.cellAt(1)! }, 'down'); assert.strictEqual(viewModel.cellAt(2)?.getText(), 'var b = 1;'); @@ -40,8 +39,7 @@ suite('CellOperations', () => { ['var b = 2;', 'javascript', CellKind.Code, [], {}], ['var c = 3;', 'javascript', CellKind.Code, [], {}] ], - async (editor) => { - const viewModel = editor.viewModel; + async (editor, viewModel) => { viewModel.updateSelectionsState({ kind: SelectionStateType.Index, focus: { start: 1, end: 2 }, selections: [{ start: 0, end: 2 }] }); await moveCellRange({ notebookEditor: editor, cell: viewModel.cellAt(1)! }, 'down'); assert.strictEqual(viewModel.cellAt(0)?.getText(), '# header b'); @@ -59,8 +57,7 @@ suite('CellOperations', () => { ['var b = 2;', 'javascript', CellKind.Code, [], {}], ['var c = 3;', 'javascript', CellKind.Code, [], {}] ], - async (editor) => { - const viewModel = editor.viewModel; + async (editor, viewModel) => { const foldingModel = new FoldingModel(); foldingModel.attachViewModel(viewModel); updateFoldingStateAtIndex(foldingModel, 0, true); @@ -86,8 +83,7 @@ suite('CellOperations', () => { ['var b = 2;', 'javascript', CellKind.Code, [], {}], ['var c = 3;', 'javascript', CellKind.Code, [], {}] ], - async (editor) => { - const viewModel = editor.viewModel; + async (editor, viewModel) => { viewModel.updateSelectionsState({ kind: SelectionStateType.Index, focus: { start: 1, end: 2 }, selections: [{ start: 1, end: 2 }] }); await copyCellRange({ notebookEditor: editor, cell: viewModel.cellAt(1)! }, 'down'); assert.strictEqual(viewModel.length, 6); @@ -105,8 +101,7 @@ suite('CellOperations', () => { ['var b = 2;', 'javascript', CellKind.Code, [], {}], ['var c = 3;', 'javascript', CellKind.Code, [], {}] ], - async (editor) => { - const viewModel = editor.viewModel; + async (editor, viewModel) => { viewModel.updateSelectionsState({ kind: SelectionStateType.Index, focus: { start: 0, end: 1 }, selections: [{ start: 0, end: 1 }] }); await copyCellRange({ notebookEditor: editor, cell: viewModel.cellAt(1)!, ui: true }, 'down'); assert.strictEqual(viewModel.length, 6); @@ -124,8 +119,7 @@ suite('CellOperations', () => { ['var b = 2;', 'javascript', CellKind.Code, [], {}], ['var c = 3;', 'javascript', CellKind.Code, [], {}] ], - async (editor) => { - const viewModel = editor.viewModel; + async (editor, viewModel) => { viewModel.updateSelectionsState({ kind: SelectionStateType.Index, focus: { start: 1, end: 2 }, selections: [{ start: 0, end: 2 }] }); await copyCellRange({ notebookEditor: editor, cell: viewModel.cellAt(1)! }, 'down'); assert.strictEqual(viewModel.length, 7); @@ -145,8 +139,7 @@ suite('CellOperations', () => { ['var b = 2;', 'javascript', CellKind.Code, [], {}], ['var c = 3;', 'javascript', CellKind.Code, [], {}] ], - async (editor) => { - const viewModel = editor.viewModel; + async (editor, viewModel) => { const foldingModel = new FoldingModel(); foldingModel.attachViewModel(viewModel); updateFoldingStateAtIndex(foldingModel, 0, true); @@ -276,8 +269,7 @@ suite('CellOperations', () => { ['var b = 2;', 'javascript', CellKind.Code, [], {}], ['var c = 3;', 'javascript', CellKind.Code, [], {}] ], - async (editor) => { - const viewModel = editor.viewModel; + async (editor, viewModel) => { editor.setFocus({ start: 0, end: 1 }); editor.setSelections([{ start: 0, end: 1 }]); runDeleteAction(viewModel, viewModel.cellAt(0)!); @@ -292,8 +284,7 @@ suite('CellOperations', () => { ['var b = 2;', 'javascript', CellKind.Code, [], {}], ['var c = 3;', 'javascript', CellKind.Code, [], {}] ], - async (editor) => { - const viewModel = editor.viewModel; + async (editor, viewModel) => { editor.setFocus({ start: 0, end: 1 }); editor.setSelections([{ start: 0, end: 2 }]); runDeleteAction(viewModel, viewModel.cellAt(0)!); @@ -309,8 +300,7 @@ suite('CellOperations', () => { ['var c = 3;', 'javascript', CellKind.Code, [], {}], ['var d = 4;', 'javascript', CellKind.Code, [], {}], ], - async (editor) => { - const viewModel = editor.viewModel; + async (editor, viewModel) => { editor.setFocus({ start: 0, end: 1 }); editor.setSelections([{ start: 2, end: 4 }]); runDeleteAction(viewModel, viewModel.cellAt(0)!); @@ -325,8 +315,7 @@ suite('CellOperations', () => { ['var b = 2;', 'javascript', CellKind.Code, [], {}], ['var c = 3;', 'javascript', CellKind.Code, [], {}] ], - async (editor) => { - const viewModel = editor.viewModel; + async (editor, viewModel) => { editor.setFocus({ start: 0, end: 1 }); editor.setSelections([{ start: 0, end: 1 }]); runDeleteAction(viewModel, viewModel.cellAt(2)!); @@ -345,8 +334,7 @@ suite('CellOperations', () => { ['var d = 4;', 'javascript', CellKind.Code, [], {}], ['var e = 5;', 'javascript', CellKind.Code, [], {}], ], - async (editor) => { - const viewModel = editor.viewModel; + async (editor, viewModel) => { editor.setFocus({ start: 0, end: 1 }); editor.setSelections([{ start: 0, end: 1 }, { start: 3, end: 5 }]); runDeleteAction(viewModel, viewModel.cellAt(1)!); @@ -365,8 +353,7 @@ suite('CellOperations', () => { ['var d = 4;', 'javascript', CellKind.Code, [], {}], ['var e = 5;', 'javascript', CellKind.Code, [], {}], ], - async (editor) => { - const viewModel = editor.viewModel; + async (editor, viewModel) => { editor.setFocus({ start: 0, end: 1 }); editor.setSelections([{ start: 2, end: 3 }]); runDeleteAction(viewModel, viewModel.cellAt(0)!); @@ -385,8 +372,7 @@ suite('CellOperations', () => { ['var d = 4;', 'javascript', CellKind.Code, [], {}], ['var e = 5;', 'javascript', CellKind.Code, [], {}], ], - async (editor) => { - const viewModel = editor.viewModel; + async (editor, viewModel) => { editor.setFocus({ start: 2, end: 3 }); editor.setSelections([{ start: 3, end: 5 }]); runDeleteAction(viewModel, viewModel.cellAt(0)!); @@ -404,8 +390,7 @@ suite('CellOperations', () => { ['var b = 2;', 'javascript', CellKind.Code, [], {}], ['var c = 3;', 'javascript', CellKind.Code, [], {}] ], - async (editor) => { - const viewModel = editor.viewModel; + async (editor, viewModel) => { editor.setFocus({ start: 2, end: 3 }); editor.setSelections([{ start: 2, end: 3 }]); runDeleteAction(viewModel, viewModel.cellAt(2)!); @@ -422,8 +407,7 @@ suite('CellOperations', () => { ['var c = 3;', 'javascript', CellKind.Code, [], {}], ['var d = 4;', 'javascript', CellKind.Code, [], {}] ], - async (editor) => { - const viewModel = editor.viewModel; + async (editor, viewModel) => { editor.setFocus({ start: 0, end: 1 }); editor.setSelections([{ start: 0, end: 1 }, { start: 3, end: 4 }]); runDeleteAction(viewModel, viewModel.cellAt(0)!); @@ -441,8 +425,7 @@ suite('CellOperations', () => { ['var d = 4;', 'javascript', CellKind.Code, [], {}], ['var e = 5;', 'javascript', CellKind.Code, [], {}], ], - async (editor) => { - const viewModel = editor.viewModel; + async (editor, viewModel) => { editor.setFocus({ start: 1, end: 2 }); editor.setSelections([{ start: 1, end: 2 }, { start: 3, end: 5 }]); runDeleteAction(viewModel, viewModel.cellAt(1)!); diff --git a/src/vs/workbench/contrib/notebook/browser/contrib/fold/test/notebookFolding.test.ts b/src/vs/workbench/contrib/notebook/browser/contrib/fold/test/notebookFolding.test.ts index db6ed0d83c1..2f5d4cd0f9f 100644 --- a/src/vs/workbench/contrib/notebook/browser/contrib/fold/test/notebookFolding.test.ts +++ b/src/vs/workbench/contrib/notebook/browser/contrib/fold/test/notebookFolding.test.ts @@ -24,8 +24,7 @@ suite('Notebook Folding', () => { ['## header 2.2', 'markdown', CellKind.Markup, [], {}], ['var e = 7;', 'markdown', CellKind.Markup, [], {}], ], - (editor) => { - const viewModel = editor.viewModel; + (editor, viewModel) => { const foldingController = new FoldingModel(); foldingController.attachViewModel(viewModel); @@ -51,8 +50,7 @@ suite('Notebook Folding', () => { ['## header 2.2', 'markdown', CellKind.Markup, [], {}], ['var e = 7;', 'markdown', CellKind.Markup, [], {}], ], - (editor) => { - const viewModel = editor.viewModel; + (editor, viewModel) => { const foldingController = new FoldingModel(); foldingController.attachViewModel(viewModel); @@ -83,8 +81,7 @@ suite('Notebook Folding', () => { ['## header 2.2', 'markdown', CellKind.Markup, [], {}], ['var e = 7;', 'markdown', CellKind.Markup, [], {}], ], - (editor) => { - const viewModel = editor.viewModel; + (editor, viewModel) => { const foldingModel = new FoldingModel(); foldingModel.attachViewModel(viewModel); updateFoldingStateAtIndex(foldingModel, 0, true); @@ -105,8 +102,7 @@ suite('Notebook Folding', () => { ['## header 2.2', 'markdown', CellKind.Markup, [], {}], ['var e = 7;', 'markdown', CellKind.Markup, [], {}], ], - (editor) => { - const viewModel = editor.viewModel; + (editor, viewModel) => { const foldingModel = new FoldingModel(); foldingModel.attachViewModel(viewModel); updateFoldingStateAtIndex(foldingModel, 2, true); @@ -128,8 +124,7 @@ suite('Notebook Folding', () => { ['## header 2.2', 'markdown', CellKind.Markup, [], {}], ['var e = 7;', 'markdown', CellKind.Markup, [], {}], ], - (editor) => { - const viewModel = editor.viewModel; + (editor, viewModel) => { const foldingModel = new FoldingModel(); foldingModel.attachViewModel(viewModel); updateFoldingStateAtIndex(foldingModel, 2, true); @@ -153,8 +148,7 @@ suite('Notebook Folding', () => { ['## header 2.2', 'markdown', CellKind.Markup, [], {}], ['var e = 7;', 'markdown', CellKind.Markup, [], {}], ], - (editor) => { - const viewModel = editor.viewModel; + (editor, viewModel) => { const foldingModel = new FoldingModel(); foldingModel.attachViewModel(viewModel); updateFoldingStateAtIndex(foldingModel, 0, true); @@ -213,8 +207,7 @@ suite('Notebook Folding', () => { ['## header 2.2', 'markdown', CellKind.Markup, [], {}], ['var e = 7;', 'markdown', CellKind.Markup, [], {}], ], - (editor) => { - const viewModel = editor.viewModel; + (editor, viewModel) => { const foldingModel = new FoldingModel(); foldingModel.attachViewModel(viewModel); foldingModel.applyMemento([{ start: 2, end: 6 }]); @@ -242,8 +235,7 @@ suite('Notebook Folding', () => { ['## header 2.2', 'markdown', CellKind.Markup, [], {}], ['var e = 7;', 'markdown', CellKind.Markup, [], {}], ], - (editor) => { - const viewModel = editor.viewModel; + (editor, viewModel) => { const foldingModel = new FoldingModel(); foldingModel.attachViewModel(viewModel); foldingModel.applyMemento([ @@ -275,8 +267,7 @@ suite('Notebook Folding', () => { ['## header 2.2', 'markdown', CellKind.Markup, [], {}], ['var e = 7;', 'markdown', CellKind.Markup, [], {}], ], - (editor) => { - const viewModel = editor.viewModel; + (editor, viewModel) => { const foldingModel = new FoldingModel(); foldingModel.attachViewModel(viewModel); foldingModel.applyMemento([ @@ -310,8 +301,7 @@ suite('Notebook Folding', () => { ['## header 2.2', 'markdown', CellKind.Markup, [], {}], ['var e = 7;', 'markdown', CellKind.Markup, [], {}], ], - (editor) => { - const viewModel = editor.viewModel; + (editor, viewModel) => { const foldingModel = new FoldingModel(); foldingModel.attachViewModel(viewModel); foldingModel.applyMemento([{ start: 2, end: 6 }]); @@ -347,8 +337,7 @@ suite('Notebook Folding', () => { ['## header 2.2', 'markdown', CellKind.Markup, [], {}], ['var e = 7;', 'markdown', CellKind.Markup, [], {}], ], - (editor) => { - const viewModel = editor.viewModel; + (editor, viewModel) => { const foldingModel = new FoldingModel(); foldingModel.attachViewModel(viewModel); foldingModel.applyMemento([ 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 8b9239eb0a3..0485436e363 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 @@ -82,8 +82,7 @@ suite('Notebook Undo/Redo', () => { ['# header 1', 'markdown', CellKind.Markup, [], {}], ['body', 'markdown', CellKind.Markup, [], {}], ], - async (editor) => { - const viewModel = editor.viewModel; + async (editor, viewModel) => { editor.textModel.applyEdits([{ editType: CellEditType.Replace, index: 1, count: 2, cells: [] }], true, undefined, () => undefined, undefined, true); diff --git a/src/vs/workbench/contrib/notebook/test/notebookCellList.test.ts b/src/vs/workbench/contrib/notebook/test/notebookCellList.test.ts index 122ffb94bc9..3e2db7e7fb0 100644 --- a/src/vs/workbench/contrib/notebook/test/notebookCellList.test.ts +++ b/src/vs/workbench/contrib/notebook/test/notebookCellList.test.ts @@ -23,8 +23,7 @@ suite('NotebookCellList', () => { ['var b = 2;', 'javascript', CellKind.Code, [], {}], ['# header c', 'markdown', CellKind.Markup, [], {}] ], - async (editor) => { - const viewModel = editor.viewModel; + async (editor, viewModel) => { viewModel.restoreEditorViewState({ editingCells: [false, false, false, false, false], editorViewStates: [null, null, null, null, null], @@ -68,8 +67,7 @@ suite('NotebookCellList', () => { ['var b = 2;', 'javascript', CellKind.Code, [], {}], ['# header c', 'markdown', CellKind.Markup, [], {}] ], - async (editor) => { - const viewModel = editor.viewModel; + async (editor, viewModel) => { viewModel.restoreEditorViewState({ editingCells: [false, false, false, false, false], editorViewStates: [null, null, null, null, null], @@ -110,8 +108,7 @@ suite('NotebookCellList', () => { ['var b = 2;', 'javascript', CellKind.Code, [], {}], ['# header c', 'markdown', CellKind.Markup, [], {}] ], - async (editor) => { - const viewModel = editor.viewModel; + async (editor, viewModel) => { viewModel.restoreEditorViewState({ editingCells: [false, false, false, false, false], editorViewStates: [null, null, null, null, null], @@ -145,8 +142,7 @@ suite('NotebookCellList', () => { ['var b = 2;', 'javascript', CellKind.Code, [], {}], ['# header c', 'markdown', CellKind.Markup, [], {}] ], - async (editor) => { - const viewModel = editor.viewModel; + async (editor, viewModel) => { viewModel.restoreEditorViewState({ editingCells: [false, false, false, false, false], editorViewStates: [null, null, null, null, null], @@ -185,10 +181,7 @@ suite('NotebookCellList', () => { ['var b = 2;', 'javascript', CellKind.Code, [], {}], ['# header c', 'markdown', CellKind.Markup, [], {}] ], - async (editor) => { - // await new Promise(c => setTimeout(c, 3000)); - - const viewModel = editor.viewModel; + async (editor, viewModel) => { viewModel.restoreEditorViewState({ editingCells: [false, false, false, false, false], editorViewStates: [null, null, null, null, null], @@ -238,10 +231,7 @@ suite('NotebookCellList', () => { ['var b = 2;', 'javascript', CellKind.Code, [], {}], ['# header c', 'markdown', CellKind.Markup, [], {}] ], - async (editor) => { - // await new Promise(c => setTimeout(c, 3000)); - - const viewModel = editor.viewModel; + async (editor, viewModel) => { viewModel.restoreEditorViewState({ editingCells: [false, false, false, false, false], editorViewStates: [null, null, null, null, null], @@ -274,8 +264,7 @@ suite('NotebookCellList', () => { ['var b = 2;', 'javascript', CellKind.Code, [], {}], ['# header c', 'markdown', CellKind.Markup, [], {}] ], - async (editor) => { - const viewModel = editor.viewModel; + async (editor, viewModel) => { viewModel.restoreEditorViewState({ editingCells: [false, false, false, false, false], editorViewStates: [null, null, null, null, null], diff --git a/src/vs/workbench/contrib/notebook/test/notebookEditor.test.ts b/src/vs/workbench/contrib/notebook/test/notebookEditor.test.ts index 77209945a10..085b529ead5 100644 --- a/src/vs/workbench/contrib/notebook/test/notebookEditor.test.ts +++ b/src/vs/workbench/contrib/notebook/test/notebookEditor.test.ts @@ -23,8 +23,7 @@ suite('ListViewInfoAccessor', () => { ['var b = 2;', 'javascript', CellKind.Code, [], {}], ['var c = 3;', 'javascript', CellKind.Code, [], {}] ], - (editor) => { - const viewModel = editor.viewModel; + (editor, viewModel) => { const foldingModel = new FoldingModel(); foldingModel.attachViewModel(viewModel); diff --git a/src/vs/workbench/contrib/notebook/test/notebookSelection.test.ts b/src/vs/workbench/contrib/notebook/test/notebookSelection.test.ts index 0580763ed93..53ed6763872 100644 --- a/src/vs/workbench/contrib/notebook/test/notebookSelection.test.ts +++ b/src/vs/workbench/contrib/notebook/test/notebookSelection.test.ts @@ -30,8 +30,7 @@ suite('NotebookCellList focus/selection', () => { ['var a = 1;', 'javascript', CellKind.Code, [], {}], ['var b = 2;', 'javascript', CellKind.Code, [], {}] ], - (editor) => { - const viewModel = editor.viewModel; + (editor, viewModel) => { const cellList = createNotebookCellList(instantiationService); cellList.attachViewModel(viewModel); @@ -51,8 +50,7 @@ suite('NotebookCellList focus/selection', () => { ['var a = 1;', 'javascript', CellKind.Code, [], {}], ['var b = 2;', 'javascript', CellKind.Code, [], {}] ], - (editor) => { - const viewModel = editor.viewModel; + (editor, viewModel) => { const cellList = createNotebookCellList(instantiationService); cellList.attachViewModel(viewModel); @@ -73,8 +71,7 @@ suite('NotebookCellList focus/selection', () => { ['var a = 1;', 'javascript', CellKind.Code, [], {}], ['var b = 2;', 'javascript', CellKind.Code, [], {}] ], - (editor) => { - const viewModel = editor.viewModel; + (editor, viewModel) => { const cellList = createNotebookCellList(instantiationService); cellList.attachViewModel(viewModel); @@ -100,8 +97,7 @@ suite('NotebookCellList focus/selection', () => { ['var b = 2;', 'javascript', CellKind.Code, [], {}], ['# header c', 'markdown', CellKind.Markup, [], {}] ], - (editor) => { - const viewModel = editor.viewModel; + (editor, viewModel) => { const cellList = createNotebookCellList(instantiationService); cellList.attachViewModel(viewModel); assert.deepStrictEqual(viewModel.getFocus(), { start: 0, end: 1 }); @@ -136,8 +132,7 @@ suite('NotebookCellList focus/selection', () => { ['var b = 2;', 'javascript', CellKind.Code, [], {}], ['# header c', 'markdown', CellKind.Markup, [], {}] ], - (editor) => { - const viewModel = editor.viewModel; + (editor, viewModel) => { const foldingModel = new FoldingModel(); foldingModel.attachViewModel(viewModel); @@ -183,8 +178,7 @@ suite('NotebookCellList focus/selection', () => { ['# header d', 'markdown', CellKind.Markup, [], {}], ['var e = 4;', 'javascript', CellKind.Code, [], {}], ], - (editor) => { - const viewModel = editor.viewModel; + (editor, viewModel) => { const foldingModel = new FoldingModel(); foldingModel.attachViewModel(viewModel); @@ -235,8 +229,7 @@ suite('NotebookCellList focus/selection', () => { ['var b = 2;', 'javascript', CellKind.Code, [], {}], ['# header c', 'markdown', CellKind.Markup, [], {}] ], - (editor) => { - const viewModel = editor.viewModel; + (editor, viewModel) => { const foldingModel = new FoldingModel(); foldingModel.attachViewModel(viewModel); @@ -262,8 +255,7 @@ suite('NotebookCellList focus/selection', () => { ['# header a', 'markdown', CellKind.Markup, [], {}], ['var b = 1;', 'javascript', CellKind.Code, [], {}] ], - (editor) => { - const viewModel = editor.viewModel; + (editor, viewModel) => { assert.deepStrictEqual(viewModel.validateRange(null), null); assert.deepStrictEqual(viewModel.validateRange(undefined), null); assert.deepStrictEqual(viewModel.validateRange({ start: 0, end: 0 }), null); @@ -282,8 +274,7 @@ suite('NotebookCellList focus/selection', () => { ['# header a', 'markdown', CellKind.Markup, [], {}], ['var b = 1;', 'javascript', CellKind.Code, [], {}] ], - (editor) => { - const viewModel = editor.viewModel; + (editor, viewModel) => { viewModel.updateSelectionsState({ kind: SelectionStateType.Index, focus: { start: 1, end: 2 }, selections: [{ start: 1, end: 2 }, { start: -1, end: 0 }] }); assert.deepStrictEqual(viewModel.getSelections(), [{ start: 1, end: 2 }]); }); @@ -295,8 +286,7 @@ suite('NotebookCellList focus/selection', () => { ['# header a', 'markdown', CellKind.Markup, [], {}], ['var b = 1;', 'javascript', CellKind.Code, [], {}] ], - (editor) => { - const viewModel = editor.viewModel; + (editor, viewModel) => { viewModel.updateSelectionsState({ kind: SelectionStateType.Index, focus: { start: 1, end: 2 }, selections: [{ start: 1, end: 2 }] }); viewModel.deleteCell(1, true, false); assert.deepStrictEqual(viewModel.getFocus(), { start: 0, end: 1 }); @@ -311,8 +301,7 @@ suite('NotebookCellList focus/selection', () => { ['var b = 1;', 'javascript', CellKind.Code, [], {}], ['var c = 2;', 'javascript', CellKind.Code, [], {}] ], - async (editor) => { - const viewModel = editor.viewModel; + async (editor, viewModel) => { viewModel.updateSelectionsState({ kind: SelectionStateType.Index, focus: { start: 1, end: 2 }, selections: [{ start: 1, end: 2 }] }); editor.textModel.applyEdits([{ editType: CellEditType.Replace, diff --git a/src/vs/workbench/contrib/notebook/test/notebookTextModel.test.ts b/src/vs/workbench/contrib/notebook/test/notebookTextModel.test.ts index d252f016f14..35ab89500b5 100644 --- a/src/vs/workbench/contrib/notebook/test/notebookTextModel.test.ts +++ b/src/vs/workbench/contrib/notebook/test/notebookTextModel.test.ts @@ -24,11 +24,10 @@ suite('NotebookTextModel', () => { ['var d = 4;', 'javascript', CellKind.Code, [], {}] ], (editor) => { - const viewModel = editor.viewModel; 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)] }, + { editType: CellEditType.Replace, index: 1, count: 0, cells: [new TestCell(textModel.viewType, 5, 'var e = 5;', 'javascript', CellKind.Code, [], modeService)] }, + { editType: CellEditType.Replace, index: 3, count: 0, cells: [new TestCell(textModel.viewType, 6, 'var f = 6;', 'javascript', CellKind.Code, [], modeService)] }, ], true, undefined, () => undefined, undefined); assert.strictEqual(textModel.cells.length, 6); @@ -48,11 +47,10 @@ suite('NotebookTextModel', () => { ['var d = 4;', 'javascript', CellKind.Code, [], {}] ], (editor) => { - const viewModel = editor.viewModel; 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)] }, + { editType: CellEditType.Replace, index: 1, count: 0, cells: [new TestCell(textModel.viewType, 5, 'var e = 5;', 'javascript', CellKind.Code, [], modeService)] }, + { editType: CellEditType.Replace, index: 1, count: 0, cells: [new TestCell(textModel.viewType, 6, 'var f = 6;', 'javascript', CellKind.Code, [], modeService)] }, ], true, undefined, () => undefined, undefined); assert.strictEqual(textModel.cells.length, 6); @@ -93,11 +91,10 @@ suite('NotebookTextModel', () => { ['var d = 4;', 'javascript', CellKind.Code, [], {}] ], (editor) => { - const viewModel = editor.viewModel; 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)] }, + { editType: CellEditType.Replace, index: 3, count: 0, cells: [new TestCell(textModel.viewType, 5, 'var e = 5;', 'javascript', CellKind.Code, [], modeService)] }, ], true, undefined, () => undefined, undefined); assert.strictEqual(textModel.cells.length, 4); @@ -116,11 +113,10 @@ suite('NotebookTextModel', () => { ['var d = 4;', 'javascript', CellKind.Code, [], {}] ], (editor) => { - const viewModel = editor.viewModel; 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)] }, + { editType: CellEditType.Replace, index: 1, count: 0, cells: [new TestCell(textModel.viewType, 5, 'var e = 5;', 'javascript', CellKind.Code, [], modeService)] }, ], true, undefined, () => undefined, undefined); assert.strictEqual(textModel.cells.length, 4); @@ -140,10 +136,9 @@ suite('NotebookTextModel', () => { ['var d = 4;', 'javascript', CellKind.Code, [], {}] ], (editor) => { - const viewModel = editor.viewModel; 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)] }, + { editType: CellEditType.Replace, index: 1, count: 1, cells: [new TestCell(textModel.viewType, 5, 'var e = 5;', 'javascript', CellKind.Code, [], modeService)] }, ], true, undefined, () => undefined, undefined); assert.strictEqual(textModel.cells.length, 4); @@ -345,7 +340,6 @@ suite('NotebookTextModel', () => { ['var d = 4;', 'javascript', CellKind.Code, [], {}] ], (editor) => { - const viewModel = editor.viewModel; const textModel = editor.textModel; let changeEvent: NotebookTextModelChangedEvent | undefined = undefined; const eventListener = textModel.onDidChangeContent(e => { @@ -355,7 +349,7 @@ suite('NotebookTextModel', () => { 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)] }, + { editType: CellEditType.Replace, index: 1, count: 0, cells: [new TestCell(textModel.viewType, 5, 'var e = 5;', 'javascript', CellKind.Code, [], modeService)] }, ], true, undefined, () => ({ kind: SelectionStateType.Index, focus: { start: 0, end: 1 }, selections: [{ start: 0, end: 1 }] }), undefined); assert.strictEqual(textModel.cells.length, 4); @@ -516,10 +510,10 @@ suite('NotebookTextModel', () => { await withTestNotebook([ ['var a = 1;', 'javascript', CellKind.Code, [], {}], ['var b = 2;', 'javascript', CellKind.Code, [], {}] - ], async (editor) => { - assert.strictEqual(editor.viewModel.getVersionId(), 0); + ], async (editor, viewModel) => { + assert.strictEqual(editor.textModel.versionId, 0); const firstAltVersion = '0_0,1;1,1'; - assert.strictEqual(editor.viewModel.getAlternativeId(), firstAltVersion); + assert.strictEqual(editor.textModel.alternativeVersionId, firstAltVersion); editor.textModel.applyEdits([ { index: 0, @@ -529,19 +523,19 @@ suite('NotebookTextModel', () => { } } ], true, undefined, () => undefined, undefined, true); - assert.strictEqual(editor.viewModel.getVersionId(), 1); - assert.notStrictEqual(editor.viewModel.getAlternativeId(), firstAltVersion); + assert.strictEqual(editor.textModel.versionId, 1); + assert.notStrictEqual(editor.textModel.alternativeVersionId, firstAltVersion); const secondAltVersion = '1_0,1;1,1'; - assert.strictEqual(editor.viewModel.getAlternativeId(), secondAltVersion); + assert.strictEqual(editor.textModel.alternativeVersionId, secondAltVersion); - await editor.viewModel.undo(); - assert.strictEqual(editor.viewModel.getVersionId(), 2); - assert.strictEqual(editor.viewModel.getAlternativeId(), firstAltVersion); + await viewModel.undo(); + assert.strictEqual(editor.textModel.versionId, 2); + assert.strictEqual(editor.textModel.alternativeVersionId, firstAltVersion); - await editor.viewModel.redo(); - assert.strictEqual(editor.viewModel.getVersionId(), 3); - assert.notStrictEqual(editor.viewModel.getAlternativeId(), firstAltVersion); - assert.strictEqual(editor.viewModel.getAlternativeId(), secondAltVersion); + await viewModel.redo(); + assert.strictEqual(editor.textModel.versionId, 3); + assert.notStrictEqual(editor.textModel.alternativeVersionId, firstAltVersion); + assert.strictEqual(editor.textModel.alternativeVersionId, secondAltVersion); editor.textModel.applyEdits([ { @@ -552,12 +546,12 @@ suite('NotebookTextModel', () => { } } ], true, undefined, () => undefined, undefined, true); - assert.strictEqual(editor.viewModel.getVersionId(), 4); - assert.strictEqual(editor.viewModel.getAlternativeId(), '4_0,1;1,1'); + assert.strictEqual(editor.textModel.versionId, 4); + assert.strictEqual(editor.textModel.alternativeVersionId, '4_0,1;1,1'); - await editor.viewModel.undo(); - assert.strictEqual(editor.viewModel.getVersionId(), 5); - assert.strictEqual(editor.viewModel.getAlternativeId(), secondAltVersion); + await viewModel.undo(); + assert.strictEqual(editor.textModel.versionId, 5); + assert.strictEqual(editor.textModel.alternativeVersionId, secondAltVersion); }); }); diff --git a/src/vs/workbench/contrib/notebook/test/notebookViewModel.test.ts b/src/vs/workbench/contrib/notebook/test/notebookViewModel.test.ts index 72b861ed3be..be72d45921a 100644 --- a/src/vs/workbench/contrib/notebook/test/notebookViewModel.test.ts +++ b/src/vs/workbench/contrib/notebook/test/notebookViewModel.test.ts @@ -50,9 +50,7 @@ suite('NotebookViewModel', () => { ['var a = 1;', 'javascript', CellKind.Code, [], {}], ['var b = 2;', 'javascript', CellKind.Code, [], {}] ], - (editor) => { - const viewModel = editor.viewModel; - + (editor, viewModel) => { const cell = viewModel.createCell(1, 'var c = 3', 'javascript', CellKind.Code, {}, [], true, true, null, []); assert.strictEqual(viewModel.length, 3); assert.strictEqual(viewModel.notebookDocument.cells.length, 3); @@ -73,8 +71,7 @@ suite('NotebookViewModel', () => { ['//b', 'javascript', CellKind.Code, [], {}], ['//c', 'javascript', CellKind.Code, [], {}], ], - (editor) => { - const viewModel = editor.viewModel; + (editor, viewModel) => { viewModel.moveCellToIdx(0, 1, 0, true); // no-op assert.strictEqual(viewModel.cellAt(0)?.getText(), '//a'); @@ -102,8 +99,7 @@ suite('NotebookViewModel', () => { ['//b', 'javascript', CellKind.Code, [], {}], ['//c', 'javascript', CellKind.Code, [], {}], ], - (editor) => { - const viewModel = editor.viewModel; + (editor, viewModel) => { viewModel.moveCellToIdx(1, 1, 0, true); // b, a, c assert.strictEqual(viewModel.cellAt(0)?.getText(), '//b'); @@ -124,8 +120,7 @@ suite('NotebookViewModel', () => { ['var a = 1;', 'javascript', CellKind.Code, [], {}], ['var b = 2;', 'javascript', CellKind.Code, [], {}] ], - (editor) => { - const viewModel = editor.viewModel; + (editor, viewModel) => { const firstViewCell = viewModel.cellAt(0)!; const lastViewCell = viewModel.cellAt(viewModel.length - 1)!; @@ -181,8 +176,7 @@ suite('NotebookViewModel Decorations', () => { ['var d = 4;', 'javascript', CellKind.Code, [], {}], ['var e = 5;', 'javascript', CellKind.Code, [], {}], ], - (editor) => { - const viewModel = editor.viewModel; + (editor, viewModel) => { const trackedId = viewModel.setTrackedRange('test', { start: 1, end: 2 }, TrackedRangeStickiness.GrowsOnlyWhenTypingAfter); assert.deepStrictEqual(viewModel.getTrackedRange(trackedId!), { start: 1, @@ -239,8 +233,7 @@ suite('NotebookViewModel Decorations', () => { ['var e = 6;', 'javascript', CellKind.Code, [], {}], ['var e = 7;', 'javascript', CellKind.Code, [], {}], ], - (editor) => { - const viewModel = editor.viewModel; + (editor, viewModel) => { const trackedId = viewModel.setTrackedRange('test', { start: 1, end: 3 }, TrackedRangeStickiness.GrowsOnlyWhenTypingAfter); assert.deepStrictEqual(viewModel.getTrackedRange(trackedId!), { start: 1, @@ -344,8 +337,7 @@ suite('NotebookViewModel API', () => { ['var e = 4;', 'TypeScript', CellKind.Code, [], {}], ['# header f', 'markdown', CellKind.Markup, [], {}] ], - (editor) => { - const viewModel = editor.viewModel; + (editor, viewModel) => { assert.strictEqual(viewModel.nearestCodeCellIndex(0), 1); // find the nearest code cell from above assert.strictEqual(viewModel.nearestCodeCellIndex(2), 1); @@ -363,8 +355,7 @@ suite('NotebookViewModel API', () => { ['var b = 1;', 'javascript', CellKind.Code, [], {}], ['# header b', 'markdown', CellKind.Markup, [], {}] ], - (editor) => { - const viewModel = editor.viewModel; + (editor, viewModel) => { assert.strictEqual(viewModel.nearestCodeCellIndex(2), 1); } ); @@ -377,8 +368,7 @@ suite('NotebookViewModel API', () => { ['var b = 1;', 'javascript', CellKind.Code, [], {}], ['# header b', 'markdown', CellKind.Markup, [], {}] ], - (editor) => { - const viewModel = editor.viewModel; + (editor, viewModel) => { assert.strictEqual(viewModel.getCells().length, 3); assert.deepStrictEqual(viewModel.getCells({ start: 0, end: 1 }).map(cell => cell.getText()), ['# header a']); assert.deepStrictEqual(viewModel.getCells({ start: 0, end: 2 }).map(cell => cell.getText()), ['# header a', 'var b = 1;']); @@ -400,8 +390,7 @@ suite('NotebookViewModel API', () => { [ ['var b = 1;', 'javascript', CellKind.Code, [], {}] ], - (editor) => { - const viewModel = editor.viewModel; + (editor, viewModel) => { assert.deepStrictEqual(viewModel.computeCellLinesContents(viewModel.cellAt(0)!, [{ lineNumber: 1, column: 4 }]), [ 'var', ' b = 1;'