Skip to content

Commit 06a4015

Browse files
committed
resolve comments
1 parent 8a4de76 commit 06a4015

File tree

3 files changed

+27
-15
lines changed

3 files changed

+27
-15
lines changed

src/vs/workbench/contrib/notebook/browser/view/cellPart.ts

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import * as DOM from 'vs/base/browser/dom';
7-
import { Disposable, DisposableStore, IDisposable } from 'vs/base/common/lifecycle';
7+
import { Disposable, DisposableStore, IDisposable, MutableDisposable } from 'vs/base/common/lifecycle';
88
import { ICellViewModel } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
99
import { CellViewModelStateChangeEvent } from 'vs/workbench/contrib/notebook/browser/notebookViewEvents';
1010
import { ICellExecutionStateChangedEvent } from 'vs/workbench/contrib/notebook/common/notebookExecutionStateService';
1111

12+
/**
13+
* A content part is a non-floating element that is rendered inside a cell.
14+
* The rendering of the content part is synchronous to avoid flickering.
15+
*/
1216
export abstract class CellContentPart extends Disposable {
1317
protected currentCell: ICellViewModel | undefined;
1418
protected cellDisposables = new DisposableStore();
@@ -64,6 +68,10 @@ export abstract class CellContentPart extends Disposable {
6468
updateForExecutionState(element: ICellViewModel, e: ICellExecutionStateChangedEvent): void { }
6569
}
6670

71+
/**
72+
* An overlay part renders on top of other components.
73+
* The rendering of the overlay part might be postponed to the next animation frame to avoid forced reflow.
74+
*/
6775
export abstract class CellOverlayPart extends Disposable {
6876
protected currentCell: ICellViewModel | undefined;
6977
protected cellDisposables = new DisposableStore();
@@ -114,10 +122,10 @@ export abstract class CellOverlayPart extends Disposable {
114122
updateForExecutionState(element: ICellViewModel, e: ICellExecutionStateChangedEvent): void { }
115123
}
116124

117-
export class CellPartsCollection {
118-
private _scheduledOverlayRendering: IDisposable | undefined;
119-
private _scheduledOverlayUpdateState: IDisposable | undefined;
120-
private _scheduledOverlayUpdateExecutionState: IDisposable | undefined;
125+
export class CellPartsCollection implements IDisposable {
126+
private _scheduledOverlayRendering = new MutableDisposable();
127+
private _scheduledOverlayUpdateState = new MutableDisposable();
128+
private _scheduledOverlayUpdateExecutionState = new MutableDisposable();
121129

122130
constructor(
123131
private readonly contentParts: readonly CellContentPart[],
@@ -147,10 +155,7 @@ export class CellPartsCollection {
147155
part.renderCell(element);
148156
}
149157

150-
// schedule overlay parts rendering
151-
this._scheduledOverlayRendering?.dispose();
152-
153-
this._scheduledOverlayRendering = DOM.modify(() => {
158+
this._scheduledOverlayRendering.value = DOM.modify(() => {
154159
for (const part of this.overlayParts) {
155160
part.renderCell(element);
156161
}
@@ -188,9 +193,7 @@ export class CellPartsCollection {
188193
part.updateState(viewCell, e);
189194
}
190195

191-
this._scheduledOverlayUpdateState?.dispose();
192-
193-
this._scheduledOverlayUpdateState = DOM.modify(() => {
196+
this._scheduledOverlayUpdateState.value = DOM.modify(() => {
194197
for (const part of this.overlayParts) {
195198
part.updateState(viewCell, e);
196199
}
@@ -202,11 +205,16 @@ export class CellPartsCollection {
202205
part.updateForExecutionState(viewCell, e);
203206
}
204207

205-
this._scheduledOverlayUpdateExecutionState?.dispose();
206-
this._scheduledOverlayUpdateExecutionState = DOM.modify(() => {
208+
this._scheduledOverlayUpdateExecutionState.value = DOM.modify(() => {
207209
for (const part of this.overlayParts) {
208210
part.updateForExecutionState(viewCell, e);
209211
}
210212
});
211213
}
214+
215+
dispose() {
216+
this._scheduledOverlayRendering?.dispose();
217+
this._scheduledOverlayUpdateState?.dispose();
218+
this._scheduledOverlayUpdateExecutionState?.dispose();
219+
}
212220
}

src/vs/workbench/contrib/notebook/browser/view/cellParts/codeCell.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export class CodeCell extends Disposable {
5555

5656
const cellEditorOptions = this._register(new CellEditorOptions(this.notebookEditor.getBaseCellEditorOptions(viewCell.language), this.notebookEditor.notebookOptions, this.configurationService));
5757
this._outputContainerRenderer = this.instantiationService.createInstance(CellOutputContainer, notebookEditor, viewCell, templateData, { limit: 500 });
58-
this.cellParts = templateData.cellParts.concatContentPart([cellEditorOptions, this._outputContainerRenderer]);
58+
this.cellParts = this._register(templateData.cellParts.concatContentPart([cellEditorOptions, this._outputContainerRenderer]));
5959

6060
const editorHeight = this.calculateInitEditorHeight();
6161
this.initializeEditor(editorHeight);

src/vs/workbench/contrib/notebook/browser/view/renderers/cellRenderer.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ export class MarkupCellRenderer extends AbstractCellRenderer implements IListRen
180180
templateDisposables.add(scopedInstaService.createInstance(BetweenCellToolbar, this.notebookEditor, titleToolbarContainer, bottomCellContainer))
181181
]);
182182

183+
templateDisposables.add(cellParts);
184+
183185
const templateData: MarkdownCellRenderTemplate = {
184186
rootContainer,
185187
cellInputCollapsedContainer,
@@ -324,6 +326,8 @@ export class CodeCellRenderer extends AbstractCellRenderer implements IListRende
324326
templateDisposables.add(scopedInstaService.createInstance(BetweenCellToolbar, this.notebookEditor, titleToolbarContainer, bottomCellToolbarContainer))
325327
]);
326328

329+
templateDisposables.add(cellParts);
330+
327331
const templateData: CodeCellRenderTemplate = {
328332
rootContainer,
329333
editorPart,

0 commit comments

Comments
 (0)