notebookBrowser.ts 6.5 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
import { Range } from 'vs/editor/common/core/range';
16 17
import { ToolBar } from 'vs/base/browser/ui/toolbar/toolbar';
import { DisposableStore } from 'vs/base/common/lifecycle';
R
rebornix 已提交
18
import { URI } from 'vs/base/common/uri';
R
rebornix 已提交
19 20

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

22 23
export const NOTEBOOK_EDITOR_FOCUSED = new RawContextKey<boolean>('notebookEditorFocused', false);

R
rebornix 已提交
24 25 26 27 28 29
export interface NotebookLayoutInfo {
	width: number;
	height: number;
	fontInfo: BareFontInfo;
}

R
rebornix 已提交
30 31 32 33 34 35 36 37 38 39
export interface ICellViewModel {
	readonly id: string;
	handle: number;
	uri: URI;
	cellKind: CellKind;
	state: CellState;
	focusMode: CellFocusMode;
	getText(): string;
}

40
export interface INotebookEditor {
R
rebornix 已提交
41 42 43 44

	/**
	 * Notebook view model attached to the current editor
	 */
R
rebornix 已提交
45
	viewModel: NotebookViewModel | undefined;
R
rebornix 已提交
46 47 48 49

	/**
	 * Focus the notebook editor cell list
	 */
R
rebornix 已提交
50
	focus(): void;
R
rebornix 已提交
51

R
rebornix 已提交
52 53 54
	/**
	 * Select & focus cell
	 */
R
rebornix 已提交
55
	selectElement(cell: ICellViewModel): void;
R
rebornix 已提交
56

R
rebornix 已提交
57 58 59
	/**
	 * Layout info for the notebook editor
	 */
R
rebornix 已提交
60
	getLayoutInfo(): NotebookLayoutInfo;
R
rebornix 已提交
61 62 63
	/**
	 * Fetch the output renderers for notebook outputs.
	 */
R
rebornix 已提交
64
	getOutputRenderer(): OutputRenderer;
R
rebornix 已提交
65 66 67 68

	/**
	 * Insert a new cell around `cell`
	 */
R
rebornix 已提交
69
	insertNotebookCell(cell: ICellViewModel, type: CellKind, direction: 'above' | 'below', initialText?: string): Promise<void>;
R
rebornix 已提交
70 71 72 73

	/**
	 * Delete a cell from the notebook
	 */
R
rebornix 已提交
74
	deleteNotebookCell(cell: ICellViewModel): void;
R
rebornix 已提交
75

76 77 78
	/**
	 * Move a cell up one spot
	 */
79
	moveCellUp(cell: ICellViewModel): void;
80 81 82 83

	/**
	 * Move a cell down one spot
	 */
84
	moveCellDown(cell: ICellViewModel): void;
85

R
rebornix 已提交
86 87 88 89 90 91
	/**
	 * 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 已提交
92
	editNotebookCell(cell: ICellViewModel): void;
R
rebornix 已提交
93 94 95 96

	/**
	 * Quit cell editing mode.
	 */
R
rebornix 已提交
97
	saveNotebookCell(cell: ICellViewModel): void;
R
rebornix 已提交
98 99 100 101

	/**
	 * Focus the container of a cell (the monaco editor inside is not focused).
	 */
R
rebornix 已提交
102
	focusNotebookCell(cell: ICellViewModel, focusEditor: boolean): void;
R
rebornix 已提交
103 104 105 106

	/**
	 * Get current active cell
	 */
R
rebornix 已提交
107
	getActiveCell(): ICellViewModel | undefined;
R
rebornix 已提交
108 109 110 111

	/**
	 * Layout the cell with a new height
	 */
R
rebornix 已提交
112
	layoutNotebookCell(cell: ICellViewModel, height: number): void;
R
rebornix 已提交
113 114 115 116

	/**
	 * Render the output in webview layer
	 */
R
rebornix 已提交
117
	createInset(cell: ICellViewModel, output: IOutput, shadowContent: string, offset: number): void;
R
rebornix 已提交
118 119 120 121

	/**
	 * Remove the output from the webview layer
	 */
R
rebornix 已提交
122
	removeInset(output: IOutput): void;
R
rebornix 已提交
123 124 125 126

	/**
	 * Trigger the editor to scroll from scroll event programmatically
	 */
127
	triggerScroll(event: IMouseWheelEvent): void;
R
rebornix 已提交
128 129 130 131

