提交 8d8cb8b8 编写于 作者: R Rob Lourens

Maybe fix listener leak warnings from notebooks

上级 39af33aa
......@@ -26,6 +26,7 @@ import { NotebookCellTextModel } from 'vs/workbench/contrib/notebook/common/mode
import { CellKind, IProcessedOutput, IRenderOutput, NotebookCellMetadata, NotebookDocumentMetadata, INotebookKernelInfo, IEditor } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { Webview } from 'vs/workbench/contrib/webview/browser/webview';
import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookTextModel';
import { IMenu } from 'vs/platform/actions/common/actions';
export const KEYBINDING_CONTEXT_NOTEBOOK_FIND_WIDGET_FOCUSED = new RawContextKey<boolean>('notebookFindWidgetFocused', false);
......@@ -451,6 +452,7 @@ export interface BaseCellRenderTemplate {
currentRenderedCell?: ICellViewModel;
statusBarContainer: HTMLElement;
languageStatusBarItem: CellLanguageStatusBarItem;
titleMenu: IMenu;
toJSON: () => object;
}
......
......@@ -170,7 +170,8 @@ export class CellEditorOptions {
}
abstract class AbstractCellRenderer {
protected editorOptions: CellEditorOptions;
protected readonly editorOptions: CellEditorOptions;
protected readonly cellMenus: CellMenus;
constructor(
protected readonly instantiationService: IInstantiationService,
......@@ -184,6 +185,7 @@ abstract class AbstractCellRenderer {
protected readonly dndController: CellDragAndDropController
) {
this.editorOptions = new CellEditorOptions(configurationService, language);
this.cellMenus = this.instantiationService.createInstance(CellMenus);
}
dispose() {
......@@ -259,12 +261,9 @@ abstract class AbstractCellRenderer {
return { primary, secondary };
}
protected setupCellToolbarActions(scopedContextKeyService: IContextKeyService, templateData: BaseCellRenderTemplate, disposables: DisposableStore): void {
const cellMenu = this.instantiationService.createInstance(CellMenus);
const menu = disposables.add(cellMenu.getCellTitleMenu(scopedContextKeyService));
protected setupCellToolbarActions(templateData: BaseCellRenderTemplate, disposables: DisposableStore): void {
const updateActions = () => {
const actions = this.getCellToolbarActions(menu);
const actions = this.getCellToolbarActions(templateData.titleMenu);
const hadFocus = DOM.isAncestor(document.activeElement, templateData.toolbar.getContainer());
templateData.toolbar.setActions(actions.primary, actions.secondary);
......@@ -288,7 +287,7 @@ abstract class AbstractCellRenderer {
};
updateActions();
disposables.add(menu.onDidChange(() => {
disposables.add(templateData.titleMenu.onDidChange(() => {
if (this.notebookEditor.isDisposed) {
return;
}
......@@ -357,6 +356,7 @@ export class MarkdownCellRenderer extends AbstractCellRenderer implements IListR
DOM.append(bottomCellContainer, $('.separator'));
const statusBar = this.instantiationService.createInstance(CellEditorStatusBar, editorPart);
const titleMenu = disposables.add(this.cellMenus.getCellTitleMenu(contextKeyService));
const templateData: MarkdownCellRenderTemplate = {
contextKeyService,
......@@ -373,6 +373,7 @@ export class MarkdownCellRenderer extends AbstractCellRenderer implements IListR
bottomCellContainer,
statusBarContainer: statusBar.statusBarContainer,
languageStatusBarItem: statusBar.languageStatusBarItem,
titleMenu,
toJSON: () => { return {}; }
};
this.dndController.registerDragHandle(templateData, () => this.getDragImage(templateData));
......@@ -427,7 +428,7 @@ export class MarkdownCellRenderer extends AbstractCellRenderer implements IListR
elementDisposables.add(new CellContextKeyManager(templateData.contextKeyService, this.notebookEditor.viewModel?.notebookDocument!, element));
// render toolbar first
this.setupCellToolbarActions(templateData.contextKeyService, templateData, elementDisposables);
this.setupCellToolbarActions(templateData, elementDisposables);
const toolbarContext = <INotebookCellActionContext>{
cell: element,
......@@ -917,6 +918,8 @@ export class CodeCellRenderer extends AbstractCellRenderer implements IListRende
const focusIndicatorBottom = DOM.append(container, $('.cell-focus-indicator.cell-focus-indicator-bottom'));
const titleMenu = disposables.add(this.cellMenus.getCellTitleMenu(contextKeyService));
const templateData: CodeCellRenderTemplate = {
contextKeyService,
container,
......@@ -941,6 +944,7 @@ export class CodeCellRenderer extends AbstractCellRenderer implements IListRende
elementDisposables: new DisposableStore(),
bottomCellContainer,
timer,
titleMenu,
toJSON: () => { return {}; }
};
......@@ -1091,7 +1095,7 @@ export class CodeCellRenderer extends AbstractCellRenderer implements IListRende
this.updateForOutputs(element, templateData);
elementDisposables.add(element.onDidChangeOutputs(_e => this.updateForOutputs(element, templateData)));
this.setupCellToolbarActions(templateData.contextKeyService, templateData, elementDisposables);
this.setupCellToolbarActions(templateData, elementDisposables);
const toolbarContext = <INotebookCellActionContext>{
cell: element,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册