4
4
*--------------------------------------------------------------------------------------------*/
5
5
6
6
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' ;
8
8
import { ICellViewModel } from 'vs/workbench/contrib/notebook/browser/notebookBrowser' ;
9
9
import { CellViewModelStateChangeEvent } from 'vs/workbench/contrib/notebook/browser/notebookViewEvents' ;
10
10
import { ICellExecutionStateChangedEvent } from 'vs/workbench/contrib/notebook/common/notebookExecutionStateService' ;
11
11
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
+ */
12
16
export abstract class CellContentPart extends Disposable {
13
17
protected currentCell : ICellViewModel | undefined ;
14
18
protected cellDisposables = new DisposableStore ( ) ;
@@ -64,6 +68,10 @@ export abstract class CellContentPart extends Disposable {
64
68
updateForExecutionState ( element : ICellViewModel , e : ICellExecutionStateChangedEvent ) : void { }
65
69
}
66
70
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
+ */
67
75
export abstract class CellOverlayPart extends Disposable {
68
76
protected currentCell : ICellViewModel | undefined ;
69
77
protected cellDisposables = new DisposableStore ( ) ;
@@ -114,10 +122,10 @@ export abstract class CellOverlayPart extends Disposable {
114
122
updateForExecutionState ( element : ICellViewModel , e : ICellExecutionStateChangedEvent ) : void { }
115
123
}
116
124
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 ( ) ;
121
129
122
130
constructor (
123
131
private readonly contentParts : readonly CellContentPart [ ] ,
@@ -147,10 +155,7 @@ export class CellPartsCollection {
147
155
part . renderCell ( element ) ;
148
156
}
149
157
150
- // schedule overlay parts rendering
151
- this . _scheduledOverlayRendering ?. dispose ( ) ;
152
-
153
- this . _scheduledOverlayRendering = DOM . modify ( ( ) => {
158
+ this . _scheduledOverlayRendering . value = DOM . modify ( ( ) => {
154
159
for ( const part of this . overlayParts ) {
155
160
part . renderCell ( element ) ;
156
161
}
@@ -188,9 +193,7 @@ export class CellPartsCollection {
188
193
part . updateState ( viewCell , e ) ;
189
194
}
190
195
191
- this . _scheduledOverlayUpdateState ?. dispose ( ) ;
192
-
193
- this . _scheduledOverlayUpdateState = DOM . modify ( ( ) => {
196
+ this . _scheduledOverlayUpdateState . value = DOM . modify ( ( ) => {
194
197
for ( const part of this . overlayParts ) {
195
198
part . updateState ( viewCell , e ) ;
196
199
}
@@ -202,11 +205,16 @@ export class CellPartsCollection {
202
205
part . updateForExecutionState ( viewCell , e ) ;
203
206
}
204
207
205
- this . _scheduledOverlayUpdateExecutionState ?. dispose ( ) ;
206
- this . _scheduledOverlayUpdateExecutionState = DOM . modify ( ( ) => {
208
+ this . _scheduledOverlayUpdateExecutionState . value = DOM . modify ( ( ) => {
207
209
for ( const part of this . overlayParts ) {
208
210
part . updateForExecutionState ( viewCell , e ) ;
209
211
}
210
212
} ) ;
211
213
}
214
+
215
+ dispose ( ) {
216
+ this . _scheduledOverlayRendering ?. dispose ( ) ;
217
+ this . _scheduledOverlayUpdateState ?. dispose ( ) ;
218
+ this . _scheduledOverlayUpdateExecutionState ?. dispose ( ) ;
219
+ }
212
220
}
0 commit comments