	/**
	 * Reveal cell into viewport.
	 */
R
rebornix 已提交
132
	revealInView(cell: ICellViewModel): void;
R
rebornix 已提交
133 134 135 136

	/**
	 * Reveal cell into viewport center.
	 */
R
rebornix 已提交
137
	revealInCenter(cell: ICellViewModel): void;
R
rebornix 已提交
138 139 140 141

	/**
	 * Reveal cell into viewport center if cell is currently out of the viewport.
	 */
R
rebornix 已提交
142
	revealInCenterIfOutsideViewport(cell: ICellViewModel): void;
R
rebornix 已提交
143 144 145 146

	/**
	 * Reveal a line in notebook cell into viewport with minimal scrolling.
	 */
R
rebornix 已提交
147
	revealLineInView(cell: ICellViewModel, line: number): void;
R
rebornix 已提交
148

R
rebornix 已提交
149 150 151
	/**
	 * Reveal a line in notebook cell into viewport center.
	 */
R
rebornix 已提交
152
	revealLineInCenter(cell: ICellViewModel, line: number): void;
R
rebornix 已提交
153 154 155 156

	/**
	 * Reveal a line in notebook cell into viewport center.
	 */
R
rebornix 已提交
157
	revealLineInCenterIfOutsideViewport(cell: ICellViewModel, line: number): void;
R
rebornix 已提交
158

R
rebornix 已提交
159 160 161
	/**
	 * Reveal a range in notebook cell into viewport with minimal scrolling.
	 */
R
rebornix 已提交
162
	revealRangeInView(cell: ICellViewModel, range: Range): void;
R
rebornix 已提交
163 164 165 166

	/**
	 * Reveal a range in notebook cell into viewport center.
	 */
R
rebornix 已提交
167
	revealRangeInCenter(cell: ICellViewModel, range: Range): void;
R
rebornix 已提交
168 169 170 171

	/**
	 * Reveal a range in notebook cell into viewport center.
	 */
R
rebornix 已提交
172
	revealRangeInCenterIfOutsideViewport(cell: ICellViewModel, range: Range): void;
R
rebornix 已提交
173

R
rebornix 已提交
174
	setCellSelection(cell: ICellViewModel, selection: Range): void;
R
rebornix 已提交
175

R
rebornix 已提交
176 177 178 179
	/**
	 * Change the decorations on cells.
	 * The notebook is virtualized and this method should be called to create/delete editor decorations safely.
	 */
R
rebornix 已提交
180
	changeDecorations(callback: (changeAccessor: IModelDecorationsChangeAccessor) => any): any;
R
rebornix 已提交
181 182 183 184 185 186

	/**
	 * Show Find Widget.
	 *
	 * Currently Find is still part of the NotebookEditor core
	 */
R
rebornix 已提交
187
	showFind(): void;
R
rebornix 已提交
188 189 190 191

	/**
	 * Hide Find Widget
	 */
R
rebornix 已提交
192
	hideFind(): void;
R
rebornix 已提交
193 194 195 196 197 198
}

export interface CellRenderTemplate {
	container: HTMLElement;
	cellContainer: HTMLElement;
	menuContainer?: HTMLElement;
199
	toolbar: ToolBar;
200
	focusIndicator?: HTMLElement;
R
rebornix 已提交
201 202 203
	editingContainer?: HTMLElement;
	outputContainer?: HTMLElement;
	editor?: CodeEditorWidget;
204
	disposables: DisposableStore;
R
rebornix 已提交
205
}
R
rebornix 已提交
206 207 208 209 210 211 212 213 214

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

	render(output: IOutput, container: HTMLElement, preferredMimeType: string | undefined): IRenderOutput;
}
R
rebornix 已提交
215 216 217 218 219 220

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

R
rebornix 已提交
221 222 223 224 225 226 227 228 229
export enum CellRevealType {
	Line,
	Range
}

export enum CellRevealPosition {
	Top,
	Center
}
R
rebornix 已提交
230 231 232 233 234 235 236

export enum CellState {
	/**
	 * Default state.
	 * For markdown cell, it's Markdown preview.
	 * For code cell, the browser focus should be on the container instead of the editor
	 */
237
	Preview,
R
rebornix 已提交
238 239 240 241 242 243 244


	/**
	 * Eding mode. Source for markdown or code is rendered in editors and the state will be persistent.
	 */
	Editing
}
R
rebornix 已提交
245 246 247 248 249 250 251 252 253 254 255 256

export enum CellFocusMode {
	Container,
	Editor
}

export enum CursorAtBoundary {
	None,
	Top,
	Bottom,
	Both
}