Skip to content

Commit f9fb40f

Browse files
committed
Separate content and overlay.
1 parent 0c12170 commit f9fb40f

22 files changed

+426
-244
lines changed

src/vs/workbench/contrib/notebook/browser/docs/viewport-rendering.drawio.svg

Lines changed: 147 additions & 147 deletions
Loading

src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,14 @@ const $ = DOM.$;
8989

9090
export function getDefaultNotebookCreationOptions(): INotebookEditorCreationOptions {
9191
// We inlined the id to avoid loading comment contrib in tests
92-
const skipContributions = ['editor.contrib.review', FloatingClickMenu.ID];
92+
const skipContributions = [
93+
'editor.contrib.review',
94+
FloatingClickMenu.ID,
95+
'editor.contrib.dirtydiff',
96+
'editor.contrib.testingOutputPeek',
97+
'editor.contrib.testingDecorations',
98+
'store.contrib.stickyScrollController'
99+
];
93100
const contributions = EditorExtensionsRegistry.getEditorContributions().filter(c => skipContributions.indexOf(c.id) === -1);
94101

95102
return {

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

Lines changed: 119 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,26 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

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';
78
import { ICellViewModel } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
89
import { CellViewModelStateChangeEvent } from 'vs/workbench/contrib/notebook/browser/notebookViewEvents';
910
import { ICellExecutionStateChangedEvent } from 'vs/workbench/contrib/notebook/common/notebookExecutionStateService';
1011

11-
export abstract class CellPart extends Disposable {
12+
export abstract class CellContentPart extends Disposable {
1213
protected currentCell: ICellViewModel | undefined;
1314
protected cellDisposables = new DisposableStore();
1415

1516
constructor() {
1617
super();
1718
}
1819

20+
/**
21+
* Prepare model for cell part rendering
22+
* No DOM operations recommended within this operation
23+
*/
24+
prepareRenderCell(element: ICellViewModel): void { }
25+
1926
/**
2027
* Update the DOM for the cell `element`
2128
*/
@@ -57,49 +64,149 @@ export abstract class CellPart extends Disposable {
5764
updateForExecutionState(element: ICellViewModel, e: ICellExecutionStateChangedEvent): void { }
5865
}
5966

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+
60117
export class CellPartsCollection {
118+
private _scheduledOverlayRendering: IDisposable | undefined;
119+
private _scheduledOverlayUpdateState: IDisposable | undefined;
120+
private _scheduledOverlayUpdateExecutionState: IDisposable | undefined;
61121

62122
constructor(
63-
private readonly parts: readonly CellPart[],
123+
private readonly contentParts: readonly CellContentPart[],
124+
private readonly overlayParts: readonly CellOverlayPart[]
64125
) { }
65126

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);
68129
}
69130

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) {
72147
part.renderCell(element);
73148
}
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+
});
74158
}
75159

76160
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) {
78170
part.unrenderCell(element);
79171
}
80172
}
81173

