Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions src/vs/workbench/contrib/notebook/browser/view/cellPart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,50 @@ export abstract class CellPart extends Disposable {
*/
updateForExecutionState(element: ICellViewModel, e: ICellExecutionStateChangedEvent): void { }
}

export class CellPartsCollection {

constructor(
private readonly parts: readonly CellPart[],
) { }

concat(other: readonly CellPart[]): CellPartsCollection {
return new CellPartsCollection(this.parts.concat(other));
}

renderCell(element: ICellViewModel): void {
for (const part of this.parts) {
part.renderCell(element);
}
}

unrenderCell(element: ICellViewModel): void {
for (const part of this.parts) {
part.unrenderCell(element);
}
}

updateInternalLayoutNow(viewCell: ICellViewModel) {
for (const part of this.parts) {
part.updateInternalLayoutNow(viewCell);
}
}

prepareLayout() {
for (const part of this.parts) {
part.prepareLayout();
}
}

updateState(viewCell: ICellViewModel, e: CellViewModelStateChangeEvent) {
for (const part of this.parts) {
part.updateState(viewCell, e);
}
}

updateForExecutionState(viewCell: ICellViewModel, e: ICellExecutionStateChangedEvent) {
for (const part of this.parts) {
part.updateForExecutionState(viewCell, e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { IOpenerService } from 'vs/platform/opener/common/opener';
import { CellFocusMode, EXPAND_CELL_INPUT_COMMAND_ID, IActiveNotebookEditorDelegate } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { CellPartsCollection } from 'vs/workbench/contrib/notebook/browser/view/cellPart';
import { CellEditorOptions } from 'vs/workbench/contrib/notebook/browser/view/cellParts/cellEditorOptions';
import { CellOutputContainer } from 'vs/workbench/contrib/notebook/browser/view/cellParts/cellOutput';
import { CellPart } from 'vs/workbench/contrib/notebook/browser/view/cellPart';
import { CollapsedCodeCellExecutionIcon } from 'vs/workbench/contrib/notebook/browser/view/cellParts/codeCellExecutionIcon';
import { CodeCellRenderTemplate } from 'vs/workbench/contrib/notebook/browser/view/notebookRenderingCommon';
import { CodeCellViewModel } from 'vs/workbench/contrib/notebook/browser/viewModel/codeCellViewModel';
Expand All @@ -35,7 +35,7 @@ export class CodeCell extends Disposable {
private _renderedInputCollapseState: boolean | undefined;
private _renderedOutputCollapseState: boolean | undefined;
private _isDisposed: boolean = false;
private readonly cellParts: CellPart[];
private readonly cellParts: CellPartsCollection;

private _collapsedExecutionIcon: CollapsedCodeCellExecutionIcon;

Expand All @@ -55,7 +55,7 @@ export class CodeCell extends Disposable {

const cellEditorOptions = this._register(new CellEditorOptions(this.notebookEditor.getBaseCellEditorOptions(viewCell.language), this.notebookEditor.notebookOptions, this.configurationService));
this._outputContainerRenderer = this.instantiationService.createInstance(CellOutputContainer, notebookEditor, viewCell, templateData, { limit: 500 });
this.cellParts = [...templateData.cellParts, cellEditorOptions, this._outputContainerRenderer];
this.cellParts = templateData.cellParts.concat([cellEditorOptions, this._outputContainerRenderer]);

const editorHeight = this.calculateInitEditorHeight();
this.initializeEditor(editorHeight);
Expand All @@ -67,16 +67,12 @@ export class CodeCell extends Disposable {

this._register(notebookExecutionStateService.onDidChangeCellExecution(e => {
if (e.affectsCell(this.viewCell.uri)) {
this.cellParts.forEach(cellPart => {
cellPart.updateForExecutionState(this.viewCell, e);
});
this.cellParts.updateForExecutionState(this.viewCell, e);
}
}));

this._register(this.viewCell.onDidChangeState(e => {
this.cellParts.forEach(cellPart => {
cellPart.updateState(this.viewCell, e);
});
this.cellParts.updateState(this.viewCell, e);

if (e.outputIsHoveredChanged) {
this.updateForOutputHover();
Expand Down Expand Up @@ -104,9 +100,10 @@ export class CodeCell extends Disposable {
}
}));

this.cellParts.forEach(cellPart => cellPart.renderCell(this.viewCell));
this.cellParts.renderCell(this.viewCell);

this._register(toDisposable(() => {
this.cellParts.forEach(cellPart => cellPart.unrenderCell(this.viewCell));
this.cellParts.unrenderCell(this.viewCell);
}));

this.updateEditorOptions();
Expand All @@ -123,7 +120,7 @@ export class CodeCell extends Disposable {
}

this._register(this.viewCell.onLayoutInfoRead(() => {
this.cellParts.forEach(cellPart => cellPart.prepareLayout());
this.cellParts.prepareLayout();
}));

const executionItemElement = DOM.append(this.templateData.cellInputCollapsedContainer, DOM.$('.collapsed-execution-icon'));
Expand All @@ -146,9 +143,7 @@ export class CodeCell extends Disposable {
private updateForLayout(): void {
this._pendingLayout?.dispose();
this._pendingLayout = DOM.modify(() => {
this.cellParts.forEach(part => {
part.updateInternalLayoutNow(this.viewCell);
});
this.cellParts.updateInternalLayoutNow(this.viewCell);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ export class MarkupCell extends Disposable {
this.registerListeners();

// update for init state
this.templateData.cellParts.forEach(cellPart => cellPart.renderCell(this.viewCell));
this.templateData.cellParts.renderCell(this.viewCell);

this._register(toDisposable(() => {
this.templateData.cellParts.forEach(cellPart => cellPart.unrenderCell(this.viewCell));
this.templateData.cellParts.unrenderCell(this.viewCell);
}));

this._register(this.accessibilityService.onDidChangeScreenReaderOptimized(() => {
Expand Down Expand Up @@ -99,9 +100,7 @@ export class MarkupCell extends Disposable {
}

layoutCellParts() {
this.templateData.cellParts.forEach(part => {
part.updateInternalLayoutNow(this.viewCell);
});
this.templateData.cellParts.updateInternalLayoutNow(this.viewCell);
}

private constructDOM() {
Expand All @@ -123,9 +122,7 @@ export class MarkupCell extends Disposable {

private registerListeners() {
this._register(this.viewCell.onDidChangeState(e => {
this.templateData.cellParts.forEach(cellPart => {
cellPart.updateState(this.viewCell, e);
});
this.templateData.cellParts.updateState(this.viewCell, e);
}));

this._register(this.viewCell.model.onDidChangeMetadata(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { Range } from 'vs/editor/common/core/range';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { ICellOutputViewModel, ICellViewModel } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { CellPart } from 'vs/workbench/contrib/notebook/browser/view/cellPart';
import { CellPartsCollection } from 'vs/workbench/contrib/notebook/browser/view/cellPart';
import { CellViewModel, NotebookViewModel } from 'vs/workbench/contrib/notebook/browser/viewModel/notebookViewModelImpl';
import { ICellRange } from 'vs/workbench/contrib/notebook/common/notebookRange';

Expand Down Expand Up @@ -101,7 +101,7 @@ export interface BaseCellRenderTemplate {
readonly templateDisposables: DisposableStore;
readonly elementDisposables: DisposableStore;
currentRenderedCell?: ICellViewModel;
cellParts: CellPart[];
cellParts: CellPartsCollection;
toJSON: () => object;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { ServiceCollection } from 'vs/platform/instantiation/common/serviceColle
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { ICellViewModel, INotebookEditorDelegate } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { CellPartsCollection } from 'vs/workbench/contrib/notebook/browser/view/cellPart';
import { CellComments } from 'vs/workbench/contrib/notebook/browser/view/cellParts/cellComments';
import { CellContextKeyPart } from 'vs/workbench/contrib/notebook/browser/view/cellParts/cellContextKeys';
import { CellDecorations } from 'vs/workbench/contrib/notebook/browser/view/cellParts/cellDecorations';
Expand Down Expand Up @@ -164,7 +165,7 @@ export class MarkupCellRenderer extends AbstractCellRenderer implements IListRen
this.notebookEditor));
const focusIndicatorBottom = new FastDomNode(DOM.append(container, $('.cell-focus-indicator.cell-focus-indicator-bottom')));

const cellParts = [
const cellParts = new CellPartsCollection([
titleToolbar,
templateDisposables.add(scopedInstaService.createInstance(BetweenCellToolbar, this.notebookEditor, titleToolbarContainer, bottomCellContainer)),
templateDisposables.add(scopedInstaService.createInstance(CellEditorStatusBar, this.notebookEditor, container, editorPart, undefined)),
Expand All @@ -176,7 +177,7 @@ export class MarkupCellRenderer extends AbstractCellRenderer implements IListRen
templateDisposables.add(new CellFocusPart(container, undefined, this.notebookEditor)),
templateDisposables.add(new CellDragAndDropPart(container)),
templateDisposables.add(scopedInstaService.createInstance(CellContextKeyPart, this.notebookEditor)),
];
]);

const templateData: MarkdownCellRenderTemplate = {
rootContainer,
Expand Down Expand Up @@ -304,7 +305,7 @@ export class CodeCellRenderer extends AbstractCellRenderer implements IListRende
this.notebookEditor));

const focusIndicatorPart = templateDisposables.add(new CellFocusIndicator(this.notebookEditor, titleToolbar, focusIndicatorTop, focusIndicatorLeft, focusIndicatorRight, focusIndicatorBottom));
const cellParts = [
const cellParts = new CellPartsCollection([
focusIndicatorPart,
titleToolbar,
templateDisposables.add(scopedInstaService.createInstance(BetweenCellToolbar, this.notebookEditor, titleToolbarContainer, bottomCellToolbarContainer)),
Expand All @@ -319,7 +320,7 @@ export class CodeCellRenderer extends AbstractCellRenderer implements IListRende
templateDisposables.add(new CellFocusPart(container, focusSinkElement, this.notebookEditor)),
templateDisposables.add(new CellDragAndDropPart(container)),
templateDisposables.add(scopedInstaService.createInstance(CellContextKeyPart, this.notebookEditor)),
];
]);

const templateData: CodeCellRenderTemplate = {
rootContainer,
Expand Down