notebookBrowser.ts 6.6 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
import { OutputRenderer } from 'vs/workbench/contrib/notebook/browser/view/output/outputRenderer';
R
rebornix 已提交
10
import { IOutput, CellKind, IRenderOutput } from 'vs/workbench/contrib/notebook/common/notebookCommon';
R
rebornix 已提交
11
import { RawContextKey } from 'vs/platform/contextkey/common/contextkey';
R
rebornix 已提交
12
import { NotebookViewModel, IModelDecorationsChangeAccessor, CellViewModel } from 'vs/workbench/contrib/notebook/browser/viewModel/notebookViewModel';
R
rebornix 已提交
13
import { FindMatch } from 'vs/editor/common/model';
R
rebornix 已提交
14
import { Range } from 'vs/editor/common/core/range';
15 16
import { ToolBar } from 'vs/base/browser/ui/toolbar/toolbar';
import { DisposableStore } from 'vs/base/common/lifecycle';
R
rebornix 已提交
17
import { URI } from 'vs/base/common/uri';
R
Rob Lourens 已提交
18
import { ProgressBar } from 'vs/base/browser/ui/progressbar/progressbar';
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
	isNotebookEditor: boolean;

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

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

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

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

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

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

	/**
	 * Move a cell down one spot
	 */
86
	moveCellDown(cell: ICellViewModel): void;
87

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

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

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

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

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

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

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

126 127 128 129 130
	/**
	 * Send message to the webview for outputs.
	 */
	postMessage(message: any): void;

R
rebornix 已提交
131 132 133
	/**
	 * Trigger the editor to scroll from scroll event programmatically
	 */
134
	triggerScroll(event: IMouseWheelEvent): void;
R
rebornix 已提交
135 136 137 138

	/**
	 * Reveal cell into viewport.
	 */
R
rebornix 已提交
139
	revealInView(cell: ICellViewModel): void;
R
rebornix 已提交
140 141 142 143

	/**
	 * Reveal cell into viewport center.
	 */
R
rebornix 已提交
144
	revealInCenter(cell: ICellViewModel): void;
R
rebornix 已提交
145 146 147 148

	/**
	 * Reveal cell into viewport center if cell is currently out of the viewport.
	 */
R
rebornix 已提交
149
	revealInCenterIfOutsideViewport(cell: ICellViewModel): void;
R
rebornix 已提交
150 151 152 153

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

R
rebornix 已提交
156 157 158
	/**
	 * Reveal a line in notebook cell into viewport center.
	 */
R
rebornix 已提交
159
	revealLineInCenter(cell: ICellViewModel, line: number): void;
R
rebornix 已提交
160 161 162 163

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

R
rebornix 已提交
166 167 168
	/**
	 * Reveal a range in notebook cell into viewport with minimal scrolling.
	 */
R
rebornix 已提交
169
	revealRangeInView(cell: ICellViewModel, range: Range): void;
R
rebornix 已提交
170 171 172 173

	/**
	 * Reveal a range in notebook cell into viewport center.
	 */
R
rebornix 已提交
174
	revealRangeInCenter(cell: ICellViewModel, range: Range): void;
R
rebornix 已提交
175 176 177 178

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

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

R
rebornix 已提交
183 184 185 186
	/**
	 * Change the decorations on cells.
	 * The notebook is virtualized and this method should be called to create/delete editor decorations safely.
	 */
R
rebornix 已提交
187
	changeDecorations(callback: (changeAccessor: IModelDecorationsChangeAccessor) => any): any;
R
rebornix 已提交
188 189 190 191 192 193

	/**
	 * Show Find Widget.
	 *
	 * Currently Find is still part of the NotebookEditor core
	 */
R
rebornix 已提交
194
	showFind(): void;
R
rebornix 已提交
195 196 197 198

	/**
	 * Hide Find Widget
	 */
R
rebornix 已提交
199
	hideFind(): void;
R
rebornix 已提交
200 201 202 203 204
}

export interface CellRenderTemplate {
	container: HTMLElement;
	cellContainer: HTMLElement;
R
Rob Lourens 已提交
205
	editorContainer?: HTMLElement;
206
	toolbar: ToolBar;
207
	focusIndicator?: HTMLElement;
R
Rob Lourens 已提交
208
	runToolbar?: ToolBar;
R
rebornix 已提交
209 210 211
	editingContainer?: HTMLElement;
	outputContainer?: HTMLElement;
	editor?: CodeEditorWidget;
R
Rob Lourens 已提交
212
	progressBar?: ProgressBar;
213
	disposables: DisposableStore;
R
rebornix 已提交
214
}
R
rebornix 已提交
215 216 217 218 219 220 221 222 223

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

	render(output: IOutput, container: HTMLElement, preferredMimeType: string | undefined): IRenderOutput;
}
R
rebornix 已提交
224 225 226 227 228 229

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

R
rebornix 已提交
230 231 232 233 234 235 236 237 238
export enum CellRevealType {
	Line,
	Range
}

export enum CellRevealPosition {
	Top,
	Center
}
R
rebornix 已提交
239 240 241 242 243 244 245

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
	 */
246
	Preview,
R
rebornix 已提交
247 248 249 250 251 252 253


	/**
	 * Eding mode. Source for markdown or code is rendered in editors and the state will be persistent.
	 */
	Editing
}
R
rebornix 已提交
254 255 256 257 258 259 260 261 262 263 264 265

export enum CellFocusMode {
	Container,
	Editor
}

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