notebookBrowser.ts 4.9 KB
Newer Older
R
rebornix 已提交
1 2 3 4 5 6 7 8
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

import { IMouseWheelEvent } from 'vs/base/browser/mouseEvent';
import { BareFontInfo } from 'vs/editor/common/config/fontInfo';
import { CodeEditorWidget } from 'vs/editor/browser/widget/codeEditorWidget';
R
rebornix 已提交
9 10
import { CellViewModel } from 'vs/workbench/contrib/notebook/browser/viewModel/notebookCellViewModel';
import { OutputRenderer } from 'vs/workbench/contrib/notebook/browser/view/output/outputRenderer';
R
rebornix 已提交
11
import { IOutput, CellKind, IRenderOutput } from 'vs/workbench/contrib/notebook/common/notebookCommon';
R
rebornix 已提交
12
import { RawContextKey } from 'vs/platform/contextkey/common/contextkey';
R
rebornix 已提交
13 14
import { NotebookViewModel, IModelDecorationsChangeAccessor } from 'vs/workbench/contrib/notebook/browser/viewModel/notebookViewModel';
import { FindMatch } from 'vs/editor/common/model';
R
rebornix 已提交
15 16

export const KEYBINDING_CONTEXT_NOTEBOOK_FIND_WIDGET_FOCUSED = new RawContextKey<boolean>('notebookFindWidgetFocused', false);
R
rebornix 已提交
17

R
rebornix 已提交
18 19 20 21 22 23
export interface NotebookLayoutInfo {
	width: number;
	height: number;
	fontInfo: BareFontInfo;
}

24
export interface INotebookEditor {
R
rebornix 已提交
25 26 27 28

	/**
	 * Notebook view model attached to the current editor
	 */
R
rebornix 已提交
29
	viewModel: NotebookViewModel | undefined;
R
rebornix 已提交
30 31 32 33

	/**
	 * Focus the notebook editor cell list
	 */
R
rebornix 已提交
34
	focus(): void;
R
rebornix 已提交
35 36 37 38

	/**
	 * Layout info for the notebook editor
	 */
R
rebornix 已提交
39
	getLayoutInfo(): NotebookLayoutInfo;
R
rebornix 已提交
40 41 42
	/**
	 * Fetch the output renderers for notebook outputs.
	 */
R
rebornix 已提交
43
	getOutputRenderer(): OutputRenderer;
R
rebornix 已提交
44 45 46 47

	/**
	 * Insert a new cell around `cell`
	 */
R
rebornix 已提交
48
	insertEmptyNotebookCell(cell: CellViewModel, type: CellKind, direction: 'above' | 'below'): Promise<void>;
R
rebornix 已提交
49 50 51 52

	/**
	 * Delete a cell from the notebook
	 */
R
rebornix 已提交
53
	deleteNotebookCell(cell: CellViewModel): void;
R
rebornix 已提交
54 55 56 57 58 59 60

	/**
	 * Switch the cell into editing mode.
	 *
	 * For code cell, the monaco editor will be focused.
	 * For markdown cell, it will switch from preview mode to editing mode, which focuses the monaco editor.
	 */
R
rebornix 已提交
61
	editNotebookCell(cell: CellViewModel): void;
R
rebornix 已提交
62 63 64 65

	/**
	 * Quit cell editing mode.
	 */
R
rebornix 已提交
66
	saveNotebookCell(cell: CellViewModel): void;
R
rebornix 已提交
67 68 69 70

	/**
	 * Focus the container of a cell (the monaco editor inside is not focused).
	 */
R
rebornix 已提交
71
	focusNotebookCell(cell: CellViewModel, focusEditor: boolean): void;
R
rebornix 已提交
72 73 74 75

	/**
	 * Get current active cell
	 */
R
rebornix 已提交
76
	getActiveCell(): CellViewModel | undefined;
R
rebornix 已提交
77 78 79 80

	/**
	 * Layout the cell with a new height
	 */
81
	layoutNotebookCell(cell: CellViewModel, height: number): void;
R
rebornix 已提交
82 83 84 85

	/**
	 * Render the output in webview layer
	 */
86
	createInset(cell: CellViewModel, output: IOutput, shadowContent: string, offset: number): void;
R
rebornix 已提交
87 88 89 90

	/**
	 * Remove the output from the webview layer
	 */
R
rebornix 已提交
91
	removeInset(output: IOutput): void;
R
rebornix 已提交
92 93 94 95

	/**
	 * Trigger the editor to scroll from scroll event programmatically
	 */
96
	triggerScroll(event: IMouseWheelEvent): void;
R
rebornix 已提交
97 98 99 100 101

	/**
	 * Reveal cell into viewport.
	 * If `offset` is provided, `top(cell) + offset` will be scrolled into view.
	 */
R
rebornix 已提交
102
	revealInView(cell: CellViewModel, offset?: number): void;
R
rebornix 已提交
103 104 105 106 107

	/**
	 * Reveal cell into viewport center.
	 * If `offset` is provided, `top(cell) + offset` will be scrolled into view.
	 */
R
rebornix 已提交
108
	revealInCenter(cell: CellViewModel, offset?: number): void;
R
rebornix 已提交
109 110 111 112 113

	/**
	 * Reveal cell into viewport center if cell is currently out of the viewport.
	 * If `offset` is provided, `top(cell) + offset` will be scrolled into view.
	 */
R
rebornix 已提交
114
	revealInCenterIfOutsideViewport(cell: CellViewModel, offset?: number): void;
R
rebornix 已提交
115

R
rebornix 已提交
116 117 118 119 120 121 122 123 124 125 126 127
	/**
	 * Reveal a line in notebook cell into viewport center.
	 * If `offset` is provided, `top(cell) + offset` will be scrolled into view.
	 */
	revealLineInCenter(cell: CellViewModel, line: number): void;

	/**
	 * Reveal a line in notebook cell into viewport center.
	 * If `offset` is provided, `top(cell) + offset` will be scrolled into view.
	 */
	revealLineInCenterIfOutsideViewport(cell: CellViewModel, line: number): void;

R
rebornix 已提交
128 129 130 131
	/**
	 * Change the decorations on cells.
	 * The notebook is virtualized and this method should be called to create/delete editor decorations safely.
	 */
R
rebornix 已提交
132
	changeDecorations(callback: (changeAccessor: IModelDecorationsChangeAccessor) => any): any;
R
rebornix 已提交
133 134 135 136 137 138

	/**
	 * Show Find Widget.
	 *
	 * Currently Find is still part of the NotebookEditor core
	 */
R
rebornix 已提交
139
	showFind(): void;
R
rebornix 已提交
140 141 142 143

	/**
	 * Hide Find Widget
	 */
R
rebornix 已提交
144
	hideFind(): void;
R
rebornix 已提交
145 146 147 148 149 150 151 152 153 154
}

export interface CellRenderTemplate {
	container: HTMLElement;
	cellContainer: HTMLElement;
	menuContainer?: HTMLElement;
	editingContainer?: HTMLElement;
	outputContainer?: HTMLElement;
	editor?: CodeEditorWidget;
}
R
rebornix 已提交
155 156 157 158 159 160 161 162 163

export interface IOutputTransformContribution {
	/**
	 * Dispose this contribution.
	 */
	dispose(): void;

	render(output: IOutput, container: HTMLElement, preferredMimeType: string | undefined): IRenderOutput;
}
R
rebornix 已提交
164 165 166 167 168 169

export interface CellFindMatch {
	cell: CellViewModel;
	matches: FindMatch[];
}