mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 13:00:58 +00:00
Simplify markup cell renderElement.
This commit is contained in:
parent
7a9cf6dbba
commit
8f37bcaf6e
|
@ -253,6 +253,7 @@ export interface ICellViewModel extends IGenericCellViewModel {
|
|||
readonly onDidChangeLayout: Event<{ totalHeight?: boolean | number; outerWidth?: number; }>;
|
||||
readonly onDidChangeCellStatusBarItems: Event<void>;
|
||||
readonly onCellDecorationsChanged: Event<{ added: INotebookCellDecorationOptions[], removed: INotebookCellDecorationOptions[] }>;
|
||||
readonly onDidChangeState: Event<CellViewModelStateChangeEvent>;
|
||||
readonly editStateSource: string;
|
||||
readonly editorAttached: boolean;
|
||||
isInputCollapsed: boolean;
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
import { Disposable, DisposableStore } from 'vs/base/common/lifecycle';
|
||||
import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { CellEditState, CellFocusMode, CellViewModelStateChangeEvent, INotebookEditorDelegate, 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_TYPE } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
|
||||
import { CellEditState, CellFocusMode, CellViewModelStateChangeEvent, ICellViewModel, INotebookEditorDelegate, 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_TYPE } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
|
||||
import { CodeCellViewModel } from 'vs/workbench/contrib/notebook/browser/viewModel/codeCellViewModel';
|
||||
import { MarkupCellViewModel } from 'vs/workbench/contrib/notebook/browser/viewModel/markupCellViewModel';
|
||||
import { NotebookCellExecutionState } from 'vs/workbench/contrib/notebook/common/notebookCommon';
|
||||
|
@ -30,7 +30,7 @@ export class CellContextKeyManager extends Disposable {
|
|||
constructor(
|
||||
private readonly contextKeyService: IContextKeyService,
|
||||
private readonly notebookEditor: INotebookEditorDelegate,
|
||||
private element: CodeCellViewModel | MarkupCellViewModel
|
||||
private element: ICellViewModel
|
||||
) {
|
||||
super();
|
||||
|
||||
|
@ -51,7 +51,7 @@ export class CellContextKeyManager extends Disposable {
|
|||
});
|
||||
}
|
||||
|
||||
public updateForElement(element: MarkupCellViewModel | CodeCellViewModel) {
|
||||
public updateForElement(element: ICellViewModel) {
|
||||
this.elementDisposables.clear();
|
||||
this.elementDisposables.add(element.onDidChangeState(e => this.onDidChangeState(e)));
|
||||
|
||||
|
|
|
@ -287,6 +287,8 @@ abstract class AbstractCellRenderer {
|
|||
} else {
|
||||
templateData.container.classList.remove(DRAGGING_CLASS);
|
||||
}
|
||||
|
||||
templateData.elementDisposables.add(new CellContextKeyManager(templateData.contextKeyService, this.notebookEditor, element));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -298,7 +300,7 @@ export class MarkupCellRenderer extends AbstractCellRenderer implements IListRen
|
|||
dndController: CellDragAndDropController,
|
||||
private renderedEditors: Map<ICellViewModel, ICodeEditor | undefined>,
|
||||
contextKeyServiceProvider: (container: HTMLElement) => IContextKeyService,
|
||||
@IConfigurationService private configurationService: IConfigurationService,
|
||||
@IConfigurationService configurationService: IConfigurationService,
|
||||
@IInstantiationService instantiationService: IInstantiationService,
|
||||
@IContextMenuService contextMenuService: IContextMenuService,
|
||||
@IMenuService menuService: IMenuService,
|
||||
|
@ -392,32 +394,12 @@ export class MarkupCellRenderer extends AbstractCellRenderer implements IListRen
|
|||
}
|
||||
|
||||
const elementDisposables = templateData.elementDisposables;
|
||||
elementDisposables.add(new CellContextKeyManager(templateData.contextKeyService, this.notebookEditor, element));
|
||||
|
||||
this.updateForLayout(element, templateData);
|
||||
elementDisposables.add(element.onDidChangeLayout(() => {
|
||||
this.updateForLayout(element, templateData);
|
||||
}));
|
||||
|
||||
this.updateForHover(element, templateData);
|
||||
const cellEditorOptions = new CellEditorOptions(this.notebookEditor, this.notebookEditor.notebookOptions, this.configurationService, element.language);
|
||||
cellEditorOptions.setLineNumbers(element.lineNumbers);
|
||||
elementDisposables.add(cellEditorOptions);
|
||||
|
||||
elementDisposables.add(element.onDidChangeState(e => {
|
||||
if (e.cellIsHoveredChanged) {
|
||||
this.updateForHover(element, templateData);
|
||||
}
|
||||
|
||||
if (e.inputCollapsedChanged) {
|
||||
this.updateCollapsedState(element);
|
||||
}
|
||||
|
||||
if (e.cellLineNumberChanged) {
|
||||
cellEditorOptions.setLineNumbers(element.lineNumbers);
|
||||
}
|
||||
}));
|
||||
|
||||
// render toolbar first
|
||||
this.setupCellToolbarActions(templateData, elementDisposables);
|
||||
|
||||
|
@ -433,10 +415,8 @@ export class MarkupCellRenderer extends AbstractCellRenderer implements IListRen
|
|||
this.setBetweenCellToolbarContext(templateData, element, toolbarContext);
|
||||
|
||||
const scopedInstaService = this.instantiationService.createChild(new ServiceCollection([IContextKeyService, templateData.contextKeyService]));
|
||||
const markdownCell = scopedInstaService.createInstance(StatefulMarkdownCell, this.notebookEditor, element, templateData, cellEditorOptions.getValue(element.internalMetadata), this.renderedEditors,);
|
||||
const markdownCell = scopedInstaService.createInstance(StatefulMarkdownCell, this.notebookEditor, element, templateData, this.renderedEditors);
|
||||
elementDisposables.add(markdownCell);
|
||||
elementDisposables.add(cellEditorOptions.onDidChange(newValue => markdownCell.updateEditorOptions(cellEditorOptions.getUpdatedValue(element.internalMetadata))));
|
||||
|
||||
templateData.statusBar.update(toolbarContext);
|
||||
}
|
||||
|
||||
|
@ -450,18 +430,6 @@ export class MarkupCellRenderer extends AbstractCellRenderer implements IListRen
|
|||
templateData.container.classList.toggle('cell-statusbar-hidden', this.notebookEditor.notebookOptions.computeEditorStatusbarHeight(element.internalMetadata) === 0);
|
||||
}
|
||||
|
||||
private updateForHover(element: MarkupCellViewModel, templateData: MarkdownCellRenderTemplate): void {
|
||||
templateData.container.classList.toggle('markdown-cell-hover', element.cellIsHovered);
|
||||
}
|
||||
|
||||
private updateCollapsedState(element: MarkupCellViewModel) {
|
||||
if (element.isInputCollapsed) {
|
||||
this.notebookEditor.hideMarkupPreviews([element]);
|
||||
} else {
|
||||
this.notebookEditor.unhideMarkupPreviews([element]);
|
||||
}
|
||||
}
|
||||
|
||||
disposeTemplate(templateData: MarkdownCellRenderTemplate): void {
|
||||
templateData.disposables.clear();
|
||||
}
|
||||
|
@ -961,8 +929,6 @@ export class CodeCellRenderer extends AbstractCellRenderer implements IListRende
|
|||
elementDisposables.add(cellEditorOptions.onDidChange(() => templateData.editor.updateOptions(cellEditorOptions.getUpdatedValue(element.internalMetadata))));
|
||||
templateData.editor.updateOptions(cellEditorOptions.getUpdatedValue(element.internalMetadata));
|
||||
|
||||
elementDisposables.add(new CellContextKeyManager(templateData.contextKeyService, this.notebookEditor, element));
|
||||
|
||||
this.updateForLayout(element, templateData);
|
||||
elementDisposables.add(element.onDidChangeLayout(() => {
|
||||
this.updateForLayout(element, templateData);
|
||||
|
|
|
@ -25,6 +25,8 @@ import { tokenizeToString } from 'vs/editor/common/modes/textToHtmlTokenizer';
|
|||
import { TokenizationRegistry } from 'vs/editor/common/modes';
|
||||
import { MarkdownCellRenderTemplate } from 'vs/workbench/contrib/notebook/browser/view/notebookRenderingCommon';
|
||||
import { IModeService } from 'vs/editor/common/services/modeService';
|
||||
import { CellEditorOptions } from 'vs/workbench/contrib/notebook/browser/view/renderers/cellEditorOptions';
|
||||
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
|
||||
|
||||
|
||||
export class StatefulMarkdownCell extends Disposable {
|
||||
|
@ -38,26 +40,34 @@ export class StatefulMarkdownCell extends Disposable {
|
|||
private readonly focusSwitchDisposable = this._register(new MutableDisposable());
|
||||
private readonly editorDisposables = this._register(new DisposableStore());
|
||||
private foldingState: CellFoldingState;
|
||||
private cellEditorOptions: CellEditorOptions;
|
||||
private editorOptions: IEditorOptions;
|
||||
|
||||
constructor(
|
||||
private readonly notebookEditor: IActiveNotebookEditorDelegate,
|
||||
private readonly viewCell: MarkupCellViewModel,
|
||||
private readonly templateData: MarkdownCellRenderTemplate,
|
||||
private editorOptions: IEditorOptions,
|
||||
private readonly renderedEditors: Map<ICellViewModel, ICodeEditor | undefined>,
|
||||
@IContextKeyService private readonly contextKeyService: IContextKeyService,
|
||||
@INotebookCellStatusBarService readonly notebookCellStatusBarService: INotebookCellStatusBarService,
|
||||
@IInstantiationService private readonly instantiationService: IInstantiationService,
|
||||
@IModeService private readonly modeService: IModeService,
|
||||
@IConfigurationService private configurationService: IConfigurationService,
|
||||
) {
|
||||
super();
|
||||
|
||||
this.constructDOM();
|
||||
this.editorPart = templateData.editorPart;
|
||||
|
||||
this.cellEditorOptions = this._register(new CellEditorOptions(this.notebookEditor, this.notebookEditor.notebookOptions, this.configurationService, this.viewCell.language));
|
||||
this.cellEditorOptions.setLineNumbers(this.viewCell.lineNumbers);
|
||||
this.editorOptions = this.cellEditorOptions.getValue(this.viewCell.internalMetadata);
|
||||
|
||||
this._register(toDisposable(() => renderedEditors.delete(this.viewCell)));
|
||||
this.registerListeners();
|
||||
|
||||
// update for init state
|
||||
this.updateForHover();
|
||||
this.updateForFocusModeChange();
|
||||
this.foldingState = viewCell.foldingState;
|
||||
this.setFoldingIndicator();
|
||||
|
@ -109,6 +119,18 @@ export class StatefulMarkdownCell extends Disposable {
|
|||
this.setFoldingIndicator();
|
||||
}
|
||||
}
|
||||
|
||||
if (e.cellIsHoveredChanged) {
|
||||
this.updateForHover();
|
||||
}
|
||||
|
||||
if (e.inputCollapsedChanged) {
|
||||
this.updateCollapsedState();
|
||||
}
|
||||
|
||||
if (e.cellLineNumberChanged) {
|
||||
this.cellEditorOptions.setLineNumbers(this.viewCell.lineNumbers);
|
||||
}
|
||||
}));
|
||||
|
||||
this._register(this.notebookEditor.notebookOptions.onDidChangeOptions(e => {
|
||||
|
@ -125,6 +147,22 @@ export class StatefulMarkdownCell extends Disposable {
|
|||
this.relayoutCell();
|
||||
}
|
||||
}));
|
||||
|
||||
this._register(this.cellEditorOptions.onDidChange(() => {
|
||||
this.updateEditorOptions(this.cellEditorOptions.getUpdatedValue(this.viewCell.internalMetadata));
|
||||
}));
|
||||
}
|
||||
|
||||
private updateCollapsedState() {
|
||||
if (this.viewCell.isInputCollapsed) {
|
||||
this.notebookEditor.hideMarkupPreviews([this.viewCell]);
|
||||
} else {
|
||||
this.notebookEditor.unhideMarkupPreviews([this.viewCell]);
|
||||
}
|
||||
}
|
||||
|
||||
private updateForHover(): void {
|
||||
this.templateData.container.classList.toggle('markdown-cell-hover', this.viewCell.cellIsHovered);
|
||||
}
|
||||
|
||||
private updateForFocusModeChange() {
|
||||
|
|
Loading…
Reference in a new issue