notebookEditor.ts 20.2 KB
Newer Older
P
Peng Lyu 已提交
1 2 3 4 5 6 7 8 9 10 11
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

import 'vs/css!./notebook';
import * as DOM from 'vs/base/browser/dom';
import { BaseEditor } from 'vs/workbench/browser/parts/editor/baseEditor';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IThemeService, registerThemingParticipant } from 'vs/platform/theme/common/themeService';
import { IStorageService } from 'vs/platform/storage/common/storage';
12
import { NotebookEditorInput, ICell, NotebookEditorModel } from 'vs/workbench/contrib/notebook/browser/notebookEditorInput';
P
Peng Lyu 已提交
13 14 15 16
import { EditorOptions } from 'vs/workbench/common/editor';
import { CancellationToken } from 'vs/base/common/cancellation';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
P
Peng Lyu 已提交
17
import { CodeEditorWidget, ICodeEditorWidgetOptions } from 'vs/editor/browser/widget/codeEditorWidget';
P
Peng Lyu 已提交
18 19 20 21 22
import * as marked from 'vs/base/common/marked/marked';
import { IModelService } from 'vs/editor/common/services/modelService';
import { URI } from 'vs/base/common/uri';
import { IModeService } from 'vs/editor/common/services/modeService';
import { deepClone } from 'vs/base/common/objects';
P
Peng Lyu 已提交
23
import { IEditorOptions } from 'vs/editor/common/config/editorOptions';
P
Peng Lyu 已提交
24
import { getExtraColor } from 'vs/workbench/contrib/welcome/walkThrough/common/walkThroughUtils';
P
Peng Lyu 已提交
25 26 27
import { textLinkForeground, textLinkActiveForeground, focusBorder, textPreformatForeground, contrastBorder, textBlockQuoteBackground, textBlockQuoteBorder, editorBackground, foreground } from 'vs/platform/theme/common/colorRegistry';
import { IListRenderer, IListVirtualDelegate } from 'vs/base/browser/ui/list/list';
import { WorkbenchList } from 'vs/platform/list/browser/listService';
28 29
import { BareFontInfo } from 'vs/editor/common/config/fontInfo';
import { getZoomLevel } from 'vs/base/browser/browser';
P
Peng Lyu 已提交
30 31 32 33
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { Action } from 'vs/base/common/actions';
import { IDisposable } from 'vs/base/common/lifecycle';
import { IEditorContributionDescription } from 'vs/editor/browser/editorExtensions';
P
Peng Lyu 已提交
34 35 36 37
import { MenuPreventer } from 'vs/workbench/contrib/codeEditor/browser/menuPreventer';
import { SuggestController } from 'vs/editor/contrib/suggest/suggestController';
import { SnippetController2 } from 'vs/editor/contrib/snippet/snippetController2';
import { TabCompletionController } from 'vs/workbench/contrib/snippets/browser/tabCompletion';
P
Peng Lyu 已提交
38
import { handleANSIOutput } from 'vs/workbench/contrib/notebook/browser/output';
39
import { ElementSizeObserver } from 'vs/editor/browser/config/elementSizeObserver';
P
Peng Lyu 已提交
40
import { ITextModel } from 'vs/editor/common/model';
P
Peng Lyu 已提交
41 42 43

const $ = DOM.$;

P
Peng Lyu 已提交
44 45

interface NotebookHandler {
46
	insertEmptyNotebookCell(cell: ICell, direction: 'above' | 'below'): void;
P
Peng Lyu 已提交
47
	deleteNotebookCell(cell: ICell): void;
48
	layoutElement(cell: ICell, height: number): void;
P
Peng Lyu 已提交
49 50
}

P
Peng Lyu 已提交
51
interface CellRenderTemplate {
52
	container: HTMLElement;
P
Peng Lyu 已提交
53
	cellContainer: HTMLElement;
P
Peng Lyu 已提交
54 55
	menuContainer?: HTMLElement;
	outputContainer?: HTMLElement;
56
	renderer?: marked.Renderer; // TODO this can be cached
57
	editor?: CodeEditorWidget;
P
Peng Lyu 已提交
58
	model?: ITextModel;
P
Peng Lyu 已提交
59 60
}

