提交 d8df542f 编写于 作者: R rebornix

track newly created view cell in notebookviewmodel

上级 69d2a45a
......@@ -507,9 +507,8 @@ export class NotebookEditor extends BaseEditor implements INotebookEditor {
const index = this.notebookViewModel!.getViewCellIndex(cell);
const insertIndex = direction === 'above' ? index : index + 1;
const newModeCell = await this.notebookService.createNotebookCell(this.viewType!, this.notebookViewModel!.uri, insertIndex, language, type);
const newCell = this.instantiationService.createInstance(CellViewModel, this.viewType!, this.notebookViewModel!.handle, newModeCell!);
const newCell = this.notebookViewModel!.insertCell(insertIndex, newModeCell!);
this.notebookViewModel!.insertCell(insertIndex, newCell);
this.list?.splice(insertIndex, 0, [newCell]);
this.list?.setFocus([insertIndex]);
......
......@@ -153,15 +153,6 @@ export class CellViewModel extends Disposable {
};
}
stopFind(keepSelection?: boolean | undefined): void {
if (!this.assertTextModelAttached()) {
return;
}
}
focus(): void {
}
assertTextModelAttached(): boolean {
if (this._textModel && this._textEditor && this._textEditor.getModel() === this._textModel) {
return true;
......
......@@ -9,7 +9,7 @@ import * as editorCommon from 'vs/editor/common/editorCommon';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { NotebookEditorModel } from 'vs/workbench/contrib/notebook/browser/notebookEditorInput';
import { CellViewModel } from 'vs/workbench/contrib/notebook/browser/viewModel/notebookCellViewModel';
import { NotebookCellsSplice } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { NotebookCellsSplice, ICell } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { IModelDeltaDecoration } from 'vs/editor/common/model';
import { onUnexpectedError } from 'vs/base/common/errors';
import { CellFindMatch } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
......@@ -114,15 +114,19 @@ export class NotebookViewModel extends Disposable {
return matches;
}
insertCell(index: number, newCell: CellViewModel) {
insertCell(index: number, cell: ICell): CellViewModel {
const newCell = this.instantiationService.createInstance(CellViewModel, this.viewType, this.handle, cell);
this.viewCells!.splice(index, 0, newCell);
this._model.insertCell(newCell.cell, index);
this._localStore.add(newCell);
return newCell;
}
deleteCell(index: number) {
let viewCell = this.viewCells[index];
this.viewCells.splice(index, 1);
this._model.deleteCell(viewCell.cell);
viewCell.dispose();
}
saveEditorViewState(): INotebookEditorViewState {
......
......@@ -9,7 +9,7 @@ import { TestInstantiationService } from 'vs/platform/instantiation/test/common/
import { NotebookEditorModel } from 'vs/workbench/contrib/notebook/browser/notebookEditorInput';
import { NotebookViewModel } from 'vs/workbench/contrib/notebook/browser/viewModel/notebookViewModel';
import { CellKind } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { createTestCellViewModel, TestNotebook, withTestNotebook } from 'vs/workbench/contrib/notebook/test/testNotebookEditor';
import { TestNotebook, withTestNotebook, TestCell } from 'vs/workbench/contrib/notebook/test/testNotebookEditor';
suite('NotebookViewModel', () => {
const instantiationService = new TestInstantiationService();
......@@ -29,8 +29,7 @@ suite('NotebookViewModel', () => {
[['var b = 2;'], 'javascript', CellKind.Code, []]
],
(editor, viewModel) => {
const cell = createTestCellViewModel(instantiationService, viewModel.viewType, viewModel.handle, 0, ['var c = 3;'], 'javascript', CellKind.Code, []);
viewModel.insertCell(1, cell);
const cell = viewModel.insertCell(1, new TestCell(viewModel.viewType, 0, ['var c = 3;'], 'javascript', CellKind.Code, []));
assert.equal(viewModel.viewCells.length, 3);
assert.equal(viewModel.notebookDocument.cells.length, 3);
assert.equal(viewModel.getViewCellIndex(cell), 1);
......@@ -55,15 +54,13 @@ suite('NotebookViewModel', () => {
const lastViewCell = viewModel.viewCells[viewModel.viewCells.length - 1];
const insertIndex = viewModel.getViewCellIndex(firstViewCell) + 1;
const cell = createTestCellViewModel(instantiationService, viewModel.viewType, viewModel.handle, 3, ['var c = 3;'], 'javascript', CellKind.Code, []);
viewModel.insertCell(insertIndex, cell);
const cell = viewModel.insertCell(insertIndex, new TestCell(viewModel.viewType, 3, ['var c = 3;'], 'javascript', CellKind.Code, []));
const addedCellIndex = viewModel.getViewCellIndex(cell);
viewModel.deleteCell(addedCellIndex);
const secondInsertIndex = viewModel.getViewCellIndex(lastViewCell) + 1;
const cell2 = createTestCellViewModel(instantiationService, viewModel.viewType, viewModel.handle, 4, ['var d = 4;'], 'javascript', CellKind.Code, []);
viewModel.insertCell(secondInsertIndex, cell2);
const cell2 = viewModel.insertCell(secondInsertIndex, new TestCell(viewModel.viewType, 4, ['var d = 4;'], 'javascript', CellKind.Code, []));
assert.equal(viewModel.viewCells.length, 3);
assert.equal(viewModel.notebookDocument.cells.length, 3);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册