提交 dbfe5613 编写于 作者: R rebornix

notebook.activeNotebookEditor

上级 bbe5ac36
......@@ -1750,6 +1750,8 @@ declare module 'vscode' {
export let activeNotebookDocument: NotebookDocument | undefined;
export let activeNotebookEditor: NotebookEditor | undefined;
// export const onDidChangeNotebookDocument: Event<NotebookDocumentChangeEvent>;
/**
......
......@@ -913,6 +913,10 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
checkProposedApiEnabled(extension);
return extHostNotebook.activeNotebookDocument;
},
get activeNotebookEditor(): vscode.NotebookEditor | undefined {
checkProposedApiEnabled(extension);
return extHostNotebook.activeNotebookEditor;
},
createConcatTextDocument(notebook, selector) {
checkProposedApiEnabled(extension);
return new ExtHostNotebookConcatDocument(extHostNotebook, extHostDocuments, notebook, selector);
......
......@@ -613,6 +613,12 @@ export class ExtHostNotebookController implements ExtHostNotebookShape, ExtHostN
return this._activeNotebookDocument;
}
private _activeNotebookEditor: ExtHostNotebookEditor | undefined;
get activeNotebookEditor() {
return this._activeNotebookEditor;
}
constructor(mainContext: IMainContext, commands: ExtHostCommands, private _documentsAndEditors: ExtHostDocumentsAndEditors) {
this._proxy = mainContext.getProxy(MainContext.MainThreadNotebook);
......@@ -746,6 +752,7 @@ export class ExtHostNotebookController implements ExtHostNotebookShape, ExtHostN
async $updateActiveEditor(viewType: string, uri: UriComponents): Promise<void> {
this._activeNotebookDocument = this._documents.get(URI.revive(uri).toString());
this._activeNotebookEditor = this._editors.get(URI.revive(uri).toString())?.editor;
}
async $destoryNotebookDocument(viewType: string, uri: UriComponents): Promise<boolean> {
......
......@@ -220,16 +220,26 @@ export class NotebookViewModel extends Disposable implements EditorFoldingStateD
this.id = '$notebookViewModel' + MODEL_ID;
this._instanceId = strings.singleLetterHash(MODEL_ID);
// this._register(this._model.onDidChangeCells(e => {
// this._onDidChangeViewCells.fire({
// synchronous: true,
// splices: e.map(splice => {
// return [splice[0], splice[1], splice[2].map(cell => {
// return createCellViewModel(this.instantiationService, this, cell as NotebookCellTextModel);
// })];
// })
// });
// }));
this._register(this._model.onDidChangeCells(e => {
const diffs = e.map(splice => {
return [splice[0], splice[1], splice[2].map(cell => {
return createCellViewModel(this.instantiationService, this, cell as NotebookCellTextModel);
})] as [number, number, CellViewModel[]];
});
diffs.reverse().forEach(diff => {
this._viewCells.splice(diff[0], diff[1], ...diff[2]);
diff[2].forEach(cell => {
this._handleToViewCellMapping.set(cell.handle, cell);
this._localStore.add(cell);
});
});
this._onDidChangeViewCells.fire({
synchronous: true,
splices: diffs
});
}));
this._register(this._model.notebook.onDidChangeMetadata(e => {
this.eventDispatcher.emit([new NotebookMetadataChangedEvent(e)]);
......
......@@ -147,6 +147,7 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
]
]
});
this._onDidChangeCells.fire([[0, 0, [cell]]]);
return;
}
......@@ -183,6 +184,7 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
]
]
});
this._onDidChangeCells.fire([[index, 0, cells]]);
return;
}
......@@ -198,6 +200,7 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
this._increaseVersionId();
this._onDidModelChange.fire({ versionId: this._versionId, changes: [[index, 1, []]] });
this._onDidChangeCells.fire([[index, 1, []]]);
}
// TODO@rebornix should this trigger content change event?
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册