61
export class NotebookCellListDelegate implements IListVirtualDelegate<ICell> {
62
	private _lineHeight: number;
P
Peng Lyu 已提交
63 64 65
	constructor(
		@IConfigurationService private readonly configurationService: IConfigurationService
	) {
66 67 68
		const editorOptions = this.configurationService.getValue<IEditorOptions>('editor');

		this._lineHeight = BareFontInfo.createFromRawSettings(editorOptions, getZoomLevel()).lineHeight;
P
Peng Lyu 已提交
69 70
	}

71
	getHeight(element: ICell): number {
72
		if (element.cell_type === 'markdown') {
P
Peng Lyu 已提交
73 74
			return 100;
		} else {
P
Peng Lyu 已提交
75
			return Math.max(element.source.length + 1, 5) * this._lineHeight + 16;
P
Peng Lyu 已提交
76 77 78
		}
	}

79 80
	hasDynamicHeight(element: ICell): boolean {
		if (element.cell_type === 'code') {
P
Peng Lyu 已提交
81 82 83 84
			// if (!element.outputs || element.outputs.length === 0) {
			// 	return false;
			// }
			return false;
85 86
		}

P
Peng Lyu 已提交
87
		return true;
P
Peng Lyu 已提交
88 89
	}

90
	getTemplateId(element: ICell): string {
P
Peng Lyu 已提交
91

92
		if (element.cell_type === 'markdown') {
P
Peng Lyu 已提交
93 94 95 96 97 98 99
			return MarkdownCellRenderer.TEMPLATE_ID;
		} else {
			return CodeCellRenderer.TEMPLATE_ID;
		}
	}
}

100 101
class AbstractCellRenderer {
	constructor(
102
		protected handler: NotebookHandler,
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
		private contextMenuService: IContextMenuService
	) { }

	showContextMenu(element: ICell, x: number, y: number) {
		const actions: Action[] = [];
		const insertAbove = new Action(
			'workbench.notebook.code.insertCellAbove',
			'Insert Code Cell Above',
			undefined,
			true,
			async () => {
				this.handler.insertEmptyNotebookCell(element, 'above');
			}
		);

		const insertBelow = new Action(
			'workbench.notebook.code.insertCellBelow',
			'Insert Code Cell Below',
			undefined,
			true,
			async () => {
				this.handler.insertEmptyNotebookCell(element, 'below');
			}
		);

P
Peng Lyu 已提交
128 129 130 131 132 133 134 135 136 137
		const deleteCell = new Action(
			'workbench.notebook.deleteCell',
			'Delete Cell',
			undefined,
			true,
			async () => {
				this.handler.deleteNotebookCell(element);
			}
		);

138 139
		actions.push(insertAbove);
		actions.push(insertBelow);
P
Peng Lyu 已提交
140
		actions.push(deleteCell);
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156

		this.contextMenuService.showContextMenu({
			getAnchor: () => {
				return {
					x,
					y
				};
			},
			getActions: () => {
				return actions;
			},
			autoSelectFirstItem: true
		});
	}
}

157
export class MarkdownCellRenderer extends AbstractCellRenderer implements IListRenderer<ICell, CellRenderTemplate> {
P
Peng Lyu 已提交
158
	static readonly TEMPLATE_ID = 'markdown_cell';
159
	private disposables: Map<HTMLElement, IDisposable> = new Map();
P
Peng Lyu 已提交
160 161

	constructor(
162 163
		handler: NotebookHandler,
		@IContextMenuService contextMenuService: IContextMenuService
P
Peng Lyu 已提交
164
	) {
165
		super(handler, contextMenuService);
P
Peng Lyu 已提交
166
	}
P
Peng Lyu 已提交
167 168 169 170 171 172 173 174 175 176 177

