diff --git a/src/vs/vscode.proposed.d.ts b/src/vs/vscode.proposed.d.ts index 2e747775ce5..70cfe3479b8 100644 --- a/src/vs/vscode.proposed.d.ts +++ b/src/vs/vscode.proposed.d.ts @@ -1750,6 +1750,8 @@ declare module 'vscode' { export let activeNotebookDocument: NotebookDocument | undefined; + export let activeNotebookEditor: NotebookEditor | undefined; + // export const onDidChangeNotebookDocument: Event; /** diff --git a/src/vs/workbench/api/common/extHost.api.impl.ts b/src/vs/workbench/api/common/extHost.api.impl.ts index 350b3b0fa10..8c79b302bc6 100644 --- a/src/vs/workbench/api/common/extHost.api.impl.ts +++ b/src/vs/workbench/api/common/extHost.api.impl.ts @@ -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); diff --git a/src/vs/workbench/api/common/extHostNotebook.ts b/src/vs/workbench/api/common/extHostNotebook.ts index 8db82c8a67b..9d1d6b742bf 100644 --- a/src/vs/workbench/api/common/extHostNotebook.ts +++ b/src/vs/workbench/api/common/extHostNotebook.ts @@ -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 { 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 { diff --git a/src/vs/workbench/contrib/notebook/browser/viewModel/notebookViewModel.ts b/src/vs/workbench/contrib/notebook/browser/viewModel/notebookViewModel.ts index e9d2cca69f0..8f02e0cffbe 100644 --- a/src/vs/workbench/contrib/notebook/browser/viewModel/notebookViewModel.ts +++ b/src/vs/workbench/contrib/notebook/browser/viewModel/notebookViewModel.ts @@ -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)]); diff --git a/src/vs/workbench/contrib/notebook/common/model/notebookTextModel.ts b/src/vs/workbench/contrib/notebook/common/model/notebookTextModel.ts index 00ad9e71fc6..ca46438fce0 100644 --- a/src/vs/workbench/contrib/notebook/common/model/notebookTextModel.ts +++ b/src/vs/workbench/contrib/notebook/common/model/notebookTextModel.ts @@ -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?