|
3 | 3 | * Licensed under the MIT License. See License.txt in the project root for license information.
|
4 | 4 | *--------------------------------------------------------------------------------------------*/
|
5 | 5 |
|
6 |
| -import { Disposable, DisposableStore } from 'vs/base/common/lifecycle'; |
| 6 | +import * as DOM from 'vs/base/browser/dom'; |
| 7 | +import { Disposable, DisposableStore, IDisposable } from 'vs/base/common/lifecycle'; |
7 | 8 | import { ICellViewModel } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
|
8 | 9 | import { CellViewModelStateChangeEvent } from 'vs/workbench/contrib/notebook/browser/notebookViewEvents';
|
9 | 10 | import { ICellExecutionStateChangedEvent } from 'vs/workbench/contrib/notebook/common/notebookExecutionStateService';
|
10 | 11 |
|
11 |
| -export abstract class CellPart extends Disposable { |
| 12 | +export abstract class CellContentPart extends Disposable { |
12 | 13 | protected currentCell: ICellViewModel | undefined;
|
13 | 14 | protected cellDisposables = new DisposableStore();
|
14 | 15 |
|
15 | 16 | constructor() {
|
16 | 17 | super();
|
17 | 18 | }
|
18 | 19 |
|
| 20 | + /** |
| 21 | + * Prepare model for cell part rendering |
| 22 | + * No DOM operations recommended within this operation |
| 23 | + */ |
| 24 | + prepareRenderCell(element: ICellViewModel): void { } |
| 25 | + |
19 | 26 | /**
|
20 | 27 | * Update the DOM for the cell `element`
|
21 | 28 | */
|
@@ -57,49 +64,149 @@ export abstract class CellPart extends Disposable {
|
57 | 64 | updateForExecutionState(element: ICellViewModel, e: ICellExecutionStateChangedEvent): void { }
|
58 | 65 | }
|
59 | 66 |
|
| 67 | +export abstract class CellOverlayPart extends Disposable { |
| 68 | + protected currentCell: ICellViewModel | undefined; |
| 69 | + protected cellDisposables = new DisposableStore(); |
| 70 | + |
| 71 | + constructor() { |
| 72 | + super(); |
| 73 | + } |
| 74 | + |
| 75 | + /** |
| 76 | + * Prepare model for cell part rendering |
| 77 | + * No DOM operations recommended within this operation |
| 78 | + */ |
| 79 | + prepareRenderCell(element: ICellViewModel): void { } |
| 80 | + |
| 81 | + /** |
| 82 | + * Update the DOM for the cell `element` |
| 83 | + */ |
| 84 | + renderCell(element: ICellViewModel): void { |
| 85 | + this.currentCell = element; |
| 86 | + this.didRenderCell(element); |
| 87 | + } |
| 88 | + |
| 89 | + protected didRenderCell(element: ICellViewModel): void { } |
| 90 | + |
| 91 | + /** |
| 92 | + * Dispose any disposables generated from `didRenderCell` |
| 93 | + */ |
| 94 | + unrenderCell(element: ICellViewModel): void { |
| 95 | + this.currentCell = undefined; |
| 96 | + this.cellDisposables.clear(); |
| 97 | + } |
| 98 | + |
| 99 | + /** |
| 100 | + * Update internal DOM (top positions) per cell layout info change |
| 101 | + * Note that a cell part doesn't need to call `DOM.scheduleNextFrame`, |
| 102 | + * the list view will ensure that layout call is invoked in the right frame |
| 103 | + */ |
| 104 | + updateInternalLayoutNow(element: ICellViewModel): void { } |
| 105 | + |
| 106 | + /** |
| 107 | + * Update per cell state change |
| 108 | + */ |
| 109 | + updateState(element: ICellViewModel, e: CellViewModelStateChangeEvent): void { } |
| 110 | + |
| 111 | + /** |
| 112 | + * Update per execution state change. |
| 113 | + */ |
| 114 | + updateForExecutionState(element: ICellViewModel, e: ICellExecutionStateChangedEvent): void { } |
| 115 | +} |
| 116 | + |
60 | 117 | export class CellPartsCollection {
|
| 118 | + private _scheduledOverlayRendering: IDisposable | undefined; |
| 119 | + private _scheduledOverlayUpdateState: IDisposable | undefined; |
| 120 | + private _scheduledOverlayUpdateExecutionState: IDisposable | undefined; |
61 | 121 |
|
62 | 122 | constructor(
|
63 |
| - private readonly parts: readonly CellPart[], |
| 123 | + private readonly contentParts: readonly CellContentPart[], |
| 124 | + private readonly overlayParts: readonly CellOverlayPart[] |
64 | 125 | ) { }
|
65 | 126 |
|
66 |
| - concat(other: readonly CellPart[]): CellPartsCollection { |
67 |
| - return new CellPartsCollection(this.parts.concat(other)); |
| 127 | + concatContentPart(other: readonly CellContentPart[]): CellPartsCollection { |
| 128 | + return new CellPartsCollection(this.contentParts.concat(other), this.overlayParts); |
68 | 129 | }
|
69 | 130 |
|
70 |
| - renderCell(element: ICellViewModel): void { |
71 |
| - for (const part of this.parts) { |
| 131 | + concatOverlayPart(other: readonly CellOverlayPart[]): CellPartsCollection { |
| 132 | + return new CellPartsCollection(this.contentParts, this.overlayParts.concat(other)); |
| 133 | + } |
| 134 | + |
| 135 | + scheduleRenderCell(element: ICellViewModel): void { |
| 136 | + // prepare model |
| 137 | + for (const part of this.contentParts) { |
| 138 | + part.prepareRenderCell(element); |
| 139 | + } |
| 140 | + |
| 141 | + for (const part of this.overlayParts) { |
| 142 | + part.prepareRenderCell(element); |
| 143 | + } |
| 144 | + |
| 145 | + // render content parts |
| 146 | + for (const part of this.contentParts) { |
72 | 147 | part.renderCell(element);
|
73 | 148 | }
|
| 149 | + |
| 150 | + // schedule overlay parts rendering |
| 151 | + this._scheduledOverlayRendering?.dispose(); |
| 152 | + |
| 153 | + this._scheduledOverlayRendering = DOM.modify(() => { |
| 154 | + for (const part of this.overlayParts) { |
| 155 | + part.renderCell(element); |
| 156 | + } |
| 157 | + }); |
74 | 158 | }
|
75 | 159 |
|
76 | 160 | unrenderCell(element: ICellViewModel): void {
|
77 |
| - for (const part of this.parts) { |
| 161 | + for (const part of this.contentParts) { |
| 162 | + part.unrenderCell(element); |
| 163 | + } |
| 164 | + |
| 165 | + this._scheduledOverlayRendering?.dispose(); |
| 166 | + this._scheduledOverlayUpdateState?.dispose(); |
| 167 | + this._scheduledOverlayUpdateExecutionState?.dispose(); |
| 168 | + |
| 169 | + for (const part of this.overlayParts) { |
78 | 170 | part.unrenderCell(element);
|
79 | 171 | }
|
80 | 172 | }
|
81 | 173 |
|
82 | 174 | updateInternalLayoutNow(viewCell: ICellViewModel) {
|
83 |
| - for (const part of this.parts) { |
| 175 | + for (const part of this.contentParts) { |
84 | 176 | part.updateInternalLayoutNow(viewCell);
|
85 | 177 | }
|
86 | 178 | }
|
87 | 179 |
|
88 | 180 | prepareLayout() {
|
89 |
| - for (const part of this.parts) { |
| 181 | + for (const part of this.contentParts) { |
90 | 182 | part.prepareLayout();
|
91 | 183 | }
|
92 | 184 | }
|
93 | 185 |
|
94 | 186 | updateState(viewCell: ICellViewModel, e: CellViewModelStateChangeEvent) {
|
95 |
| - for (const part of this.parts) { |
| 187 | + for (const part of this.contentParts) { |
96 | 188 | part.updateState(viewCell, e);
|
97 | 189 | }
|
| 190 | + |
| 191 | + this._scheduledOverlayUpdateState?.dispose(); |
| 192 | + |
| 193 | + this._scheduledOverlayUpdateState = DOM.modify(() => { |
| 194 | + for (const part of this.overlayParts) { |
| 195 | + part.updateState(viewCell, e); |
| 196 | + } |
| 197 | + }); |
98 | 198 | }
|
99 | 199 |
|
100 | 200 | updateForExecutionState(viewCell: ICellViewModel, e: ICellExecutionStateChangedEvent) {
|
101 |
| - for (const part of this.parts) { |
| 201 | + for (const part of this.contentParts) { |
102 | 202 | part.updateForExecutionState(viewCell, e);
|
103 | 203 | }
|
| 204 | + |
| 205 | + this._scheduledOverlayUpdateExecutionState?.dispose(); |
| 206 | + this._scheduledOverlayUpdateExecutionState = DOM.modify(() => { |
| 207 | + for (const part of this.overlayParts) { |
| 208 | + part.updateForExecutionState(viewCell, e); |
| 209 | + } |
| 210 | + }); |
104 | 211 | }
|
105 | 212 | }
|
0 commit comments