	get templateId() {
		return MarkdownCellRenderer.TEMPLATE_ID;
	}

	renderTemplate(container: HTMLElement): CellRenderTemplate {
		const innerContent = document.createElement('div');
		DOM.addClasses(innerContent, 'cell', 'markdown');
		const renderer = new marked.Renderer();
		container.appendChild(innerContent);

P
Peng Lyu 已提交
178 179 180 181
		const action = document.createElement('div');
		DOM.addClasses(action, 'menu', 'codicon-settings-gear', 'codicon');
		container.appendChild(action);

P
Peng Lyu 已提交
182
		return {
183
			container: container,
P
Peng Lyu 已提交
184
			cellContainer: innerContent,
P
Peng Lyu 已提交
185
			menuContainer: action,
P
Peng Lyu 已提交
186 187 188 189
			renderer: renderer
		};
	}

190
	renderElement(element: ICell, index: number, templateData: CellRenderTemplate, height: number | undefined): void {
191
		templateData.cellContainer.innerHTML = marked(element.source.join(''), { renderer: templateData.renderer });
P
Peng Lyu 已提交
192
		let disposable = this.disposables.get(templateData.menuContainer!);
193 194 195

		if (disposable) {
			disposable.dispose();
P
Peng Lyu 已提交
196
			this.disposables.delete(templateData.menuContainer!);
197
		}
P
Peng Lyu 已提交
198

P
Peng Lyu 已提交
199 200
		let listener = DOM.addStandardDisposableListener(templateData.menuContainer!, 'mousedown', e => {
			const { top, height } = DOM.getDomNodePagePosition(templateData.menuContainer!);
P
Peng Lyu 已提交
201 202
			e.preventDefault();

203
			this.showContextMenu(element, e.posx, top + height);
P
Peng Lyu 已提交
204 205
		});

P
Peng Lyu 已提交
206
		this.disposables.set(templateData.menuContainer!, listener);
P
Peng Lyu 已提交
207 208 209 210 211 212 213
	}

	disposeTemplate(templateData: CellRenderTemplate): void {
		// throw nerendererw Error('Method not implemented.');
	}
}

214
export class CodeCellRenderer extends AbstractCellRenderer implements IListRenderer<ICell, CellRenderTemplate> {
P
Peng Lyu 已提交
215 216
	static readonly TEMPLATE_ID = 'code_cell';
	private editorOptions: IEditorOptions;
P
Peng Lyu 已提交
217
	private widgetOptions: ICodeEditorWidgetOptions;
218
	private disposables: Map<HTMLElement, IDisposable> = new Map();
P
Peng Lyu 已提交
219 220

	constructor(
221 222
		handler: NotebookHandler,
		@IContextMenuService contextMenuService: IContextMenuService,
P
Peng Lyu 已提交
223 224 225
		@IConfigurationService private readonly configurationService: IConfigurationService,
		@IInstantiationService private readonly instantiationService: IInstantiationService,
		@IModelService private readonly modelService: IModelService,
P
Peng Lyu 已提交
226 227
		@IModeService private readonly modeService: IModeService,
		@IThemeService private readonly themeService: IThemeService
P
Peng Lyu 已提交
228
	) {
229 230
		super(handler, contextMenuService);

P
Peng Lyu 已提交
231
		const language = 'python';
P
Peng Lyu 已提交
232 233 234 235 236 237 238 239 240 241 242 243
		const editorOptions = deepClone(this.configurationService.getValue<IEditorOptions>('editor', { overrideIdentifier: language }));
		this.editorOptions = {
			...editorOptions,
			scrollBeyondLastLine: false,
			scrollbar: {
				verticalScrollbarSize: 14,
				horizontal: 'auto',
				useShadows: true,
				verticalHasArrows: false,
				horizontalHasArrows: false
			},
			overviewRulerLanes: 3,
P
Peng Lyu 已提交
244
			fixedOverflowWidgets: false,
P
Peng Lyu 已提交
245 246 247 248
			lineNumbersMinChars: 1,
			minimap: { enabled: false },
		};

P
Peng Lyu 已提交
249
		this.widgetOptions = this.getSimpleCodeEditorWidgetOptions();
P
Peng Lyu 已提交
250 251 252 253 254 255 256 257 258 259
	}

