Path: blob/main/src/vs/workbench/contrib/notebook/test/browser/cellOperations.test.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import assert from 'assert';6import { FoldingModel, updateFoldingStateAtIndex } from '../../browser/viewModel/foldingModel.js';7import { changeCellToKind, computeCellLinesContents, copyCellRange, insertCell, joinNotebookCells, moveCellRange, runDeleteAction } from '../../browser/controller/cellOperations.js';8import { CellEditType, CellKind, SelectionStateType } from '../../common/notebookCommon.js';9import { withTestNotebook } from './testNotebookEditor.js';10import { Range } from '../../../../../editor/common/core/range.js';11import { ResourceTextEdit } from '../../../../../editor/browser/services/bulkEditService.js';12import { ResourceNotebookCellEdit } from '../../../bulkEdit/browser/bulkCellEdits.js';13import { ILanguageService } from '../../../../../editor/common/languages/language.js';14import { ITextBuffer, ValidAnnotatedEditOperation } from '../../../../../editor/common/model.js';15import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../../base/test/common/utils.js';1617suite('CellOperations', () => {18ensureNoDisposablesAreLeakedInTestSuite();1920test('Move cells - single cell', async function () {21await withTestNotebook(22[23['# header a', 'markdown', CellKind.Markup, [], {}],24['var b = 1;', 'javascript', CellKind.Code, [], {}],25['# header b', 'markdown', CellKind.Markup, [], {}],26['var b = 2;', 'javascript', CellKind.Code, [], {}],27['var c = 3;', 'javascript', CellKind.Code, [], {}]28],29async (editor, viewModel) => {30viewModel.updateSelectionsState({ kind: SelectionStateType.Index, focus: { start: 1, end: 2 }, selections: [{ start: 1, end: 2 }] });31const cell = viewModel.cellAt(1);32assert.ok(cell);33await moveCellRange({ notebookEditor: editor, cell: cell }, 'down');34assert.strictEqual(viewModel.cellAt(2)?.getText(), 'var b = 1;');35assert.strictEqual(cell, viewModel.cellAt(2));36});37});3839test('Move cells - multiple cells in a selection', async function () {40await withTestNotebook(41[42['# header a', 'markdown', CellKind.Markup, [], {}],43['var b = 1;', 'javascript', CellKind.Code, [], {}],44['# header b', 'markdown', CellKind.Markup, [], {}],45['var b = 2;', 'javascript', CellKind.Code, [], {}],46['var c = 3;', 'javascript', CellKind.Code, [], {}]47],48async (editor, viewModel) => {49viewModel.updateSelectionsState({ kind: SelectionStateType.Index, focus: { start: 1, end: 2 }, selections: [{ start: 0, end: 2 }] });50await moveCellRange({ notebookEditor: editor }, 'down');51assert.strictEqual(viewModel.cellAt(0)?.getText(), '# header b');52assert.strictEqual(viewModel.cellAt(1)?.getText(), '# header a');53assert.strictEqual(viewModel.cellAt(2)?.getText(), 'var b = 1;');54});55});5657test('Move cells - move with folding ranges', async function () {58await withTestNotebook(59[60['# header a', 'markdown', CellKind.Markup, [], {}],61['var b = 1;', 'javascript', CellKind.Code, [], {}],62['# header b', 'markdown', CellKind.Markup, [], {}],63['var b = 2;', 'javascript', CellKind.Code, [], {}],64['var c = 3;', 'javascript', CellKind.Code, [], {}]65],66async (editor, viewModel, ds) => {67const foldingModel = ds.add(new FoldingModel());68foldingModel.attachViewModel(viewModel);69updateFoldingStateAtIndex(foldingModel, 0, true);70updateFoldingStateAtIndex(foldingModel, 1, true);71viewModel.updateFoldingRanges(foldingModel.regions);72editor.setHiddenAreas([{ start: 1, end: 2 }]);73editor.setHiddenAreas(viewModel.getHiddenRanges());7475viewModel.updateSelectionsState({ kind: SelectionStateType.Index, focus: { start: 0, end: 1 }, selections: [{ start: 0, end: 1 }] });76await moveCellRange({ notebookEditor: editor }, 'down');77assert.strictEqual(viewModel.cellAt(0)?.getText(), '# header b');78assert.strictEqual(viewModel.cellAt(1)?.getText(), '# header a');79assert.strictEqual(viewModel.cellAt(2)?.getText(), 'var b = 1;');80});81});828384test('Copy/duplicate cells - single cell', async function () {85await withTestNotebook(86[87['# header a', 'markdown', CellKind.Markup, [], {}],88['var b = 1;', 'javascript', CellKind.Code, [], {}],89['# header b', 'markdown', CellKind.Markup, [], {}],90['var b = 2;', 'javascript', CellKind.Code, [], {}],91['var c = 3;', 'javascript', CellKind.Code, [], {}]92],93async (editor, viewModel) => {94viewModel.updateSelectionsState({ kind: SelectionStateType.Index, focus: { start: 1, end: 2 }, selections: [{ start: 1, end: 2 }] });95await copyCellRange({ notebookEditor: editor, cell: viewModel.cellAt(1)! }, 'down');96assert.strictEqual(viewModel.length, 6);97assert.strictEqual(viewModel.cellAt(1)?.getText(), 'var b = 1;');98assert.strictEqual(viewModel.cellAt(2)?.getText(), 'var b = 1;');99});100});101102test('Copy/duplicate cells - target and selection are different, #119769', async function () {103await withTestNotebook(104[105['# header a', 'markdown', CellKind.Markup, [], {}],106['var b = 1;', 'javascript', CellKind.Code, [], {}],107['# header b', 'markdown', CellKind.Markup, [], {}],108['var b = 2;', 'javascript', CellKind.Code, [], {}],109['var c = 3;', 'javascript', CellKind.Code, [], {}]110],111async (editor, viewModel) => {112viewModel.updateSelectionsState({ kind: SelectionStateType.Index, focus: { start: 0, end: 1 }, selections: [{ start: 0, end: 1 }] });113await copyCellRange({ notebookEditor: editor, cell: viewModel.cellAt(1)!, ui: true }, 'down');114assert.strictEqual(viewModel.length, 6);115assert.strictEqual(viewModel.cellAt(1)?.getText(), 'var b = 1;');116assert.strictEqual(viewModel.cellAt(2)?.getText(), 'var b = 1;');117});118});119120test('Copy/duplicate cells - multiple cells in a selection', async function () {121await withTestNotebook(122[123['# header a', 'markdown', CellKind.Markup, [], {}],124['var b = 1;', 'javascript', CellKind.Code, [], {}],125['# header b', 'markdown', CellKind.Markup, [], {}],126['var b = 2;', 'javascript', CellKind.Code, [], {}],127['var c = 3;', 'javascript', CellKind.Code, [], {}]128],129async (editor, viewModel) => {130viewModel.updateSelectionsState({ kind: SelectionStateType.Index, focus: { start: 1, end: 2 }, selections: [{ start: 0, end: 2 }] });131await copyCellRange({ notebookEditor: editor, cell: viewModel.cellAt(1)! }, 'down');132assert.strictEqual(viewModel.length, 7);133assert.strictEqual(viewModel.cellAt(0)?.getText(), '# header a');134assert.strictEqual(viewModel.cellAt(1)?.getText(), 'var b = 1;');135assert.strictEqual(viewModel.cellAt(2)?.getText(), '# header a');136assert.strictEqual(viewModel.cellAt(3)?.getText(), 'var b = 1;');137});138});139140test('Copy/duplicate cells - move with folding ranges', async function () {141await withTestNotebook(142[143['# header a', 'markdown', CellKind.Markup, [], {}],144['var b = 1;', 'javascript', CellKind.Code, [], {}],145['# header b', 'markdown', CellKind.Markup, [], {}],146['var b = 2;', 'javascript', CellKind.Code, [], {}],147['var c = 3;', 'javascript', CellKind.Code, [], {}]148],149async (editor, viewModel, ds) => {150const foldingModel = ds.add(new FoldingModel());151foldingModel.attachViewModel(viewModel);152updateFoldingStateAtIndex(foldingModel, 0, true);153updateFoldingStateAtIndex(foldingModel, 1, true);154viewModel.updateFoldingRanges(foldingModel.regions);155editor.setHiddenAreas([{ start: 1, end: 2 }]);156editor.setHiddenAreas(viewModel.getHiddenRanges());157158viewModel.updateSelectionsState({ kind: SelectionStateType.Index, focus: { start: 0, end: 1 }, selections: [{ start: 0, end: 1 }] });159await copyCellRange({ notebookEditor: editor, cell: viewModel.cellAt(1)! }, 'down');160assert.strictEqual(viewModel.length, 7);161assert.strictEqual(viewModel.cellAt(0)?.getText(), '# header a');162assert.strictEqual(viewModel.cellAt(1)?.getText(), 'var b = 1;');163assert.strictEqual(viewModel.cellAt(2)?.getText(), '# header a');164assert.strictEqual(viewModel.cellAt(3)?.getText(), 'var b = 1;');165});166});167168test('Copy/duplicate cells - should not share the same text buffer #102423', async function () {169await withTestNotebook(170[171['# header a', 'markdown', CellKind.Markup, [], {}],172['var b = 1;', 'javascript', CellKind.Code, [], {}]173],174async (editor, viewModel) => {175viewModel.updateSelectionsState({ kind: SelectionStateType.Index, focus: { start: 1, end: 2 }, selections: [{ start: 1, end: 2 }] });176await copyCellRange({ notebookEditor: editor, cell: viewModel.cellAt(1)! }, 'down');177assert.strictEqual(viewModel.length, 3);178const cell1 = viewModel.cellAt(1);179const cell2 = viewModel.cellAt(2);180assert.ok(cell1);181assert.ok(cell2);182assert.strictEqual(cell1.getText(), 'var b = 1;');183assert.strictEqual(viewModel.cellAt(2)?.getText(), 'var b = 1;');184185(cell1.textBuffer as ITextBuffer).applyEdits([186new ValidAnnotatedEditOperation(null, new Range(1, 1, 1, 4), '', false, false, false)187], false, true);188assert.notStrictEqual(cell1.getText(), cell2.getText());189});190});191192test('Join cell with below - single cell', async function () {193await withTestNotebook(194[195['# header a', 'markdown', CellKind.Markup, [], {}],196['var b = 1;', 'javascript', CellKind.Code, [], {}],197['# header b', 'markdown', CellKind.Markup, [], {}],198['var b = 2;', 'javascript', CellKind.Code, [], {}],199['var c = 3;', 'javascript', CellKind.Code, [], {}]200],201async (editor, viewModel, accessor) => {202viewModel.updateSelectionsState({ kind: SelectionStateType.Index, focus: { start: 3, end: 4 }, selections: [{ start: 3, end: 4 }] });203const ret = await joinNotebookCells(editor, { start: 3, end: 4 }, 'below');204assert.strictEqual(ret?.edits.length, 2);205assert.deepStrictEqual(ret?.edits[0], new ResourceTextEdit(viewModel.cellAt(3)!.uri, {206range: new Range(1, 11, 1, 11), text: viewModel.cellAt(4)!.textBuffer.getEOL() + 'var c = 3;'207}));208assert.deepStrictEqual(ret?.edits[1], new ResourceNotebookCellEdit(editor.textModel.uri,209{210editType: CellEditType.Replace,211index: 4,212count: 1,213cells: []214}215));216});217});218219test('Join cell with above - single cell', async function () {220await withTestNotebook(221[222['# header a', 'markdown', CellKind.Markup, [], {}],223['var b = 1;', 'javascript', CellKind.Code, [], {}],224['# header b', 'markdown', CellKind.Markup, [], {}],225['var b = 2;', 'javascript', CellKind.Code, [], {}],226['var c = 3;', 'javascript', CellKind.Code, [], {}]227],228async (editor, viewModel, accessor) => {229viewModel.updateSelectionsState({ kind: SelectionStateType.Index, focus: { start: 3, end: 4 }, selections: [{ start: 3, end: 4 }] });230const ret = await joinNotebookCells(editor, { start: 4, end: 5 }, 'above');231assert.strictEqual(ret?.edits.length, 2);232assert.deepStrictEqual(ret?.edits[0], new ResourceTextEdit(viewModel.cellAt(3)!.uri, {233range: new Range(1, 11, 1, 11), text: viewModel.cellAt(4)!.textBuffer.getEOL() + 'var c = 3;'234}));235assert.deepStrictEqual(ret?.edits[1], new ResourceNotebookCellEdit(editor.textModel.uri,236{237editType: CellEditType.Replace,238index: 4,239count: 1,240cells: []241}242));243});244});245246test('Join cell with below - multiple cells', async function () {247await withTestNotebook(248[249['var a = 1;', 'javascript', CellKind.Code, [], {}],250['var b = 2;', 'javascript', CellKind.Code, [], {}],251['var c = 3;', 'javascript', CellKind.Code, [], {}]252],253async (editor, viewModel, accessor) => {254viewModel.updateSelectionsState({ kind: SelectionStateType.Index, focus: { start: 1, end: 2 }, selections: [{ start: 0, end: 2 }] });255const ret = await joinNotebookCells(editor, { start: 0, end: 2 }, 'below');256assert.strictEqual(ret?.edits.length, 2);257assert.deepStrictEqual(ret?.edits[0], new ResourceTextEdit(viewModel.cellAt(0)!.uri, {258range: new Range(1, 11, 1, 11), text: viewModel.cellAt(1)!.textBuffer.getEOL() + 'var b = 2;' + viewModel.cellAt(2)!.textBuffer.getEOL() + 'var c = 3;'259}));260assert.deepStrictEqual(ret?.edits[1], new ResourceNotebookCellEdit(editor.textModel.uri,261{262editType: CellEditType.Replace,263index: 1,264count: 2,265cells: []266}267));268});269});270271test('Join cell with above - multiple cells', async function () {272await withTestNotebook(273[274['var a = 1;', 'javascript', CellKind.Code, [], {}],275['var b = 2;', 'javascript', CellKind.Code, [], {}],276['var c = 3;', 'javascript', CellKind.Code, [], {}]277],278async (editor, viewModel, accessor) => {279viewModel.updateSelectionsState({ kind: SelectionStateType.Index, focus: { start: 2, end: 3 }, selections: [{ start: 1, end: 3 }] });280const ret = await joinNotebookCells(editor, { start: 1, end: 3 }, 'above');281assert.strictEqual(ret?.edits.length, 2);282assert.deepStrictEqual(ret?.edits[0], new ResourceTextEdit(viewModel.cellAt(0)!.uri, {283range: new Range(1, 11, 1, 11), text: viewModel.cellAt(1)!.textBuffer.getEOL() + 'var b = 2;' + viewModel.cellAt(2)!.textBuffer.getEOL() + 'var c = 3;'284}));285assert.deepStrictEqual(ret?.edits[1], new ResourceNotebookCellEdit(editor.textModel.uri,286{287editType: CellEditType.Replace,288index: 1,289count: 2,290cells: []291}292));293});294});295296test('Delete focus cell', async function () {297await withTestNotebook(298[299['var a = 1;', 'javascript', CellKind.Code, [], {}],300['var b = 2;', 'javascript', CellKind.Code, [], {}],301['var c = 3;', 'javascript', CellKind.Code, [], {}]302],303async (editor, viewModel) => {304editor.setFocus({ start: 0, end: 1 });305editor.setSelections([{ start: 0, end: 1 }]);306runDeleteAction(editor, viewModel.cellAt(0)!);307assert.strictEqual(viewModel.length, 2);308});309});310311test('Delete selected cells', async function () {312await withTestNotebook(313[314['var a = 1;', 'javascript', CellKind.Code, [], {}],315['var b = 2;', 'javascript', CellKind.Code, [], {}],316['var c = 3;', 'javascript', CellKind.Code, [], {}]317],318async (editor, viewModel) => {319editor.setFocus({ start: 0, end: 1 });320editor.setSelections([{ start: 0, end: 2 }]);321runDeleteAction(editor, viewModel.cellAt(0)!);322assert.strictEqual(viewModel.length, 1);323});324});325326test('Delete focus cell out of a selection', async function () {327await withTestNotebook(328[329['var a = 1;', 'javascript', CellKind.Code, [], {}],330['var b = 2;', 'javascript', CellKind.Code, [], {}],331['var c = 3;', 'javascript', CellKind.Code, [], {}],332['var d = 4;', 'javascript', CellKind.Code, [], {}],333],334async (editor, viewModel) => {335editor.setFocus({ start: 0, end: 1 });336editor.setSelections([{ start: 2, end: 4 }]);337runDeleteAction(editor, viewModel.cellAt(0)!);338assert.strictEqual(viewModel.length, 3);339});340});341342test('Delete UI target', async function () {343await withTestNotebook(344[345['var a = 1;', 'javascript', CellKind.Code, [], {}],346['var b = 2;', 'javascript', CellKind.Code, [], {}],347['var c = 3;', 'javascript', CellKind.Code, [], {}]348],349async (editor, viewModel) => {350editor.setFocus({ start: 0, end: 1 });351editor.setSelections([{ start: 0, end: 1 }]);352runDeleteAction(editor, viewModel.cellAt(2)!);353assert.strictEqual(viewModel.length, 2);354assert.strictEqual(viewModel.cellAt(0)?.getText(), 'var a = 1;');355assert.strictEqual(viewModel.cellAt(1)?.getText(), 'var b = 2;');356});357});358359test('Delete UI target 2', async function () {360await withTestNotebook(361[362['var a = 1;', 'javascript', CellKind.Code, [], {}],363['var b = 2;', 'javascript', CellKind.Code, [], {}],364['var c = 3;', 'javascript', CellKind.Code, [], {}],365['var d = 4;', 'javascript', CellKind.Code, [], {}],366['var e = 5;', 'javascript', CellKind.Code, [], {}],367],368async (editor, viewModel) => {369editor.setFocus({ start: 0, end: 1 });370editor.setSelections([{ start: 0, end: 1 }, { start: 3, end: 5 }]);371runDeleteAction(editor, viewModel.cellAt(1)!);372assert.strictEqual(viewModel.length, 4);373assert.deepStrictEqual(editor.getFocus(), { start: 0, end: 1 });374assert.deepStrictEqual(viewModel.getSelections(), [{ start: 0, end: 1 }, { start: 2, end: 4 }]);375});376});377378test('Delete UI target 3', async function () {379await withTestNotebook(380[381['var a = 1;', 'javascript', CellKind.Code, [], {}],382['var b = 2;', 'javascript', CellKind.Code, [], {}],383['var c = 3;', 'javascript', CellKind.Code, [], {}],384['var d = 4;', 'javascript', CellKind.Code, [], {}],385['var e = 5;', 'javascript', CellKind.Code, [], {}],386],387async (editor, viewModel) => {388editor.setFocus({ start: 0, end: 1 });389editor.setSelections([{ start: 2, end: 3 }]);390runDeleteAction(editor, viewModel.cellAt(0)!);391assert.strictEqual(viewModel.length, 4);392assert.deepStrictEqual(editor.getFocus(), { start: 0, end: 1 });393assert.deepStrictEqual(viewModel.getSelections(), [{ start: 1, end: 2 }]);394});395});396397test('Delete UI target 4', async function () {398await withTestNotebook(399[400['var a = 1;', 'javascript', CellKind.Code, [], {}],401['var b = 2;', 'javascript', CellKind.Code, [], {}],402['var c = 3;', 'javascript', CellKind.Code, [], {}],403['var d = 4;', 'javascript', CellKind.Code, [], {}],404['var e = 5;', 'javascript', CellKind.Code, [], {}],405],406async (editor, viewModel) => {407editor.setFocus({ start: 2, end: 3 });408editor.setSelections([{ start: 3, end: 5 }]);409runDeleteAction(editor, viewModel.cellAt(0)!);410assert.strictEqual(viewModel.length, 4);411assert.deepStrictEqual(editor.getFocus(), { start: 1, end: 2 });412assert.deepStrictEqual(viewModel.getSelections(), [{ start: 2, end: 4 }]);413});414});415416417test('Delete last cell sets selection correctly', async function () {418await withTestNotebook(419[420['var a = 1;', 'javascript', CellKind.Code, [], {}],421['var b = 2;', 'javascript', CellKind.Code, [], {}],422['var c = 3;', 'javascript', CellKind.Code, [], {}]423],424async (editor, viewModel) => {425editor.setFocus({ start: 2, end: 3 });426editor.setSelections([{ start: 2, end: 3 }]);427runDeleteAction(editor, viewModel.cellAt(2)!);428assert.strictEqual(viewModel.length, 2);429assert.deepStrictEqual(editor.getFocus(), { start: 1, end: 2 });430});431});432433test('#120187. Delete should work on multiple distinct selection', async function () {434await withTestNotebook(435[436['var a = 1;', 'javascript', CellKind.Code, [], {}],437['var b = 2;', 'javascript', CellKind.Code, [], {}],438['var c = 3;', 'javascript', CellKind.Code, [], {}],439['var d = 4;', 'javascript', CellKind.Code, [], {}]440],441async (editor, viewModel) => {442editor.setFocus({ start: 0, end: 1 });443editor.setSelections([{ start: 0, end: 1 }, { start: 3, end: 4 }]);444runDeleteAction(editor, viewModel.cellAt(0)!);445assert.strictEqual(viewModel.length, 2);446assert.deepStrictEqual(editor.getFocus(), { start: 0, end: 1 });447});448});449450test('#120187. Delete should work on multiple distinct selection 2', async function () {451await withTestNotebook(452[453['var a = 1;', 'javascript', CellKind.Code, [], {}],454['var b = 2;', 'javascript', CellKind.Code, [], {}],455['var c = 3;', 'javascript', CellKind.Code, [], {}],456['var d = 4;', 'javascript', CellKind.Code, [], {}],457['var e = 5;', 'javascript', CellKind.Code, [], {}],458],459async (editor, viewModel) => {460editor.setFocus({ start: 1, end: 2 });461editor.setSelections([{ start: 1, end: 2 }, { start: 3, end: 5 }]);462runDeleteAction(editor, viewModel.cellAt(1)!);463assert.strictEqual(viewModel.length, 2);464assert.deepStrictEqual(editor.getFocus(), { start: 1, end: 2 });465});466});467468test('Change cell kind - single cell', async function () {469await withTestNotebook(470[471['# header a', 'markdown', CellKind.Markup, [], {}],472['var b = 1;', 'javascript', CellKind.Code, [], {}],473['# header b', 'markdown', CellKind.Markup, [], {}],474['var b = 2;', 'javascript', CellKind.Code, [], {}],475['var c = 3;', 'javascript', CellKind.Code, [], {}]476],477async (editor, viewModel) => {478viewModel.updateSelectionsState({ kind: SelectionStateType.Index, focus: { start: 1, end: 2 }, selections: [{ start: 1, end: 2 }] });479await changeCellToKind(CellKind.Markup, { notebookEditor: editor, cell: viewModel.cellAt(1)!, ui: true });480assert.strictEqual(viewModel.cellAt(1)?.cellKind, CellKind.Markup);481});482});483484test('Change cell kind - multi cells', async function () {485await withTestNotebook(486[487['# header a', 'markdown', CellKind.Markup, [], {}],488['var b = 1;', 'javascript', CellKind.Code, [], {}],489['# header b', 'markdown', CellKind.Markup, [], {}],490['var b = 2;', 'javascript', CellKind.Code, [], {}],491['var c = 3;', 'javascript', CellKind.Code, [], {}]492],493async (editor, viewModel) => {494viewModel.updateSelectionsState({ kind: SelectionStateType.Index, focus: { start: 1, end: 2 }, selections: [{ start: 1, end: 2 }] });495await changeCellToKind(CellKind.Markup, { notebookEditor: editor, selectedCells: [viewModel.cellAt(3)!, viewModel.cellAt(4)!], ui: false });496assert.strictEqual(viewModel.cellAt(3)?.cellKind, CellKind.Markup);497assert.strictEqual(viewModel.cellAt(4)?.cellKind, CellKind.Markup);498});499});500501502test('split cell', async function () {503await withTestNotebook(504[505['var b = 1;', 'javascript', CellKind.Code, [], {}]506],507(editor, viewModel) => {508assert.deepStrictEqual(computeCellLinesContents(viewModel.cellAt(0)!, [{ lineNumber: 1, column: 4 }]), [509'var',510' b = 1;'511]);512513assert.deepStrictEqual(computeCellLinesContents(viewModel.cellAt(0)!, [{ lineNumber: 1, column: 4 }, { lineNumber: 1, column: 6 }]), [514'var',515' b',516' = 1;'517]);518519assert.deepStrictEqual(computeCellLinesContents(viewModel.cellAt(0)!, [{ lineNumber: 1, column: 1 }]), [520'',521'var b = 1;'522]);523524assert.deepStrictEqual(computeCellLinesContents(viewModel.cellAt(0)!, [{ lineNumber: 1, column: 11 }]), [525'var b = 1;',526'',527]);528}529);530});531532test('Insert cell', async function () {533await withTestNotebook(534[535['# header a', 'markdown', CellKind.Markup, [], {}],536['var b = 1;', 'javascript', CellKind.Code, [], {}],537['# header b', 'markdown', CellKind.Markup, [], {}],538['var b = 2;', 'javascript', CellKind.Code, [], {}],539['var c = 3;', 'javascript', CellKind.Code, [], {}]540],541async (editor, viewModel, _ds, accessor) => {542const languageService = accessor.get(ILanguageService);543544const insertedCellAbove = insertCell(languageService, editor, 4, CellKind.Code, 'above', 'var a = 0;');545assert.strictEqual(viewModel.length, 6);546assert.strictEqual(viewModel.cellAt(4), insertedCellAbove);547548const insertedCellBelow = insertCell(languageService, editor, 1, CellKind.Code, 'below', 'var a = 0;');549assert.strictEqual(viewModel.length, 7);550assert.strictEqual(viewModel.cellAt(2), insertedCellBelow);551});552});553});554555556