82174
updateInternalLayoutNow(viewCell: ICellViewModel) {
83-
for (const part of this.parts) {
175+
for (const part of this.contentParts) {
84176
part.updateInternalLayoutNow(viewCell);
85177
}
86178
}
87179

88180
prepareLayout() {
89-
for (const part of this.parts) {
181+
for (const part of this.contentParts) {
90182
part.prepareLayout();
91183
}
92184
}
93185

94186
updateState(viewCell: ICellViewModel, e: CellViewModelStateChangeEvent) {
95-
for (const part of this.parts) {
187+
for (const part of this.contentParts) {
96188
part.updateState(viewCell, e);
97189
}
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+
});
98198
}
99199

100200
updateForExecutionState(viewCell: ICellViewModel, e: ICellExecutionStateChangedEvent) {
101-
for (const part of this.parts) {
201+
for (const part of this.contentParts) {
102202
part.updateForExecutionState(viewCell, e);
103203
}
204+
205+
this._scheduledOverlayUpdateExecutionState?.dispose();
206+
this._scheduledOverlayUpdateExecutionState = DOM.modify(() => {
207+
for (const part of this.overlayParts) {
208+
part.updateForExecutionState(viewCell, e);
209+
}
210+
});
104211
}
105212
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ import { IThemeService } from 'vs/platform/theme/common/themeService';
1414
import { ICommentService } from 'vs/workbench/contrib/comments/browser/commentService';
1515
import { CommentThreadWidget } from 'vs/workbench/contrib/comments/browser/commentThreadWidget';
1616
import { ICellViewModel, INotebookEditorDelegate } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
17-
import { CellPart } from 'vs/workbench/contrib/notebook/browser/view/cellPart';
17+
import { CellContentPart } from 'vs/workbench/contrib/notebook/browser/view/cellPart';
1818
import { CodeCellViewModel } from 'vs/workbench/contrib/notebook/browser/viewModel/codeCellViewModel';
1919
import { CellKind } from 'vs/workbench/contrib/notebook/common/notebookCommon';
2020
import { ICellRange } from 'vs/workbench/contrib/notebook/common/notebookRange';
2121

22-
export class CellComments extends CellPart {
22+
export class CellComments extends CellContentPart {
2323
private _initialized: boolean = false;
2424
private _commentThreadWidget: CommentThreadWidget<ICellRange> | null = null;
2525
private currentElement: CodeCellViewModel | undefined;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/c
88
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
99
import { CellEditState, CellFocusMode, ICellViewModel, INotebookEditorDelegate } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
1010
import { CellViewModelStateChangeEvent } from 'vs/workbench/contrib/notebook/browser/notebookViewEvents';
11-
import { CellPart } from 'vs/workbench/contrib/notebook/browser/view/cellPart';
11+
import { CellContentPart } from 'vs/workbench/contrib/notebook/browser/view/cellPart';
1212
import { CodeCellViewModel } from 'vs/workbench/contrib/notebook/browser/viewModel/codeCellViewModel';
1313
import { MarkupCellViewModel } from 'vs/workbench/contrib/notebook/browser/viewModel/markupCellViewModel';
1414
import { NotebookCellExecutionState } from 'vs/workbench/contrib/notebook/common/notebookCommon';
1515
import { NotebookCellExecutionStateContext, NOTEBOOK_CELL_EDITABLE, NOTEBOOK_CELL_EDITOR_FOCUSED, NOTEBOOK_CELL_EXECUTING, NOTEBOOK_CELL_EXECUTION_STATE, NOTEBOOK_CELL_FOCUSED, NOTEBOOK_CELL_HAS_OUTPUTS, NOTEBOOK_CELL_INPUT_COLLAPSED, NOTEBOOK_CELL_LINE_NUMBERS, NOTEBOOK_CELL_MARKDOWN_EDIT_MODE, NOTEBOOK_CELL_OUTPUT_COLLAPSED, NOTEBOOK_CELL_RESOURCE, NOTEBOOK_CELL_TYPE } from 'vs/workbench/contrib/notebook/common/notebookContextKeys';
1616
import { INotebookExecutionStateService } from 'vs/workbench/contrib/notebook/common/notebookExecutionStateService';
1717

18-
export class CellContextKeyPart extends CellPart {
18+
export class CellContextKeyPart extends CellContentPart {
1919
private cellContextKeyManager: CellContextKeyManager;
2020

2121
constructor(

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55

66
import * as DOM from 'vs/base/browser/dom';
77
import { ICellViewModel } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
8-
import { CellPart } from 'vs/workbench/contrib/notebook/browser/view/cellPart';
8+
import { CellContentPart } from 'vs/workbench/contrib/notebook/browser/view/cellPart';
99

10-
export class CellDecorations extends CellPart {
10+
export class CellDecorations extends CellContentPart {
1111
constructor(
1212
readonly rootContainer: HTMLElement,
1313
readonly decorationContainer: HTMLElement,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { Disposable, MutableDisposable } from 'vs/base/common/lifecycle';
99
import * as platform from 'vs/base/common/platform';
1010
import { expandCellRangesWithHiddenCells, ICellViewModel, INotebookEditorDelegate } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
1111
import { CellViewModelStateChangeEvent } from 'vs/workbench/contrib/notebook/browser/notebookViewEvents';
12-
import { CellPart } from 'vs/workbench/contrib/notebook/browser/view/cellPart';
12+
import { CellContentPart } from 'vs/workbench/contrib/notebook/browser/view/cellPart';
1313
import { BaseCellRenderTemplate, INotebookCellList } from 'vs/workbench/contrib/notebook/browser/view/notebookRenderingCommon';
1414
import { cloneNotebookCellTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookCellTextModel';
1515
import { CellEditType, ICellMoveEdit, SelectionStateType } from 'vs/workbench/contrib/notebook/common/notebookCommon';
@@ -30,7 +30,7 @@ interface CellDragEvent {
3030
dragPosRatio: number;
3131
}
3232

33-
export class CellDragAndDropPart extends CellPart {
33+
export class CellDragAndDropPart extends CellContentPart {
3434
constructor(
3535
private readonly container: HTMLElement
3636
) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ import { ActiveEditorContext } from 'vs/workbench/common/contextkeys';
1717
import { INotebookCellToolbarActionContext, INotebookCommandContext, NotebookMultiCellAction, NOTEBOOK_ACTIONS_CATEGORY } from 'vs/workbench/contrib/notebook/browser/controller/coreActions';
1818
import { IBaseCellEditorOptions, ICellViewModel } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
1919
import { NOTEBOOK_CELL_LINE_NUMBERS, NOTEBOOK_EDITOR_FOCUSED } from 'vs/workbench/contrib/notebook/common/notebookContextKeys';
20-
import { CellPart } from 'vs/workbench/contrib/notebook/browser/view/cellPart';
20+
import { CellContentPart } from 'vs/workbench/contrib/notebook/browser/view/cellPart';
2121
import { NotebookCellInternalMetadata, NOTEBOOK_EDITOR_ID } from 'vs/workbench/contrib/notebook/common/notebookCommon';
2222
import { NotebookOptions } from 'vs/workbench/contrib/notebook/common/notebookOptions';
2323
import { CellViewModelStateChangeEvent } from 'vs/workbench/contrib/notebook/browser/notebookViewEvents';
2424

25-
export class CellEditorOptions extends CellPart {
25+
export class CellEditorOptions extends CellContentPart {
2626
private _lineNumbers: 'on' | 'off' | 'inherit' = 'inherit';
2727
private readonly _onDidChange = this._register(new Emitter<void>());
2828
readonly onDidChange: Event<void> = this._onDidChange.event;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ import { disposableTimeout } from 'vs/base/common/async';
88
import { DisposableStore } from 'vs/base/common/lifecycle';
99
import { ICellViewModel, INotebookEditorDelegate } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
1010
import { CellViewModelStateChangeEvent } from 'vs/workbench/contrib/notebook/browser/notebookViewEvents';
11-
import { CellPart } from 'vs/workbench/contrib/notebook/browser/view/cellPart';
11+
import { CellContentPart } from 'vs/workbench/contrib/notebook/browser/view/cellPart';
1212
import { NotebookCellInternalMetadata } from 'vs/workbench/contrib/notebook/common/notebookCommon';
1313
import { INotebookExecutionStateService } from 'vs/workbench/contrib/notebook/common/notebookExecutionStateService';
1414

1515
const UPDATE_EXECUTION_ORDER_GRACE_PERIOD = 200;
1616

17-
export class CellExecutionPart extends CellPart {
17+
export class CellExecutionPart extends CellContentPart {
1818
private kernelDisposables = this._register(new DisposableStore());
1919

2020
constructor(

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

66
import * as DOM from 'vs/base/browser/dom';
77
import { INotebookEditor } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
8-
import { CellPart } from 'vs/workbench/contrib/notebook/browser/view/cellPart';
8+
import { CellContentPart } from 'vs/workbench/contrib/notebook/browser/view/cellPart';
99
import { CodeCellViewModel } from 'vs/workbench/contrib/notebook/browser/viewModel/codeCellViewModel';
1010

11-
export class CellFocusPart extends CellPart {
11+
export class CellFocusPart extends CellContentPart {
1212
constructor(
1313
containerElement: HTMLElement,
1414
focusSinkElement: HTMLElement | undefined,

0 commit comments

Comments
 (0)