	get templateId() {
		return CodeCellRenderer.TEMPLATE_ID;
	}

	renderTemplate(container: HTMLElement): CellRenderTemplate {
		const innerContent = document.createElement('div');
		DOM.addClasses(innerContent, 'cell', 'code');
		container.appendChild(innerContent);
260 261 262 263 264 265
		const editor = this.instantiationService.createInstance(CodeEditorWidget, innerContent, {
			...this.editorOptions,
			dimension: {
				width: 0,
				height: 0
			}
P
Peng Lyu 已提交
266
		}, {});
P
Peng Lyu 已提交
267 268 269
		const action = document.createElement('div');
		DOM.addClasses(action, 'menu', 'codicon-settings-gear', 'codicon');
		container.appendChild(action);
P
Peng Lyu 已提交
270

P
Peng Lyu 已提交
271 272 273 274
		const outputContainer = document.createElement('div');
		DOM.addClasses(outputContainer, 'output');
		container.appendChild(outputContainer);

P
Peng Lyu 已提交
275
		return {
276
			container: container,
277
			cellContainer: innerContent,
P
Peng Lyu 已提交
278
			menuContainer: action,
P
Peng Lyu 已提交
279
			outputContainer: outputContainer,
280
			editor
P
Peng Lyu 已提交
281 282 283
		};
	}

284
	renderElement(element: ICell, index: number, templateData: CellRenderTemplate, height: number | undefined): void {
P
Peng Lyu 已提交
285 286
		const innerContent = templateData.cellContainer;
		const width = innerContent.clientWidth;
287
		const lineNum = element.source.length;
P
Peng Lyu 已提交
288
		const totalHeight = Math.max(lineNum + 1, 5) * 21;
289
		const resource = URI.parse(`notebookcell-${index}-${Date.now()}.py`);
P
Peng Lyu 已提交
290

291
		const model = this.modelService.createModel(element.source.join(''), this.modeService.createByFilepathOrFirstLine(resource), resource, false);
292 293 294 295 296
		templateData.editor?.setModel(model);
		templateData.editor?.layout(
			{
				width: width,
				height: totalHeight
P
Peng Lyu 已提交
297
			}
298
		);
P
Peng Lyu 已提交
299

P
Peng Lyu 已提交
300 301
		let listener = DOM.addStandardDisposableListener(templateData.menuContainer!, 'mousedown', e => {
			const { top, height } = DOM.getDomNodePagePosition(templateData.menuContainer!);
P
Peng Lyu 已提交
302 303
			e.preventDefault();

304
			this.showContextMenu(element, e.posx, top + height);
P
Peng Lyu 已提交
305 306
		});

307
		this.disposables.set(templateData.cellContainer, listener);
P
Peng Lyu 已提交
308

P
Peng Lyu 已提交
309 310 311 312 313
		if (templateData.outputContainer) {
			templateData.outputContainer!.innerHTML = '';
		}

		if (element.outputs.length > 0) {
314
			const outputNodes = [];
P
Peng Lyu 已提交
315 316 317 318
			for (let i = 0; i < element.outputs.length; i++) {
				const outputNode = document.createElement('div');
				if (element.outputs[i].output_type === 'stream') {
					outputNode.innerText = element.outputs[i].text;
319 320
					outputNodes.push(outputNode);
				} else if (element.outputs[i].output_type === 'error') {
P
Peng Lyu 已提交
321
					const traceback = document.createElement('pre');
P
Peng Lyu 已提交
322 323 324 325 326 327 328
					DOM.addClasses(traceback, 'traceback');
					if (element.outputs[i].traceback) {
						for (let j = 0; j < element.outputs[i].traceback.length; j++) {
							traceback.appendChild(handleANSIOutput(element.outputs[i].traceback[j], this.themeService));
							outputNode.appendChild(traceback);
						}
					}
329 330 331 332 333 334 335 336 337 338 339 340
					outputNodes.push(outputNode);
				} else if (element.outputs[i].output_type === 'display_data') {
					const display = document.createElement('div');
					DOM.addClasses(display, 'display');
					if (element.outputs[i].data && element.outputs[i].data['image/png']) {
						const image = document.createElement('img');
						image.src = `data:image/png;base64,${element.outputs[i].data['image/png']}`;
						display.appendChild(image);
						outputNode.appendChild(display);
						shouldResize = true;
						outputNodes.push(outputNode);
					}
P
Peng Lyu 已提交
341 342 343 344
				}

				templateData.outputContainer?.appendChild(outputNode);
			}
345

P
Peng Lyu 已提交
346
			if (height !== undefined) {
347 348
				let dimensions = DOM.getClientArea(templateData.outputContainer!);
				const elementSizeObserver = new ElementSizeObserver(templateData.outputContainer!, dimensions, () => {
P
Peng Lyu 已提交
349 350 351 352
					if (templateData.outputContainer && document.body.contains(templateData.outputContainer!)) {
						let height = elementSizeObserver.getHeight();
						this.handler.layoutElement(element, totalHeight + 32 + height);
					}
353 354
				});
				elementSizeObserver.startObserving();
P
Peng Lyu 已提交
355
				this.handler.layoutElement(element, totalHeight + 32 + dimensions.height);
356 357 358 359 360 361 362 363 364

				this.disposables.set(templateData.outputContainer!, {
					dispose: () => {
						elementSizeObserver.stopObserving();
						elementSizeObserver.dispose();
					}
				});

			}
P
Peng Lyu 已提交
365 366
		}

P
Peng Lyu 已提交
367 368 369 370 371
	}

