notebookBrowser.ts 6.3 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 19

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

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

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

29
export interface INotebookEditor {
R
rebornix 已提交
30 31 32 33

	/**
	 * Notebook view model attached to the current editor
	 */
R
rebornix 已提交
34
	viewModel: NotebookViewModel | undefined;
R
rebornix 已提交
35 36 37 38

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

R
rebornix 已提交
41 42 43 44 45
	/**
	 * Select & focus cell
	 */
	selectElement(cell: CellViewModel): void;

R
rebornix 已提交
46 47 48
	/**
	 * Layout info for the notebook editor
	 */
R
rebornix 已提交
49
	getLayoutInfo(): NotebookLayoutInfo;
R
rebornix 已提交
50 51 52
	/**
	 * Fetch the output renderers for notebook outputs.
	 */
R
rebornix 已提交
53
	getOutputRenderer(): OutputRenderer;
R
rebornix 已提交
54 55 56 57

	/**
	 * Insert a new cell around `cell`
	 */
58
	insertNotebookCell(cell: CellViewModel, type: CellKind, direction: 'above' | 'below', initialText?: string): Promise<void>;
R
rebornix 已提交
59 60 61 62

	/**
	 * Delete a cell from the notebook
	 */
R
rebornix 已提交
63
	deleteNotebookCell(cell: CellViewModel): void;
R
rebornix 已提交
64

65 66 67 68 69 70 71 72 73 74
	/**
	 * Move a cell up one spot
	 */
	moveCellUp(cell: CellViewModel): void;

	/**
	 * Move a cell down one spot
	 */
	moveCellDown(cell: CellViewModel): void;

R
rebornix 已提交
75 76 77 78 79 80
	/**
	 * 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 已提交
81
	editNotebookCell(cell: CellViewModel): void;
R
rebornix 已提交
82 83 84 85

	/**
	 * Quit cell editing mode.
	 */
R
rebornix 已提交
86
	saveNotebookCell(cell: CellViewModel): void;
R
rebornix 已提交
87 88 89 90

	/**
	 * Focus the container of a cell (the monaco editor inside is not focused).
	 */
R
rebornix 已提交
91
	focusNotebookCell(cell: CellViewModel, focusEditor: boolean): void;
R
rebornix 已提交
92 93 94 95

	/**
	 * Get current active cell
	 */
R
rebornix 已提交
96
	getActiveCell(): CellViewModel | undefined;
R
rebornix 已提交
97 98 99 100

	/**
	 * Layout the cell with a new height
	 */
101
	layoutNotebookCell(cell: CellViewModel, height: number): void;
R
rebornix 已提交
102 103 104 105

	/**
	 * Render the output in webview layer
	 */
106
	createInset(cell: CellViewModel, output: IOutput, shadowContent: string, offset: number): void;
R
rebornix 已提交
107 108 109 110

	/**
	 * Remove the output from the webview layer
	 */
R
rebornix 已提交
111
	removeInset(output: IOutput): void;
R
rebornix 已提交
112 113 114 115

	/**
	 * Trigger the editor to scroll from scroll event programmatically
	 */
116
	triggerScroll(event: IMouseWheelEvent): void;
R
rebornix 已提交
117 118 119 120

	/**
	 * Reveal cell into viewport.
	 */
R
rebornix 已提交
121
	revealInView(cell: CellViewModel): void;
R
rebornix 已提交
122 123 124 125

	/**
	 * Reveal cell into viewport center.
	 */
R
rebornix 已提交
126
	revealInCenter(cell: CellViewModel): void;
R
rebornix 已提交
127 128 129 130

	/**
	 * Reveal cell into viewport center if cell is currently out of the viewport.
	 */
R
rebornix 已提交
131 132 133 134 135 136
	revealInCenterIfOutsideViewport(cell: CellViewModel): void;

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

R
rebornix 已提交
138 139 140 141 142 143 144 145 146 147
	/**
	 * Reveal a line in notebook cell into viewport center.
	 */
	revealLineInCenter(cell: CellViewModel, line: number): void;

	/**
	 * Reveal a line in notebook cell into viewport center.
	 */
	revealLineInCenterIfOutsideViewport(cell: CellViewModel, line: number): void;

R
rebornix 已提交
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
	/**
	 * Reveal a range in notebook cell into viewport with minimal scrolling.
	 */
	revealRangeInView(cell: CellViewModel, range: Range): void;

	/**
	 * Reveal a range in notebook cell into viewport center.
	 */
	revealRangeInCenter(cell: CellViewModel, range: Range): void;

	/**
	 * Reveal a range in notebook cell into viewport center.
	 */
	revealRangeInCenterIfOutsideViewport(cell: CellViewModel, range: Range): void;

R
rebornix 已提交
163
	setCellSelection(cell: CellViewModel, selection: Range): void;
R
rebornix 已提交
164

R
rebornix 已提交
165 166 167 168
	/**
	 * Change the decorations on cells.
	 * The notebook is virtualized and this method should be called to create/delete editor decorations safely.
	 */
R
rebornix 已提交
169
	changeDecorations(callback: (changeAccessor: IModelDecorationsChangeAccessor) => any): any;
R
rebornix 已提交
170 171 172 173 174 175

	/**
	 * Show Find Widget.
	 *
	 * Currently Find is still part of the NotebookEditor core
	 */
R
rebornix 已提交
176
	showFind(): void;
R
rebornix 已提交
177 178 179 180

	/**
	 * Hide Find Widget
	 */
R
rebornix 已提交
181
	hideFind(): void;
R
rebornix 已提交
182 183 184 185 186 187
}

export interface CellRenderTemplate {
	container: HTMLElement;
	cellContainer: HTMLElement;
	menuContainer?: HTMLElement;
188
	toolbar: ToolBar;
R
rebornix 已提交
189 190 191
	editingContainer?: HTMLElement;
	outputContainer?: HTMLElement;
	editor?: CodeEditorWidget;
192
	disposables: DisposableStore;
R
rebornix 已提交
193
}
R
rebornix 已提交
194 195 196 197 198 199 200 201 202

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

	render(output: IOutput, container: HTMLElement, preferredMimeType: string | undefined): IRenderOutput;
}
R
rebornix 已提交
203 204 205 206 207 208

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

R
rebornix 已提交
209 210 211 212 213 214 215 216 217
export enum CellRevealType {
	Line,
	Range
}

export enum CellRevealPosition {
	Top,
	Center
}
R
rebornix 已提交
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238

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
	 */
	Read,

	/**
	 * Content preview mode.
	 * For markdown cell, the source is now rendered in the editor. When the cell is not longer focsued/selected, it will fall back to Read mode.
	 * For code cell, this state is the same as Editing
	 */
	PreviewContent,

	/**
	 * Eding mode. Source for markdown or code is rendered in editors and the state will be persistent.
	 */
	Editing
}