Avoid creating execution state listener for every cell. (#177025)

This commit is contained in:
Peng Lyu
2023-03-13 18:09:05 -07:00
committed by GitHub
parent 7b81968088
commit 93eaf7cf02
4 changed files with 25 additions and 19 deletions

View File

@@ -33,6 +33,7 @@ import { CellKind, ICell, INotebookSearchOptions, ISelectionState, NotebookCells
import { cellIndexesToRanges, cellRangesToIndexes, ICellRange, reduceCellRanges } from 'vs/workbench/contrib/notebook/common/notebookRange';
import { NotebookLayoutInfo, NotebookMetadataChangedEvent } from 'vs/workbench/contrib/notebook/browser/notebookViewEvents';
import { CellFindMatchModel } from 'vs/workbench/contrib/notebook/browser/contrib/find/findModel';
import { INotebookExecutionStateService } from 'vs/workbench/contrib/notebook/common/notebookExecutionStateService';
const invalidFunc = () => { throw new Error(`Invalid change accessor`); };
@@ -196,6 +197,7 @@ export class NotebookViewModel extends Disposable implements EditorFoldingStateD
@IBulkEditService private readonly _bulkEditService: IBulkEditService,
@IUndoRedoService private readonly _undoService: IUndoRedoService,
@ITextModelService private readonly _textModelService: ITextModelService,
@INotebookExecutionStateService notebookExecutionStateService: INotebookExecutionStateService,
) {
super();
@@ -318,6 +320,13 @@ export class NotebookViewModel extends Disposable implements EditorFoldingStateD
}
}));
this._register(notebookExecutionStateService.onDidChangeCellExecution(e => {
const cell = this.getCellByHandle(e.cellHandle);
if (cell instanceof CodeCellViewModel) {
cell.updateExecutionState(e);
}
}));
this._register(this._selectionCollection.onDidChangeSelection(e => {
this._onDidChangeSelection.fire(e);