notebookBrowser.ts 5.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
import { Range } from 'vs/editor/common/core/range';
R
rebornix 已提交
16 17

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

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

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

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

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

R
rebornix 已提交
37 38 39 40 41
	/**
	 * Select & focus cell
	 */
	selectElement(cell: CellViewModel): void;

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

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

	/**
	 * Delete a cell from the notebook
	 */
R
rebornix 已提交
59
	deleteNotebookCell(cell: CellViewModel): void;
R
rebornix 已提交
60 61 62 63 64 65 66

	/**
	 * 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 已提交
67
	editNotebookCell(cell: CellViewModel): void;
R
rebornix 已提交
68 69 70 71

	/**
	 * Quit cell editing mode.
	 */
R
rebornix 已提交
72
	saveNotebookCell(cell: CellViewModel): void;
R
rebornix 已提交
73 74 75 76

	/**
	 * Focus the container of a cell (the monaco editor inside is not focused).
	 */
R
rebornix 已提交
77
	focusNotebookCell(cell: CellViewModel, focusEditor: boolean): void;
R
rebornix 已提交
78 79 80 81

	/**
	 * Get current active cell
	 */
R
rebornix 已提交
82
	getActiveCell(): CellViewModel | undefined;
R
rebornix 已提交
83 84 85 86

	/**
	 * Layout the cell with a new height
	 */
87
	layoutNotebookCell(cell: CellViewModel, height: number): void;
R
rebornix 已提交
88 89 90 91

	/**
	 * Render the output in webview layer
	 */
92
	createInset(cell: CellViewModel, output: IOutput, shadowContent: string, offset: number): void;
R
rebornix 已提交
93 94 95 96

	/**
	 * Remove the output from the webview layer
	 */
R
rebornix 已提交
97
	removeInset(output: IOutput): void;
R
rebornix 已提交
98 99 100 101

	/**
	 * Trigger the editor to scroll from scroll event programmatically
	 */
102
	triggerScroll(event: IMouseWheelEvent): void;
R
rebornix 已提交
103 104 105 106

	/**
	 * Reveal cell into viewport.
	 */
R
rebornix 已提交
107
	revealInView(cell: CellViewModel): void;
R
rebornix 已提交
108 109 110 111

	/**
	 * Reveal cell into viewport center.
	 */
R
rebornix 已提交
112
	revealInCenter(cell: CellViewModel): void;
R
rebornix 已提交
113 114 115 116

	/**
	 * Reveal cell into viewport center if cell is currently out of the viewport.
	 */
R
rebornix 已提交
117 118 119 120 121 122
	revealInCenterIfOutsideViewport(cell: CellViewModel): void;

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

R
rebornix 已提交
124 125 126 127 128 129 130 131 132 133
	/**
	 * 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 已提交
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
	/**
	 * 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 已提交
149
	setCellSelection(cell: CellViewModel, selection: Range): void;
R
rebornix 已提交
150

R
rebornix 已提交
151 152 153 154
	/**
	 * Change the decorations on cells.
	 * The notebook is virtualized and this method should be called to create/delete editor decorations safely.
	 */
R
rebornix 已提交
155
	changeDecorations(callback: (changeAccessor: IModelDecorationsChangeAccessor) => any): any;
R
rebornix 已提交
156 157 158 159 160 161

	/**
	 * Show Find Widget.
	 *
	 * Currently Find is still part of the NotebookEditor core
	 */
R
rebornix 已提交
162
	showFind(): void;
R
rebornix 已提交
163 164 165 166

	/**
	 * Hide Find Widget
	 */
R
rebornix 已提交
167
	hideFind(): void;
R
rebornix 已提交
168 169 170 171 172 173 174 175 176 177
}

export interface CellRenderTemplate {
	container: HTMLElement;
	cellContainer: HTMLElement;
	menuContainer?: HTMLElement;
	editingContainer?: HTMLElement;
	outputContainer?: HTMLElement;
	editor?: CodeEditorWidget;
}
R
rebornix 已提交
178 179 180 181 182 183 184 185 186

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

	render(output: IOutput, container: HTMLElement, preferredMimeType: string | undefined): IRenderOutput;
}
R
rebornix 已提交
187 188 189 190 191 192

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

R
rebornix 已提交
193 194 195 196 197 198 199 200 201
export enum CellRevealType {
	Line,
	Range
}

export enum CellRevealPosition {
	Top,
	Center
}
R
rebornix 已提交
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222

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
}