Skip to content

Commit dbfe561

Browse files
committed
notebook.activeNotebookEditor
1 parent bbe5ac3 commit dbfe561

5 files changed

Lines changed: 36 additions & 10 deletions

File tree

src/vs/vscode.proposed.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1750,6 +1750,8 @@ declare module 'vscode' {
17501750

17511751
export let activeNotebookDocument: NotebookDocument | undefined;
17521752

1753+
export let activeNotebookEditor: NotebookEditor | undefined;
1754+
17531755
// export const onDidChangeNotebookDocument: Event<NotebookDocumentChangeEvent>;
17541756

17551757
/**

src/vs/workbench/api/common/extHost.api.impl.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -913,6 +913,10 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
913913
checkProposedApiEnabled(extension);
914914
return extHostNotebook.activeNotebookDocument;
915915
},
916+
get activeNotebookEditor(): vscode.NotebookEditor | undefined {
917+
checkProposedApiEnabled(extension);
918+
return extHostNotebook.activeNotebookEditor;
919+
},
916920
createConcatTextDocument(notebook, selector) {
917921
checkProposedApiEnabled(extension);
918922
return new ExtHostNotebookConcatDocument(extHostNotebook, extHostDocuments, notebook, selector);

src/vs/workbench/api/common/extHostNotebook.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,12 @@ export class ExtHostNotebookController implements ExtHostNotebookShape, ExtHostN
613613
return this._activeNotebookDocument;
614614
}
615615

616+
private _activeNotebookEditor: ExtHostNotebookEditor | undefined;
617+
618+
get activeNotebookEditor() {
619+
return this._activeNotebookEditor;
620+
}
621+
616622
constructor(mainContext: IMainContext, commands: ExtHostCommands, private _documentsAndEditors: ExtHostDocumentsAndEditors) {
617623
this._proxy = mainContext.getProxy(MainContext.MainThreadNotebook);
618624

@@ -746,6 +752,7 @@ export class ExtHostNotebookController implements ExtHostNotebookShape, ExtHostN
746752

747753
async $updateActiveEditor(viewType: string, uri: UriComponents): Promise<void> {
748754
this._activeNotebookDocument = this._documents.get(URI.revive(uri).toString());
755+
this._activeNotebookEditor = this._editors.get(URI.revive(uri).toString())?.editor;
749756
}
750757

751758
async $destoryNotebookDocument(viewType: string, uri: UriComponents): Promise<boolean> {

src/vs/workbench/contrib/notebook/browser/viewModel/notebookViewModel.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -220,16 +220,26 @@ export class NotebookViewModel extends Disposable implements EditorFoldingStateD
220220
this.id = '$notebookViewModel' + MODEL_ID;
221221
this._instanceId = strings.singleLetterHash(MODEL_ID);
222222

223-
// this._register(this._model.onDidChangeCells(e => {
224-
// this._onDidChangeViewCells.fire({
225-
// synchronous: true,
226-
// splices: e.map(splice => {
227-
// return [splice[0], splice[1], splice[2].map(cell => {
228-
// return createCellViewModel(this.instantiationService, this, cell as NotebookCellTextModel);
229-
// })];
230-
// })
231-
// });
232-
// }));
223+
this._register(this._model.onDidChangeCells(e => {
224+
const diffs = e.map(splice => {
225+
return [splice[0], splice[1], splice[2].map(cell => {
226+
return createCellViewModel(this.instantiationService, this, cell as NotebookCellTextModel);
227+
})] as [number, number, CellViewModel[]];
228+
});
229+
230+
diffs.reverse().forEach(diff => {
231+
this._viewCells.splice(diff[0], diff[1], ...diff[2]);
232+
diff[2].forEach(cell => {
233+
this._handleToViewCellMapping.set(cell.handle, cell);
234+
this._localStore.add(cell);
235+
});
236+
});
237+
238+
this._onDidChangeViewCells.fire({
239+
synchronous: true,
240+
splices: diffs
241+
});
242+
}));
233243

234244
this._register(this._model.notebook.onDidChangeMetadata(e => {
235245
this.eventDispatcher.emit([new NotebookMetadataChangedEvent(e)]);

src/vs/workbench/contrib/notebook/common/model/notebookTextModel.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
147147
]
148148
]
149149
});
150+
this._onDidChangeCells.fire([[0, 0, [cell]]]);
150151

151152
return;
152153
}
@@ -183,6 +184,7 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
183184
]
184185
]
185186
});
187+
this._onDidChangeCells.fire([[index, 0, cells]]);
186188

187189
return;
188190
}
@@ -198,6 +200,7 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
198200

199201
this._increaseVersionId();
200202
this._onDidModelChange.fire({ versionId: this._versionId, changes: [[index, 1, []]] });
203+
this._onDidChangeCells.fire([[index, 1, []]]);
201204
}
202205

203206
// TODO@rebornix should this trigger content change event?

0 commit comments

Comments
 (0)