	disposeTemplate(templateData: CellRenderTemplate): void {
		// throw nerendererw Error('Method not implemented.');
	}
P
Peng Lyu 已提交
372

P
Peng Lyu 已提交
373 374

	disposeElement(element: ICell, index: number, templateData: CellRenderTemplate, height: number | undefined): void {
375
		let cellDisposable = this.disposables.get(templateData.cellContainer);
P
Peng Lyu 已提交
376

377 378 379 380 381 382 383 384 385 386 387 388
		if (cellDisposable) {
			cellDisposable.dispose();
			this.disposables.delete(templateData.cellContainer);
		}

		if (templateData.outputContainer) {
			let outputDisposable = this.disposables.get(templateData.outputContainer!);

			if (outputDisposable) {
				outputDisposable.dispose();
				this.disposables.delete(templateData.outputContainer!);
			}
P
Peng Lyu 已提交
389 390 391
		}
	}

P
Peng Lyu 已提交
392 393 394
	getSimpleCodeEditorWidgetOptions(): ICodeEditorWidgetOptions {
		return {
			isSimpleWidget: false,
P
Peng Lyu 已提交
395 396 397 398 399 400 401
			contributions: <IEditorContributionDescription[]>[
				{ id: MenuPreventer.ID, ctor: MenuPreventer },
				{ id: SuggestController.ID, ctor: SuggestController },
				// { id: ModesHoverController.ID, ctor: ModesHoverController },
				{ id: SnippetController2.ID, ctor: SnippetController2 },
				{ id: TabCompletionController.ID, ctor: TabCompletionController },
			]
P
Peng Lyu 已提交
402 403
		};
	}
P
Peng Lyu 已提交
404 405
}

P
Peng Lyu 已提交
406 407

export class NotebookEditor extends BaseEditor implements NotebookHandler {
P
Peng Lyu 已提交
408 409 410
	static readonly ID: string = 'workbench.editor.notebook';
	private rootElement!: HTMLElement;
	private body!: HTMLElement;
411
	private list: WorkbenchList<ICell> | undefined;
P
Peng Lyu 已提交
412
	private model: NotebookEditorModel | undefined;
P
Peng Lyu 已提交
413 414 415 416 417

