提交 7de343c2 编写于 作者: R rebornix

Move notebookActions to separate module.

上级 1adc63c0
......@@ -3,29 +3,20 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { IEditorOptions, ITextEditorOptions } from 'vs/platform/editor/common/editor';
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle';
import { Registry } from 'vs/platform/registry/common/platform';
import { EditorDescriptor, Extensions as EditorExtensions, IEditorRegistry } from 'vs/workbench/browser/editor';
import { NotebookEditor, NOTEBOOK_EDITOR_FOCUSED } from 'vs/workbench/contrib/notebook/browser/notebookEditor';
import { NotebookEditorInput } from 'vs/workbench/contrib/notebook/browser/notebookEditorInput';
import { IEditorService, IOpenEditorOverride } from 'vs/workbench/services/editor/common/editorService';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { Extensions as WorkbenchExtensions, IWorkbenchContribution, IWorkbenchContributionsRegistry } from 'vs/workbench/common/contributions';
import { IEditorInput } from 'vs/workbench/common/editor';
import { IEditorOptions, ITextEditorOptions } from 'vs/platform/editor/common/editor';
import { IEditorGroup } from 'vs/workbench/services/editor/common/editorGroupsService';
import { LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle';
import { NotebookEditor } from 'vs/workbench/contrib/notebook/browser/notebookEditor';
import { NotebookEditorInput } from 'vs/workbench/contrib/notebook/browser/notebookEditorInput';
import { INotebookService, NotebookService } from 'vs/workbench/contrib/notebook/browser/notebookService';
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
import { IWorkbenchActionRegistry, Extensions as WorkbenchActionExtensions } from 'vs/workbench/common/actions';
import { IActiveCodeEditor, isDiffEditor, isCodeEditor } from 'vs/editor/browser/editorBrowser';
import { Action } from 'vs/base/common/actions';
import { SyncActionDescriptor, MenuRegistry, MenuId } from 'vs/platform/actions/common/actions';
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
import { InputFocusedContextKey, InputFocusedContext } from 'vs/platform/contextkey/common/contextkeys';
import { KeyCode } from 'vs/base/common/keyCodes';
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
import { NotebookHandler } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { IEditorGroup } from 'vs/workbench/services/editor/common/editorGroupsService';
import { IEditorService, IOpenEditorOverride } from 'vs/workbench/services/editor/common/editorService';
// Output renderers registration
......@@ -33,6 +24,9 @@ import 'vs/workbench/contrib/notebook/browser/output/transforms/streamTransform'
import 'vs/workbench/contrib/notebook/browser/output/transforms/errorTransform';
import 'vs/workbench/contrib/notebook/browser/output/transforms/richTransform';
// Actions
import 'vs/workbench/contrib/notebook/browser/notebookActions';
Registry.as<IEditorRegistry>(EditorExtensions.Editors).registerEditor(
EditorDescriptor.create(
......@@ -45,140 +39,6 @@ Registry.as<IEditorRegistry>(EditorExtensions.Editors).registerEditor(
]
);
export class ExecuteNotebookCellAction extends Action {
static readonly ID = 'workbench.action.executeNotebookCell';
static readonly LABEL = 'Execute Notebook Cell';
constructor(
id: string,
label: string,
@IEditorService private readonly editorService: IEditorService,
@INotebookService private readonly notebookService: INotebookService
) {
super(id, label);
}
async run(): Promise<void> {
let resource = this.editorService.activeEditor?.getResource();
if (resource) {
let notebookProviders = this.notebookService.getContributedNotebook(resource!);
if (notebookProviders.length > 0) {
let viewType = notebookProviders[0].id;
this.notebookService.executeNotebookActiveCell(viewType, resource);
}
}
}
}
export class ExecuteNotebookAction extends Action {
static readonly ID = 'workbench.action.executeNotebook';
static readonly LABEL = 'Execute Notebook';
constructor(
id: string,
label: string,
@IEditorService private readonly editorService: IEditorService,
@INotebookService private readonly notebookService: INotebookService
) {
super(id, label);
}
async run(): Promise<void> {
let resource = this.editorService.activeEditor?.getResource();
if (resource) {
let notebookProviders = this.notebookService.getContributedNotebook(resource!);
if (notebookProviders.length > 0) {
let viewType = notebookProviders[0].id;
this.notebookService.executeNotebook(viewType, resource);
}
}
}
}
export class QuitNotebookEditAction extends Action {
static readonly ID = 'workbench.action.quitNotebookEdit';
static readonly LABEL = 'Quit Notebook Cell Editing';
constructor(
id: string,
label: string,
@IEditorService private readonly editorService: IEditorService,
@INotebookService private readonly notebookService: INotebookService
) {
super(id, label);
}
async run(): Promise<void> {
let resource = this.editorService.activeEditor?.getResource();
let editorControl = this.editorService.activeControl;
if (resource && editorControl) {
let notebookProviders = this.notebookService.getContributedNotebook(resource!);
if (notebookProviders.length > 0) {
let editorViewType = ((editorControl! as any) as NotebookHandler).viewType;
let viewType = notebookProviders[0].id;
if (viewType === editorViewType) {
let activeCell = ((editorControl! as any) as NotebookHandler).getActiveCell();
if (activeCell) {
((editorControl! as any) as NotebookHandler).focusNotebookCell(activeCell, false);
}
}
}
}
}
}
export class EditNotebookCellAction extends Action {
static readonly ID = 'workbench.action.editNotebookActiveCell';
static readonly LABEL = 'Edit Notebook Active Cell';
constructor(
id: string,
label: string,
@IEditorService private readonly editorService: IEditorService,
@INotebookService private readonly notebookService: INotebookService
) {
super(id, label);
}
async run(): Promise<void> {
let resource = this.editorService.activeEditor?.getResource();
let editorControl = this.editorService.activeControl;
if (resource && editorControl) {
let notebookProviders = this.notebookService.getContributedNotebook(resource!);
if (notebookProviders.length > 0) {
let editorViewType = ((editorControl! as any) as NotebookHandler).viewType;
let viewType = notebookProviders[0].id;
if (viewType === editorViewType) {
let activeCell = ((editorControl! as any) as NotebookHandler).getActiveCell();
if (activeCell) {
((editorControl! as any) as NotebookHandler).editNotebookCell(undefined, activeCell);
}
}
}
}
}
}
export class NotebookContribution implements IWorkbenchContribution {
private _resourceMapping: Map<string, NotebookEditorInput> = new Map<string, NotebookEditorInput>();
......@@ -190,8 +50,6 @@ export class NotebookContribution implements IWorkbenchContribution {
) {
this.editorService.overrideOpenEditor((editor, options, group) => this.onEditorOpening(editor, options, group));
this.registerCommands();
this.editorService.onDidActiveEditorChange(() => {
if (this.editorService.activeEditor && this.editorService.activeEditor! instanceof NotebookEditorInput) {
let editorInput = this.editorService.activeEditor! as NotebookEditorInput;
......@@ -229,93 +87,9 @@ export class NotebookContribution implements IWorkbenchContribution {
return { override: this.editorService.openEditor(input, options, group) };
}
private registerCommands() {
const workbenchActionsRegistry = Registry.as<IWorkbenchActionRegistry>(WorkbenchActionExtensions.WorkbenchActions);
workbenchActionsRegistry.registerWorkbenchAction(SyncActionDescriptor.create(ExecuteNotebookAction, ExecuteNotebookAction.ID, ExecuteNotebookAction.LABEL), 'Execute Notebook', 'Notebook');
MenuRegistry.appendMenuItem(MenuId.EditorTitle, {
command: {
id: 'workbench.action.executeNotebook',
title: 'Execute Notebook (Run all cells)',
icon: { id: 'codicon/debug-start' }
},
order: -1,
group: 'navigation',
when: NOTEBOOK_EDITOR_FOCUSED
});
workbenchActionsRegistry.registerWorkbenchAction(SyncActionDescriptor.create(ExecuteNotebookCellAction, ExecuteNotebookCellAction.ID, ExecuteNotebookCellAction.LABEL), 'Execute Notebook Cell', 'Notebook');
MenuRegistry.appendMenuItem(MenuId.EditorTitle, {
command: {
id: 'workbench.action.executeNotebookCell',
title: 'Execute Notebook Cell',
icon: { id: 'codicon/debug-continue' }
},
order: -1,
group: 'navigation',
when: NOTEBOOK_EDITOR_FOCUSED
});
}
}
const workbenchContributionsRegistry = Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench);
workbenchContributionsRegistry.registerWorkbenchContribution(NotebookContribution, LifecyclePhase.Starting);
registerSingleton(INotebookService, NotebookService);
const registry = Registry.as<IWorkbenchActionRegistry>(WorkbenchActionExtensions.WorkbenchActions);
registry.registerWorkbenchAction(
SyncActionDescriptor.create(
EditNotebookCellAction,
EditNotebookCellAction.ID,
EditNotebookCellAction.LABEL,
{
primary: KeyCode.Enter,
},
ContextKeyExpr.and(NOTEBOOK_EDITOR_FOCUSED, ContextKeyExpr.not(InputFocusedContextKey)),
),
'Edit Notebook Active Cell;',
'Notebook'
);
registry.registerWorkbenchAction(
SyncActionDescriptor.create(
QuitNotebookEditAction,
QuitNotebookEditAction.ID,
QuitNotebookEditAction.LABEL,
{
primary: KeyCode.Escape,
},
ContextKeyExpr.and(NOTEBOOK_EDITOR_FOCUSED, InputFocusedContext),
// TODO: It's set to `EditorContrib - 5` to ensure all editor escape commands to work
// but, how about core?
KeybindingWeight.EditorContrib - 5
),
'Edit Notebook Active Cell;',
'Notebook'
);
export function getActiveEditor(editorService: IEditorService): IActiveCodeEditor | null {
let activeTextEditorWidget = editorService.activeTextEditorWidget;
if (isDiffEditor(activeTextEditorWidget)) {
if (activeTextEditorWidget.getOriginalEditor().hasTextFocus()) {
activeTextEditorWidget = activeTextEditorWidget.getOriginalEditor();
} else {
activeTextEditorWidget = activeTextEditorWidget.getModifiedEditor();
}
}
if (!isCodeEditor(activeTextEditorWidget) || !activeTextEditorWidget.hasModel()) {
return null;
}
return activeTextEditorWidget;
}
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { Action } from 'vs/base/common/actions';
import { KeyCode } from 'vs/base/common/keyCodes';
import { SyncActionDescriptor, MenuRegistry, MenuId } from 'vs/platform/actions/common/actions';
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
import { InputFocusedContext, InputFocusedContextKey } from 'vs/platform/contextkey/common/contextkeys';
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
import { Registry } from 'vs/platform/registry/common/platform';
import { Extensions as WorkbenchActionExtensions, IWorkbenchActionRegistry } from 'vs/workbench/common/actions';
import { INotebookService } from 'vs/workbench/contrib/notebook/browser/notebookService';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { NOTEBOOK_EDITOR_FOCUSED, NotebookEditor } from 'vs/workbench/contrib/notebook/browser/notebookEditor';
export class ExecuteNotebookCellAction extends Action {
static readonly ID = 'workbench.action.executeNotebookCell';
static readonly LABEL = 'Execute Notebook Cell';
constructor(
id: string,
label: string,
@IEditorService private readonly editorService: IEditorService,
@INotebookService private readonly notebookService: INotebookService
) {
super(id, label);
}
async run(): Promise<void> {
let resource = this.editorService.activeEditor?.getResource();
if (resource) {
let notebookProviders = this.notebookService.getContributedNotebook(resource!);
if (notebookProviders.length > 0) {
let viewType = notebookProviders[0].id;
this.notebookService.executeNotebookActiveCell(viewType, resource);
}
}
}
}
export class ExecuteNotebookAction extends Action {
static readonly ID = 'workbench.action.executeNotebook';
static readonly LABEL = 'Execute Notebook';
constructor(
id: string,
label: string,
@IEditorService private readonly editorService: IEditorService,
@INotebookService private readonly notebookService: INotebookService
) {
super(id, label);
}
async run(): Promise<void> {
let resource = this.editorService.activeEditor?.getResource();
if (resource) {
let notebookProviders = this.notebookService.getContributedNotebook(resource!);
if (notebookProviders.length > 0) {
let viewType = notebookProviders[0].id;
this.notebookService.executeNotebook(viewType, resource);
}
}
}
}
export class QuitNotebookEditAction extends Action {
static readonly ID = 'workbench.action.quitNotebookEdit';
static readonly LABEL = 'Quit Notebook Cell Editing';
constructor(
id: string,
label: string,
@IEditorService private readonly editorService: IEditorService,
@INotebookService private readonly notebookService: INotebookService
) {
super(id, label);
}
async run(): Promise<void> {
let resource = this.editorService.activeEditor?.getResource();
let editorControl = this.editorService.activeControl;
if (resource && editorControl) {
let notebookProviders = this.notebookService.getContributedNotebook(resource!);
if (notebookProviders.length > 0) {
let editorViewType = (editorControl! as NotebookEditor).viewType;
let viewType = notebookProviders[0].id;
if (viewType === editorViewType) {
let activeCell = (editorControl! as NotebookEditor).getActiveCell();
if (activeCell) {
(editorControl! as NotebookEditor).focusNotebookCell(activeCell, false);
}
}
}
}
}
}
export class EditNotebookCellAction extends Action {
static readonly ID = 'workbench.action.editNotebookActiveCell';
static readonly LABEL = 'Edit Notebook Active Cell';
constructor(
id: string,
label: string,
@IEditorService private readonly editorService: IEditorService,
@INotebookService private readonly notebookService: INotebookService
) {
super(id, label);
}
async run(): Promise<void> {
let resource = this.editorService.activeEditor?.getResource();
let editorControl = this.editorService.activeControl;
if (resource && editorControl) {
let notebookProviders = this.notebookService.getContributedNotebook(resource!);
if (notebookProviders.length > 0) {
let editorViewType = (editorControl! as NotebookEditor).viewType;
let viewType = notebookProviders[0].id;
if (viewType === editorViewType) {
let activeCell = (editorControl! as NotebookEditor).getActiveCell();
if (activeCell) {
(editorControl! as NotebookEditor).editNotebookCell(undefined, activeCell);
}
}
}
}
}
}
const registry = Registry.as<IWorkbenchActionRegistry>(WorkbenchActionExtensions.WorkbenchActions);
registry.registerWorkbenchAction(
SyncActionDescriptor.create(
EditNotebookCellAction,
EditNotebookCellAction.ID,
EditNotebookCellAction.LABEL,
{
primary: KeyCode.Enter,
},
ContextKeyExpr.and(NOTEBOOK_EDITOR_FOCUSED, ContextKeyExpr.not(InputFocusedContextKey)),
),
'Edit Notebook Active Cell;',
'Notebook'
);
registry.registerWorkbenchAction(
SyncActionDescriptor.create(
QuitNotebookEditAction,
QuitNotebookEditAction.ID,
QuitNotebookEditAction.LABEL,
{
primary: KeyCode.Escape,
},
ContextKeyExpr.and(NOTEBOOK_EDITOR_FOCUSED, InputFocusedContext),
// TODO: It's set to `EditorContrib - 5` to ensure all editor escape commands to work
// but, how about core?
KeybindingWeight.EditorContrib - 5
),
'Edit Notebook Active Cell;',
'Notebook'
);
registry.registerWorkbenchAction(
SyncActionDescriptor.create(
ExecuteNotebookAction,
ExecuteNotebookAction.ID,
ExecuteNotebookAction.LABEL
),
'Execute Notebook',
'Notebook'
);
registry.registerWorkbenchAction(
SyncActionDescriptor.create(
ExecuteNotebookCellAction,
ExecuteNotebookCellAction.ID,
ExecuteNotebookCellAction.LABEL
),
'Execute Notebook Cell',
'Notebook'
);
MenuRegistry.appendMenuItem(MenuId.EditorTitle, {
command: {
id: 'workbench.action.executeNotebook',
title: 'Execute Notebook (Run all cells)',
icon: { id: 'codicon/debug-start' }
},
order: -1,
group: 'navigation',
when: NOTEBOOK_EDITOR_FOCUSED
});
MenuRegistry.appendMenuItem(MenuId.EditorTitle, {
command: {
id: 'workbench.action.executeNotebookCell',
title: 'Execute Notebook Cell',
icon: { id: 'codicon/debug-continue' }
},
order: -1,
group: 'navigation',
when: NOTEBOOK_EDITOR_FOCUSED
});
......@@ -3,7 +3,6 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as DOM from 'vs/base/browser/dom';
import { IMouseWheelEvent } from 'vs/base/browser/mouseEvent';
import { BareFontInfo } from 'vs/editor/common/config/fontInfo';
......@@ -11,18 +10,18 @@ import { CodeEditorWidget } from 'vs/editor/browser/widget/codeEditorWidget';
import { CellViewModel } from 'vs/workbench/contrib/notebook/browser/renderers/cellViewModel';
import { OutputRenderer } from 'vs/workbench/contrib/notebook/browser/output/outputRenderer';
export interface NotebookHandler {
export interface INotebookEditor {
viewType: string | undefined;
insertEmptyNotebookCell(listIndex: number | undefined, cell: CellViewModel, type: 'markdown' | 'code', direction: 'above' | 'below'): Promise<void>;
deleteNotebookCell(listIndex: number | undefined, cell: CellViewModel): void;
editNotebookCell(listIndex: number | undefined, cell: CellViewModel): void;
saveNotebookCell(listIndex: number | undefined, cell: CellViewModel): void;
insertEmptyNotebookCell(index: number | undefined, cell: CellViewModel, type: 'markdown' | 'code', direction: 'above' | 'below'): Promise<void>;
deleteNotebookCell(index: number | undefined, cell: CellViewModel): void;
editNotebookCell(index: number | undefined, cell: CellViewModel): void;
saveNotebookCell(index: number | undefined, cell: CellViewModel): void;
focusNotebookCell(cell: CellViewModel, focusEditor: boolean): void;
getActiveCell(): CellViewModel | undefined;
layoutElement(cell: CellViewModel, height: number): void;
layoutNotebookCell(cell: CellViewModel, height: number): void;
createContentWidget(cell: CellViewModel, index: number, shadowContent: string, offset: number): void;
disposeViewCell(cell: CellViewModel): void;
triggerWheel(event: IMouseWheelEvent): void;
triggerScroll(event: IMouseWheelEvent): void;
getFontInfo(): BareFontInfo | undefined;
getListDimension(): DOM.Dimension | null;
getOutputRenderer(): OutputRenderer;
......
......@@ -34,7 +34,7 @@ import { IEnvironmentService } from 'vs/platform/environment/common/environment'
import { IContextKeyService, IContextKey, RawContextKey } from 'vs/platform/contextkey/common/contextkey';
import { IOpenerService } from 'vs/platform/opener/common/opener';
import { INotebook, CELL_MARGIN } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { NotebookHandler } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { INotebookEditor } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { OutputRenderer } from 'vs/workbench/contrib/notebook/browser/output/outputRenderer';
const $ = DOM.$;
......@@ -46,7 +46,7 @@ interface INotebookEditorViewState {
editingCells: { [key: number]: boolean };
}
export class NotebookEditor extends BaseEditor implements NotebookHandler {
export class NotebookEditor extends BaseEditor implements INotebookEditor {
static readonly ID: string = 'workbench.editor.notebook';
private rootElement!: HTMLElement;
private body!: HTMLElement;
......@@ -185,7 +185,7 @@ export class NotebookEditor extends BaseEditor implements NotebookHandler {
return this.dimension;
}
triggerWheel(event: IMouseWheelEvent) {
triggerScroll(event: IMouseWheelEvent) {
this.list?.triggerScrollFromMouseWheelEvent(event);
}
......@@ -339,7 +339,7 @@ export class NotebookEditor extends BaseEditor implements NotebookHandler {
});
}
layoutElement(cell: CellViewModel, height: number) {
layoutNotebookCell(cell: CellViewModel, height: number) {
let relayout = (cell: CellViewModel, height: number) => {
let index = this.model!.getNotebook().cells.indexOf(cell.cell);
if (index >= 0) {
......
......@@ -47,6 +47,7 @@ export class NotebookEditorModel extends EditorModel {
return this._notebook;
}
// TODO, remove file based notebook from core
let content = this.textModel.getValue();
this._notebook = JSON.parse(content);
return this._notebook!;
......
......@@ -5,9 +5,9 @@
import { IOutputTransformContribution } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { BrandedService, IConstructorSignature1 } from 'vs/platform/instantiation/common/instantiation';
import { NotebookHandler } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { INotebookEditor } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
export type IOutputTransformCtor = IConstructorSignature1<NotebookHandler, IOutputTransformContribution>;
export type IOutputTransformCtor = IConstructorSignature1<INotebookEditor, IOutputTransformContribution>;
export interface IOutputTransformDescription {
id: string;
......@@ -21,7 +21,7 @@ export namespace NotebookRegistry {
}
}
export function registerOutputTransform<Services extends BrandedService[]>(id: string, types: string[], ctor: { new(handler: NotebookHandler, ...services: Services): IOutputTransformContribution }): void {
export function registerOutputTransform<Services extends BrandedService[]>(id: string, types: string[], ctor: { new(handler: INotebookEditor, ...services: Services): IOutputTransformContribution }): void {
NotebookRegistryImpl.INSTANCE.registerOutputTransform(id, types, ctor);
}
......@@ -35,7 +35,7 @@ class NotebookRegistryImpl {
this.outputTransforms = [];
}
public registerOutputTransform<Services extends BrandedService[]>(id: string, types: string[], ctor: { new(handler: NotebookHandler, ...services: Services): IOutputTransformContribution }): void {
public registerOutputTransform<Services extends BrandedService[]>(id: string, types: string[], ctor: { new(handler: INotebookEditor, ...services: Services): IOutputTransformContribution }): void {
this.outputTransforms.push({ id: id, types: types, ctor: ctor as IOutputTransformCtor });
}
......
......@@ -7,14 +7,14 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
import { IOutputTransformContribution, IOutput, IRenderOutput } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { NotebookRegistry } from 'vs/workbench/contrib/notebook/browser/notebookRegistry';
import { onUnexpectedError } from 'vs/base/common/errors';
import { NotebookHandler } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { INotebookEditor } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
export class OutputRenderer {
protected readonly _contributions: { [key: string]: IOutputTransformContribution; };
protected readonly _mimeTypeMapping: { [key: string]: IOutputTransformContribution; };
constructor(
private readonly notebookHandler: NotebookHandler,
private readonly notebookHandler: INotebookEditor,
private readonly instantiationService: IInstantiationService
) {
this._contributions = {};
......
......@@ -9,11 +9,11 @@ import * as DOM from 'vs/base/browser/dom';
import { RGBA, Color } from 'vs/base/common/color';
import { ansiColorIdentifiers } from 'vs/workbench/contrib/terminal/common/terminalColorRegistry';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { NotebookHandler } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { INotebookEditor } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
class ErrorTransform implements IOutputTransformContribution {
constructor(
public handler: NotebookHandler,
public handler: INotebookEditor,
@IThemeService private readonly themeService: IThemeService
) {
}
......
......@@ -6,7 +6,7 @@
import { IOutputTransformContribution, IRenderOutput } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { registerOutputTransform } from 'vs/workbench/contrib/notebook/browser/notebookRegistry';
import * as DOM from 'vs/base/browser/dom';
import { NotebookHandler } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { INotebookEditor } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { isArray } from 'vs/base/common/types';
import * as marked from 'vs/base/common/marked/marked';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
......@@ -20,7 +20,7 @@ class RichRenderer implements IOutputTransformContribution {
private _mdRenderer: marked.Renderer = new marked.Renderer({ gfm: true });;
constructor(
public handler: NotebookHandler,
public handler: INotebookEditor,
@IInstantiationService private readonly instantiationService: IInstantiationService,
@IModelService private readonly modelService: IModelService,
@IModeService private readonly modeService: IModeService
......
......@@ -5,11 +5,11 @@
import { IOutputTransformContribution, IRenderOutput } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { registerOutputTransform } from 'vs/workbench/contrib/notebook/browser/notebookRegistry';
import { NotebookHandler } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { INotebookEditor } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
class StreamRenderer implements IOutputTransformContribution {
constructor(
handler: NotebookHandler
handler: INotebookEditor
) {
}
......
......@@ -22,7 +22,7 @@ import { CellViewModel } from './cellViewModel';
import { CodeCell } from 'vs/workbench/contrib/notebook/browser/renderers/codeCell';
import { IModelService } from 'vs/editor/common/services/modelService';
import { IModeService } from 'vs/editor/common/services/modeService';
import { CellRenderTemplate, NotebookHandler } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { CellRenderTemplate, INotebookEditor } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
export class NotebookCellListDelegate implements IListVirtualDelegate<CellViewModel> {
private _lineHeight: number;
......@@ -58,7 +58,7 @@ class AbstractCellRenderer {
protected editorOptions: IEditorOptions;
constructor(
protected handler: NotebookHandler,
protected handler: INotebookEditor,
private contextMenuService: IContextMenuService,
private configurationService: IConfigurationService,
language: string
......@@ -186,7 +186,7 @@ export class MarkdownCellRenderer extends AbstractCellRenderer implements IListR
private disposables: Map<CellViewModel, DisposableStore> = new Map();
constructor(
handler: NotebookHandler,
handler: INotebookEditor,
@IInstantiationService private readonly instantiationService: IInstantiationService,
@IConfigurationService configurationService: IConfigurationService,
@IContextMenuService contextMenuService: IContextMenuService
......@@ -268,7 +268,7 @@ export class CodeCellRenderer extends AbstractCellRenderer implements IListRende
private disposables: Map<CellViewModel, DisposableStore> = new Map();
constructor(
protected handler: NotebookHandler,
protected handler: INotebookEditor,
@IContextMenuService contextMenuService: IContextMenuService,
@IConfigurationService configurationService: IConfigurationService,
@IInstantiationService private readonly instantiationService: IInstantiationService,
......
......@@ -11,11 +11,11 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
import { IModelService } from 'vs/editor/common/services/modelService';
import { IModeService } from 'vs/editor/common/services/modeService';
import { CELL_MARGIN } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { CellRenderTemplate, NotebookHandler } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { CellRenderTemplate, INotebookEditor } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
export class CodeCell extends Disposable {
constructor(
handler: NotebookHandler,
handler: INotebookEditor,
viewCell: CellViewModel,
templateData: CellRenderTemplate,
themeService: IThemeService,
......@@ -88,9 +88,9 @@ export class CodeCell extends Disposable {
if (viewCell.outputs.length) {
let outputHeight = templateData.outputContainer!.clientHeight;
handler.layoutElement(viewCell, e.contentHeight + 32 + outputHeight);
handler.layoutNotebookCell(viewCell, e.contentHeight + 32 + outputHeight);
} else {
handler.layoutElement(viewCell, e.contentHeight + 16);
handler.layoutNotebookCell(viewCell, e.contentHeight + 16);
}
}
}
......@@ -124,7 +124,7 @@ export class CodeCell extends Disposable {
let height = elementSizeObserver.getHeight();
if (clientHeight !== height) {
viewCell.dynamicHeight = totalHeight + 32 + height;
handler.layoutElement(viewCell, totalHeight + 32 + height);
handler.layoutNotebookCell(viewCell, totalHeight + 32 + height);
}
elementSizeObserver.dispose();
......@@ -132,7 +132,7 @@ export class CodeCell extends Disposable {
});
elementSizeObserver.startObserving();
viewCell.dynamicHeight = totalHeight + 32 + clientHeight;
handler.layoutElement(viewCell, totalHeight + 32 + clientHeight);
handler.layoutNotebookCell(viewCell, totalHeight + 32 + clientHeight);
this._register(elementSizeObserver);
}
......@@ -166,7 +166,7 @@ export class CodeCell extends Disposable {
let height = elementSizeObserver.getHeight();
if (clientHeight !== height) {
viewCell.dynamicHeight = totalHeight + 32 + height;
handler.layoutElement(viewCell, totalHeight + 32 + height);
handler.layoutNotebookCell(viewCell, totalHeight + 32 + height);
}
elementSizeObserver.dispose();
......
......@@ -14,7 +14,7 @@ import { URI } from 'vs/base/common/uri';
import { WebviewResourceScheme } from 'vs/workbench/contrib/webview/common/resourceLoader';
import * as path from 'vs/base/common/path';
import { CELL_MARGIN } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { NotebookHandler } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { INotebookEditor } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
export interface IDimentionMessage {
type: 'dimension';
......@@ -75,7 +75,7 @@ export class BackLayerWebView extends Disposable {
public outputMapping: Map<string, boolean> = new Map();
public preloadsCache: Map<string, boolean> = new Map();
constructor(public webviewService: IWebviewService, public notebookService: INotebookService, public notebookHandler: NotebookHandler, public environmentSerice: IEnvironmentService) {
constructor(public webviewService: IWebviewService, public notebookService: INotebookService, public notebookHandler: INotebookEditor, public environmentSerice: IEnvironmentService) {
super();
this.element = document.createElement('div');
......@@ -242,7 +242,7 @@ export class BackLayerWebView extends Disposable {
this.webview.mountTo(this.element);
this._register(this.webview.onDidWheel(e => {
this.notebookHandler.triggerWheel(e);
this.notebookHandler.triggerScroll(e);
}));
this._register(this.webview.onMessage((data: IMessage) => {
......@@ -255,7 +255,7 @@ export class BackLayerWebView extends Disposable {
const lineHeight = this.notebookHandler.getFontInfo()?.lineHeight ?? 18;
const totalHeight = lineNum * lineHeight;
cell.dynamicHeight = totalHeight + 32 /* code cell padding */ + outputHeight;
this.notebookHandler.layoutElement(cell, totalHeight + 32 /* code cell padding */ + outputHeight);
this.notebookHandler.layoutNotebookCell(cell, totalHeight + 32 /* code cell padding */ + outputHeight);
}
} else if (data.type === 'scroll-ack') {
// const date = new Date();
......
......@@ -10,7 +10,7 @@ import { IEditorOptions } from 'vs/editor/common/config/editorOptions';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { getResizesObserver } from 'vs/workbench/contrib/notebook/browser/renderers/sizeObserver';
import { CELL_MARGIN } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { NotebookHandler, CellRenderTemplate } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { INotebookEditor, CellRenderTemplate } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
export class StatefullMarkdownCell extends Disposable {
private editor: CodeEditorWidget | null = null;
......@@ -20,7 +20,7 @@ export class StatefullMarkdownCell extends Disposable {
private localDisposables: DisposableStore;
constructor(
handler: NotebookHandler,
handler: INotebookEditor,
viewCell: CellViewModel,
templateData: CellRenderTemplate,
editorOptions: IEditorOptions,
......@@ -84,7 +84,7 @@ export class StatefullMarkdownCell extends Disposable {
this.cellContainer.appendChild(renderedHTML);
}
handler.layoutElement(viewCell, realContentHeight + 32 + clientHeight);
handler.layoutNotebookCell(viewCell, realContentHeight + 32 + clientHeight);
}));
this.localDisposables.add(this.editor.onDidContentSizeChange(e => {
......@@ -98,7 +98,7 @@ export class StatefullMarkdownCell extends Disposable {
}
);
const clientHeight = this.cellContainer.clientHeight;
handler.layoutElement(viewCell, e.contentHeight + 32 + clientHeight);
handler.layoutNotebookCell(viewCell, e.contentHeight + 32 + clientHeight);
}
}));
......@@ -126,20 +126,20 @@ export class StatefullMarkdownCell extends Disposable {
this.cellContainer.appendChild(renderedHTML);
this.localDisposables.add(markdownRenderer.onDidUpdateRender(() => {
const clientHeight = this.cellContainer.clientHeight;
handler.layoutElement(viewCell, clientHeight);
handler.layoutNotebookCell(viewCell, clientHeight);
}));
}
}
const clientHeight = this.cellContainer.clientHeight;
handler.layoutElement(viewCell, totalHeight + 32 + clientHeight);
handler.layoutNotebookCell(viewCell, totalHeight + 32 + clientHeight);
this.editor.focus();
} else {
if (this.editor) {
// switch from editing mode
this.editingContainer!.style.display = 'none';
const clientHeight = this.cellContainer.clientHeight;
handler.layoutElement(viewCell, clientHeight);
handler.layoutNotebookCell(viewCell, clientHeight);
} else {
// first time, readonly mode
this.editingContainer!.style.display = 'none';
......@@ -153,7 +153,7 @@ export class StatefullMarkdownCell extends Disposable {
this.localDisposables.add(markdownRenderer.onDidUpdateRender(() => {
const clientHeight = this.cellContainer.clientHeight;
handler.layoutElement(viewCell, clientHeight);
handler.layoutNotebookCell(viewCell, clientHeight);
}));
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册