提交 9df3fcdf 编写于 作者: R rebornix

use ref when dealing with cell text model.

上级 7223877c
......@@ -104,7 +104,7 @@ export abstract class BaseCellViewModel extends Disposable {
}
hasModel(): this is IEditableCellViewModel {
return !!this.model.textModel;
return !!this._textModel;
}
private _dragging: boolean = false;
......
......@@ -70,15 +70,6 @@ export class NotebookCellTextModel extends Disposable implements ICell {
return this._textBuffer;
}
private _textModel?: model.ITextModel;
get textModel(): model.ITextModel | undefined {
return this._textModel;
}
set textModel(m: model.ITextModel | undefined) {
this._textModel = m;
}
constructor(
readonly uri: URI,
......@@ -144,10 +135,6 @@ export class NotebookCellTextModel extends Disposable implements ICell {
async resolveTextModelRef() {
const ref = await this._modelService.createModelReference(this.uri);
ref.object.textEditorModel.onWillDispose(() => {
this.textModel = undefined;
});
return ref;
}
......
......@@ -559,14 +559,15 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
async splitNotebookCell(index: number, newLinesContents: string[], endSelections: number[]) {
const cell = this.cells[index];
if (!cell.textModel) {
return;
}
const ref = await cell.resolveTextModelRef();
const textModel = ref.object.textEditorModel;
cell.textModel.applyEdits([
{ range: cell.textModel.getFullModelRange(), text: newLinesContents[0] }
textModel.applyEdits([
{ range: textModel.getFullModelRange(), text: newLinesContents[0] }
], false);
ref.dispose();
// create new cells based on the new text models
const language = cell.language;
const kind = cell.cellKind;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册