	constructor(
		@ITelemetryService telemetryService: ITelemetryService,
		@IThemeService themeService: IThemeService,
		@IInstantiationService private readonly instantiationService: IInstantiationService,
P
Peng Lyu 已提交
418
		@IStorageService storageService: IStorageService
P
Peng Lyu 已提交
419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436
	) {
		super(NotebookEditor.ID, telemetryService, themeService, storageService);
	}
	get minimumWidth(): number { return 375; }
	get maximumWidth(): number { return Number.POSITIVE_INFINITY; }

	// these setters need to exist because this extends from BaseEditor
	set minimumWidth(value: number) { /*noop*/ }
	set maximumWidth(value: number) { /*noop*/ }


	protected createEditor(parent: HTMLElement): void {
		this.rootElement = DOM.append(parent, $('.notebook-editor'));
		this.createBody(this.rootElement);
	}

	private createBody(parent: HTMLElement): void {
		this.body = document.createElement('div'); //DOM.append(parent, $('.notebook-body'));
P
Peng Lyu 已提交
437 438 439
		DOM.addClass(this.body, 'cell-list-container');
		this.createCellList();
		DOM.append(parent, this.body);
P
Peng Lyu 已提交
440 441
	}

P
Peng Lyu 已提交
442 443
	private createCellList(): void {
		DOM.addClass(this.body, 'cell-list-container');
P
Peng Lyu 已提交
444

P
Peng Lyu 已提交
445
		const renders = [
P
Peng Lyu 已提交
446
			// this.instantiationService.createInstance(OutputCellRenderer, this),
P
Peng Lyu 已提交
447 448
			this.instantiationService.createInstance(MarkdownCellRenderer, this),
			this.instantiationService.createInstance(CodeCellRenderer, this)
P
Peng Lyu 已提交
449 450
		];

451
		this.list = this.instantiationService.createInstance<typeof WorkbenchList, WorkbenchList<ICell>>(
P
Peng Lyu 已提交
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473
			WorkbenchList,
			'NotebookCellList',
			this.body,
			this.instantiationService.createInstance(NotebookCellListDelegate),
			renders,
			{
				setRowLineHeight: false,
				supportDynamicHeights: true,
				horizontalScrolling: false,
				keyboardSupport: false,
				mouseSupport: false,
				multipleSelectionSupport: false,
				overrideStyles: {
					listBackground: editorBackground,
					listActiveSelectionBackground: editorBackground,
					listActiveSelectionForeground: foreground,
					listFocusAndSelectionBackground: editorBackground,
					listFocusAndSelectionForeground: foreground,
					listFocusBackground: editorBackground,
					listFocusForeground: foreground,
					listHoverForeground: foreground,
					listHoverBackground: editorBackground,
474 475
					listHoverOutline: focusBorder,
					listFocusOutline: focusBorder,
476 477 478 479
					listInactiveSelectionBackground: editorBackground,
					listInactiveSelectionForeground: foreground,
					listInactiveFocusBackground: editorBackground,
					listInactiveFocusOutline: editorBackground,
P
Peng Lyu 已提交
480 481 482 483
				}
			}
		);
	}
P
Peng Lyu 已提交
484

P
Peng Lyu 已提交
485
	setInput(input: NotebookEditorInput, options: EditorOptions | undefined, token: CancellationToken): Promise<void> {
486 487 488 489 490
		return super.setInput(input, options, token)
			.then(() => {
				return input.resolve();
			})
			.then(model => {
P
Peng Lyu 已提交
491 492 493 494
				if (this.model !== undefined && this.model.textModel === model.textModel) {
					return;
				}

P
Peng Lyu 已提交
495
				this.model = model;
P
Peng Lyu 已提交
496 497
				let cells = model.getNookbook().cells;
				this.list?.splice(0, this.list?.length, cells);
498 499
				this.list?.layout();
			});
P
Peng Lyu 已提交
500 501
	}

502 503 504 505 506
	layoutElement(cell: ICell, height: number) {
		let index = this.model!.getNookbook().cells.indexOf(cell);
		this.list?.updateDynamicHeight(index, cell, height);
	}

P
Peng Lyu 已提交
507 508 509
	insertEmptyNotebookCell(cell: ICell, direction: 'above' | 'below') {
		let newCell: ICell = {
			source: [],
P
Peng Lyu 已提交
510 511
			cell_type: 'code',
			outputs: []
P
Peng Lyu 已提交
512 513 514 515 516 517 518 519 520
		};

		let index = this.model!.getNookbook().cells.indexOf(cell);
		const insertIndex = direction === 'above' ? index : index + 1;

		this.model!.getNookbook().cells.splice(insertIndex, 0, newCell);
		this.list?.splice(insertIndex, 0, [newCell]);
	}

P
Peng Lyu 已提交
521 522 523 524 525 526 527 528
	deleteNotebookCell(cell: ICell) {
		let index = this.model!.getNookbook().cells.indexOf(cell);

		this.model!.getNookbook().cells.splice(index, 1);
		this.list?.splice(index, 1);
	}


P
Peng Lyu 已提交
529 530 531
	layout(dimension: DOM.Dimension): void {
		DOM.toggleClass(this.rootElement, 'mid-width', dimension.width < 1000 && dimension.width >= 600);
		DOM.toggleClass(this.rootElement, 'narrow-width', dimension.width < 600);
532
		DOM.size(this.body, dimension.width - 20, dimension.height);
533
		this.list?.layout(dimension.height, dimension.width - 20);
P
Peng Lyu 已提交
534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575
	}
}

