Skip to content

Commit

Permalink
Move Cell Decorations to CellPart
Browse files Browse the repository at this point in the history
  • Loading branch information
rebornix committed Mar 17, 2022
1 parent 27e2f3a commit eef0ee4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,42 @@
*--------------------------------------------------------------------------------------------*/

import * as DOM from 'vs/base/browser/dom';
import { Disposable } from 'vs/base/common/lifecycle';
import { ICellViewModel } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { CellViewModelStateChangeEvent } from 'vs/workbench/contrib/notebook/browser/notebookViewEvents';
import { CellPart } from 'vs/workbench/contrib/notebook/browser/view/cellParts/cellPart';
import { BaseCellRenderTemplate } from 'vs/workbench/contrib/notebook/browser/view/notebookRenderingCommon';

export class CellDecorations extends Disposable {
export class CellDecorations extends CellPart {
constructor(
rootContainer: HTMLElement,
decorationContainer: HTMLElement,
element: ICellViewModel
readonly rootContainer: HTMLElement,
readonly decorationContainer: HTMLElement,
) {
super();
}

renderCell(element: ICellViewModel, templateData: BaseCellRenderTemplate): void {
const removedClassNames: string[] = [];
rootContainer.classList.forEach(className => {
this.rootContainer.classList.forEach(className => {
if (/^nb\-.*$/.test(className)) {
removedClassNames.push(className);
}
});

removedClassNames.forEach(className => {
rootContainer.classList.remove(className);
this.rootContainer.classList.remove(className);
});

decorationContainer.innerText = '';
this.decorationContainer.innerText = '';

const generateCellTopDecorations = () => {
decorationContainer.innerText = '';
this.decorationContainer.innerText = '';

element.getCellDecorations().filter(options => options.topClassName !== undefined).forEach(options => {
decorationContainer.append(DOM.$(`.${options.topClassName!}`));
this.decorationContainer.append(DOM.$(`.${options.topClassName!}`));
});
};

this._register(element.onCellDecorationsChanged((e) => {
templateData.elementDisposables.add(element.onCellDecorationsChanged((e) => {
const modified = e.added.find(e => e.topClassName) || e.removed.find(e => e.topClassName);

if (modified) {
Expand All @@ -46,4 +49,13 @@ export class CellDecorations extends Disposable {

generateCellTopDecorations();
}

prepareLayout(): void {
}

updateInternalLayoutNow(element: ICellViewModel): void {
}

updateState(element: ICellViewModel, e: CellViewModelStateChangeEvent): void {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ export interface BaseCellRenderTemplate {
instantiationService: IInstantiationService;
container: HTMLElement;
cellContainer: HTMLElement;
decorationContainer: HTMLElement;
readonly templateDisposables: DisposableStore;
readonly elementDisposables: DisposableStore;
currentRenderedCell?: ICellViewModel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ abstract class AbstractCellRenderer {
}

protected commonRenderElement(element: ICellViewModel, templateData: BaseCellRenderTemplate): void {
templateData.elementDisposables.add(new CellDecorations(templateData.rootContainer, templateData.decorationContainer, element));
}
}

Expand Down Expand Up @@ -170,12 +169,15 @@ export class MarkupCellRenderer extends AbstractCellRenderer implements IListRen
const foldedCellHint = templateDisposables.add(scopedInstaService.createInstance(FoldedCellHint, this.notebookEditor, DOM.append(container, $('.notebook-folded-hint'))));

const focusIndicator = templateDisposables.add(new CellFocusIndicator(this.notebookEditor, titleToolbar, focusIndicatorTop, focusIndicatorLeft, focusIndicatorRight, focusIndicatorBottom));
const cellDecorationsPart = templateDisposables.add(new CellDecorations(rootContainer, decorationContainer));

const cellParts = [
betweenCellToolbar,
titleToolbar,
statusBar,
focusIndicator,
foldedCellHint,
cellDecorationsPart,
templateDisposables.add(new CollapsedCellInput(this.notebookEditor, cellInputCollapsedContainer)),
templateDisposables.add(new CellFocusPart(container, undefined, this.notebookEditor)),
templateDisposables.add(new CellDragAndDropPart(container)),
Expand All @@ -187,7 +189,6 @@ export class MarkupCellRenderer extends AbstractCellRenderer implements IListRen
cellInputCollapsedContainer,
instantiationService: scopedInstaService,
container,
decorationContainer,
cellContainer: innerContent,
editorPart,
editorContainer,
Expand Down Expand Up @@ -319,13 +320,15 @@ export class CodeCellRenderer extends AbstractCellRenderer implements IListRende
this.notebookEditor));

const focusIndicatorPart = templateDisposables.add(new CellFocusIndicator(this.notebookEditor, titleToolbar, focusIndicatorTop, focusIndicatorLeft, focusIndicatorRight, focusIndicatorBottom));
const cellDecorationsPart = templateDisposables.add(new CellDecorations(rootContainer, decorationContainer));
const cellParts = [
focusIndicatorPart,
templateDisposables.add(scopedInstaService.createInstance(BetweenCellToolbar, this.notebookEditor, titleToolbarContainer, bottomCellToolbarContainer)),
statusBar,
progressBar,
titleToolbar,
runToolbar,
cellDecorationsPart,
templateDisposables.add(new CellExecutionPart(this.notebookEditor, executionOrderLabel)),
templateDisposables.add(this.instantiationService.createInstance(CollapsedCellOutput, this.notebookEditor, cellOutputCollapsedContainer)),
templateDisposables.add(new CollapsedCellInput(this.notebookEditor, cellInputCollapsedContainer)),
Expand All @@ -341,7 +344,6 @@ export class CodeCellRenderer extends AbstractCellRenderer implements IListRende
cellOutputCollapsedContainer,
instantiationService: scopedInstaService,
container,
decorationContainer,
cellContainer,
statusBar,
focusSinkElement,
Expand Down

0 comments on commit eef0ee4

Please sign in to comment.