const embeddedEditorBackground = 'walkThrough.embeddedEditorBackground';

registerThemingParticipant((theme, collector) => {
	const color = getExtraColor(theme, embeddedEditorBackground, { dark: 'rgba(0, 0, 0, .4)', extra_dark: 'rgba(200, 235, 255, .064)', light: '#f4f4f4', hc: null });
	if (color) {
		collector.addRule(`.monaco-workbench .part.editor > .content .notebook-editor .monaco-editor-background,
			.monaco-workbench .part.editor > .content .notebook-editor .margin-view-overlays { background: ${color}; }`);
	}
	const link = theme.getColor(textLinkForeground);
	if (link) {
		collector.addRule(`.monaco-workbench .part.editor > .content .notebook-editor a { color: ${link}; }`);
	}
	const activeLink = theme.getColor(textLinkActiveForeground);
	if (activeLink) {
		collector.addRule(`.monaco-workbench .part.editor > .content .notebook-editor a:hover,
			.monaco-workbench .part.editor > .content .notebook-editor a:active { color: ${activeLink}; }`);
	}
	const focusColor = theme.getColor(focusBorder);
	if (focusColor) {
		collector.addRule(`.monaco-workbench .part.editor > .content .notebook-editor a:focus { outline-color: ${focusColor}; }`);
	}
	const shortcut = theme.getColor(textPreformatForeground);
	if (shortcut) {
		collector.addRule(`.monaco-workbench .part.editor > .content .notebook-editor code,
			.monaco-workbench .part.editor > .content .notebook-editor .shortcut { color: ${shortcut}; }`);
	}
	const border = theme.getColor(contrastBorder);
	if (border) {
		collector.addRule(`.monaco-workbench .part.editor > .content .notebook-editor .monaco-editor { border-color: ${border}; }`);
	}
	const quoteBackground = theme.getColor(textBlockQuoteBackground);
	if (quoteBackground) {
		collector.addRule(`.monaco-workbench .part.editor > .content .notebook-editor blockquote { background: ${quoteBackground}; }`);
	}
	const quoteBorder = theme.getColor(textBlockQuoteBorder);
	if (quoteBorder) {
		collector.addRule(`.monaco-workbench .part.editor > .content .notebook-editor blockquote { border-color: ${quoteBorder}; }`);
	}
});