Path: blob/main/src/vs/workbench/contrib/notebook/browser/notebookBrowser.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { CodeWindow } from '../../../../base/browser/window.js';6import { CancellationToken } from '../../../../base/common/cancellation.js';7import { Event } from '../../../../base/common/event.js';8import { IDisposable } from '../../../../base/common/lifecycle.js';9import { URI } from '../../../../base/common/uri.js';10import { IEditorContributionDescription } from '../../../../editor/browser/editorExtensions.js';11import * as editorCommon from '../../../../editor/common/editorCommon.js';12import { FontInfo } from '../../../../editor/common/config/fontInfo.js';13import { IPosition } from '../../../../editor/common/core/position.js';14import { IRange, Range } from '../../../../editor/common/core/range.js';15import { Selection } from '../../../../editor/common/core/selection.js';16import { FindMatch, IModelDeltaDecoration, IReadonlyTextBuffer, ITextModel, TrackedRangeStickiness } from '../../../../editor/common/model.js';17import { MenuId } from '../../../../platform/actions/common/actions.js';18import { ITextEditorOptions, ITextResourceEditorInput } from '../../../../platform/editor/common/editor.js';19import { IConstructorSignature } from '../../../../platform/instantiation/common/instantiation.js';20import { IEditorPane, IEditorPaneWithSelection } from '../../../common/editor.js';21import { CellViewModelStateChangeEvent, NotebookCellStateChangedEvent, NotebookLayoutInfo } from './notebookViewEvents.js';22import { NotebookCellTextModel } from '../common/model/notebookCellTextModel.js';23import { NotebookTextModel } from '../common/model/notebookTextModel.js';24import { CellKind, ICellOutput, INotebookCellStatusBarItem, INotebookRendererInfo, INotebookFindOptions, IOrderedMimeType, NotebookCellInternalMetadata, NotebookCellMetadata, NOTEBOOK_EDITOR_ID, NOTEBOOK_DIFF_EDITOR_ID } from '../common/notebookCommon.js';25import { isCompositeNotebookEditorInput } from '../common/notebookEditorInput.js';26import { INotebookKernel } from '../common/notebookKernelService.js';27import { NotebookOptions } from './notebookOptions.js';28import { cellRangesToIndexes, ICellRange, reduceCellRanges } from '../common/notebookRange.js';29import { IWebviewElement } from '../../webview/browser/webview.js';30import { IEditorCommentsOptions, IEditorOptions } from '../../../../editor/common/config/editorOptions.js';31import { IContextKeyService } from '../../../../platform/contextkey/common/contextkey.js';32import { ICodeEditor } from '../../../../editor/browser/editorBrowser.js';33import { IObservable } from '../../../../base/common/observable.js';34import { INotebookTextDiffEditor } from './diff/notebookDiffEditorBrowser.js';3536//#region Shared commands37export const EXPAND_CELL_INPUT_COMMAND_ID = 'notebook.cell.expandCellInput';38export const EXECUTE_CELL_COMMAND_ID = 'notebook.cell.execute';39export const DETECT_CELL_LANGUAGE = 'notebook.cell.detectLanguage';40export const CHANGE_CELL_LANGUAGE = 'notebook.cell.changeLanguage';41export const QUIT_EDIT_CELL_COMMAND_ID = 'notebook.cell.quitEdit';42export const EXPAND_CELL_OUTPUT_COMMAND_ID = 'notebook.cell.expandCellOutput';434445//#endregion4647//#region Notebook extensions4849// Hardcoding viewType/extension ID for now. TODO these should be replaced once we can50// look them up in the marketplace dynamically.51export const IPYNB_VIEW_TYPE = 'jupyter-notebook';52export const JUPYTER_EXTENSION_ID = 'ms-toolsai.jupyter';53/** @deprecated use the notebookKernel<Type> "keyword" instead */54export const KERNEL_EXTENSIONS = new Map<string, string>([55[IPYNB_VIEW_TYPE, JUPYTER_EXTENSION_ID],56]);57// @TODO lramos15, place this in a similar spot to our normal recommendations.58export const KERNEL_RECOMMENDATIONS = new Map<string, Map<string, INotebookExtensionRecommendation>>();59KERNEL_RECOMMENDATIONS.set(IPYNB_VIEW_TYPE, new Map<string, INotebookExtensionRecommendation>());60KERNEL_RECOMMENDATIONS.get(IPYNB_VIEW_TYPE)?.set('python', {61extensionIds: [62'ms-python.python',63JUPYTER_EXTENSION_ID64],65displayName: 'Python + Jupyter',66});6768export interface INotebookExtensionRecommendation {69readonly extensionIds: string[];70readonly displayName?: string;71}7273//#endregion7475//#region Output related types7677// !! IMPORTANT !! ----------------------------------------------------------------------------------78// NOTE that you MUST update vs/workbench/contrib/notebook/browser/view/renderers/webviewPreloads.ts#L198679// whenever changing the values of this const enum. The webviewPreloads-files manually inlines these values80// because it cannot have dependencies.81// !! IMPORTANT !! ----------------------------------------------------------------------------------82export const enum RenderOutputType {83Html = 0,84Extension = 185}8687export interface IRenderPlainHtmlOutput {88readonly type: RenderOutputType.Html;89readonly source: IDisplayOutputViewModel;90readonly htmlContent: string;91}9293export interface IRenderOutputViaExtension {94readonly type: RenderOutputType.Extension;95readonly source: IDisplayOutputViewModel;96readonly mimeType: string;97readonly renderer: INotebookRendererInfo;98}99100export type IInsetRenderOutput = IRenderPlainHtmlOutput | IRenderOutputViaExtension;101102export interface ICellOutputViewModel extends IDisposable {103cellViewModel: IGenericCellViewModel;104/**105* When rendering an output, `model` should always be used as we convert legacy `text/error` output to `display_data` output under the hood.106*/107model: ICellOutput;108resolveMimeTypes(textModel: NotebookTextModel, kernelProvides: readonly string[] | undefined): [readonly IOrderedMimeType[], number];109pickedMimeType: IOrderedMimeType | undefined;110hasMultiMimeType(): boolean;111readonly onDidResetRenderer: Event<void>;112readonly visible: IObservable<boolean>;113setVisible(visible: boolean, force?: boolean): void;114resetRenderer(): void;115toRawJSON(): any;116}117118export interface IDisplayOutputViewModel extends ICellOutputViewModel {119resolveMimeTypes(textModel: NotebookTextModel, kernelProvides: readonly string[] | undefined): [readonly IOrderedMimeType[], number];120}121122123//#endregion124125//#region Shared types between the Notebook Editor and Notebook Diff Editor, they are mostly used for output rendering126127export interface IGenericCellViewModel {128id: string;129handle: number;130uri: URI;131metadata: NotebookCellMetadata;132outputIsHovered: boolean;133outputIsFocused: boolean;134inputInOutputIsFocused: boolean;135outputsViewModels: ICellOutputViewModel[];136getOutputOffset(index: number): number;137updateOutputHeight(index: number, height: number, source?: string): void;138}139140export interface IDisplayOutputLayoutUpdateRequest {141readonly cell: IGenericCellViewModel;142output: IDisplayOutputViewModel;143cellTop: number;144outputOffset: number;145forceDisplay: boolean;146}147148export interface ICommonCellInfo {149readonly cellId: string;150readonly cellHandle: number;151readonly cellUri: URI;152readonly executionId?: string;153}154155export enum ScrollToRevealBehavior {156fullCell,157firstLine158}159160export interface IFocusNotebookCellOptions {161readonly skipReveal?: boolean;162readonly focusEditorLine?: number;163readonly revealBehavior?: ScrollToRevealBehavior | undefined;164readonly outputId?: string;165readonly altOutputId?: string;166readonly outputWebviewFocused?: boolean;167}168169//#endregion170171export enum CellLayoutState {172Uninitialized,173Estimated,174FromCache,175Measured176}177178/** LayoutInfo of the parts that are shared between all cell types. */179export interface CellLayoutInfo {180readonly layoutState: CellLayoutState;181readonly fontInfo: FontInfo | null;182readonly chatHeight: number;183readonly editorWidth: number;184readonly editorHeight: number;185readonly statusBarHeight: number;186readonly commentOffset: number;187readonly commentHeight: number;188readonly bottomToolbarOffset: number;189readonly totalHeight: number;190}191192export interface CellLayoutChangeEvent {193readonly font?: FontInfo;194readonly outerWidth?: number;195readonly commentHeight?: boolean;196}197198export interface CodeCellLayoutInfo extends CellLayoutInfo {199readonly estimatedHasHorizontalScrolling: boolean;200readonly outputContainerOffset: number;201readonly outputTotalHeight: number;202readonly outputShowMoreContainerHeight: number;203readonly outputShowMoreContainerOffset: number;204readonly codeIndicatorHeight: number;205readonly outputIndicatorHeight: number;206}207208export interface CodeCellLayoutChangeEvent extends CellLayoutChangeEvent {209readonly source?: string;210readonly chatHeight?: boolean;211readonly editorHeight?: boolean;212readonly outputHeight?: boolean;213readonly outputShowMoreContainerHeight?: number;214readonly totalHeight?: boolean;215}216217export interface MarkupCellLayoutInfo extends CellLayoutInfo {218readonly previewHeight: number;219readonly foldHintHeight: number;220}221222export enum CellLayoutContext {223Fold224}225226export interface MarkupCellLayoutChangeEvent extends CellLayoutChangeEvent {227readonly editorHeight?: number;228readonly previewHeight?: number;229totalHeight?: number;230readonly context?: CellLayoutContext;231}232233export interface ICommonCellViewModelLayoutChangeInfo {234readonly totalHeight?: boolean | number;235readonly outerWidth?: number;236readonly context?: CellLayoutContext;237}238export interface ICellViewModel extends IGenericCellViewModel {239readonly model: NotebookCellTextModel;240readonly id: string;241readonly textBuffer: IReadonlyTextBuffer;242readonly layoutInfo: CellLayoutInfo;243readonly onDidChangeLayout: Event<ICommonCellViewModelLayoutChangeInfo>;244readonly onDidChangeCellStatusBarItems: Event<void>;245readonly onCellDecorationsChanged: Event<{ added: INotebookCellDecorationOptions[]; removed: INotebookCellDecorationOptions[] }>;246readonly onDidChangeState: Event<CellViewModelStateChangeEvent>;247readonly onDidChangeEditorAttachState: Event<void>;248readonly editStateSource: string;249readonly editorAttached: boolean;250isInputCollapsed: boolean;251isOutputCollapsed: boolean;252dragging: boolean;253handle: number;254uri: URI;255language: string;256readonly mime: string;257cellKind: CellKind;258lineNumbers: 'on' | 'off' | 'inherit';259commentOptions: IEditorCommentsOptions;260chatHeight: number;261commentHeight: number;262focusMode: CellFocusMode;263focusedOutputId?: string | undefined;264outputIsHovered: boolean;265getText(): string;266getAlternativeId(): number;267getTextLength(): number;268getHeight(lineHeight: number): number;269metadata: NotebookCellMetadata;270internalMetadata: NotebookCellInternalMetadata;271textModel: ITextModel | undefined;272hasModel(): this is IEditableCellViewModel;273resolveTextModel(): Promise<ITextModel>;274getSelections(): Selection[];275setSelections(selections: Selection[]): void;276getSelectionsStartPosition(): IPosition[] | undefined;277getCellDecorations(): INotebookCellDecorationOptions[];278getCellStatusBarItems(): INotebookCellStatusBarItem[];279getEditState(): CellEditState;280updateEditState(state: CellEditState, source: string): void;281deltaModelDecorations(oldDecorations: readonly string[], newDecorations: readonly IModelDeltaDecoration[]): string[];282getCellDecorationRange(id: string): Range | null;283enableAutoLanguageDetection(): void;284}285286export interface IEditableCellViewModel extends ICellViewModel {287textModel: ITextModel;288}289290export interface INotebookEditorMouseEvent {291readonly event: MouseEvent;292readonly target: ICellViewModel;293}294295export interface INotebookEditorContribution {296/**297* Dispose this contribution.298*/299dispose(): void;300/**301* Store view state.302*/303saveViewState?(): unknown;304/**305* Restore view state.306*/307restoreViewState?(state: unknown): void;308}309310/**311* Vertical Lane in the overview ruler of the notebook editor.312*/313export enum NotebookOverviewRulerLane {314Left = 1,315Center = 2,316Right = 4,317Full = 7318}319320export interface INotebookCellDecorationOptions {321className?: string;322gutterClassName?: string;323outputClassName?: string;324topClassName?: string;325overviewRuler?: {326color: string;327modelRanges: IRange[];328includeOutput: boolean;329position: NotebookOverviewRulerLane;330};331}332333export interface INotebookViewZoneDecorationOptions {334overviewRuler?: {335color: string;336position: NotebookOverviewRulerLane;337};338}339340export interface INotebookDeltaCellDecoration {341readonly handle: number;342readonly options: INotebookCellDecorationOptions;343}344345export interface INotebookDeltaViewZoneDecoration {346readonly viewZoneId: string;347readonly options: INotebookViewZoneDecorationOptions;348}349350export function isNotebookCellDecoration(obj: unknown): obj is INotebookDeltaCellDecoration {351return !!obj && typeof (obj as INotebookDeltaCellDecoration).handle === 'number';352}353354export function isNotebookViewZoneDecoration(obj: unknown): obj is INotebookDeltaViewZoneDecoration {355return !!obj && typeof (obj as INotebookDeltaViewZoneDecoration).viewZoneId === 'string';356}357358export type INotebookDeltaDecoration = INotebookDeltaCellDecoration | INotebookDeltaViewZoneDecoration;359360export interface INotebookDeltaCellStatusBarItems {361readonly handle: number;362readonly items: readonly INotebookCellStatusBarItem[];363}364365export const enum CellRevealType {366Default = 1,367Top = 2,368Center = 3,369CenterIfOutsideViewport = 4,370NearTopIfOutsideViewport = 5,371FirstLineIfOutsideViewport = 6372}373374export enum CellRevealRangeType {375Default = 1,376Center = 2,377CenterIfOutsideViewport = 3,378}379380export interface INotebookEditorOptions extends ITextEditorOptions {381readonly cellOptions?: ITextResourceEditorInput;382readonly cellRevealType?: CellRevealType;383readonly cellSelections?: ICellRange[];384readonly isReadOnly?: boolean;385readonly viewState?: INotebookEditorViewState;386readonly indexedCellOptions?: { index: number; selection?: IRange };387readonly label?: string;388}389390export type INotebookEditorContributionCtor = IConstructorSignature<INotebookEditorContribution, [INotebookEditor]>;391392export interface INotebookEditorContributionDescription {393id: string;394ctor: INotebookEditorContributionCtor;395}396397export interface INotebookEditorCreationOptions {398readonly isReplHistory?: boolean;399readonly isReadOnly?: boolean;400readonly contributions?: INotebookEditorContributionDescription[];401readonly cellEditorContributions?: IEditorContributionDescription[];402readonly menuIds: {403notebookToolbar: MenuId;404cellTitleToolbar: MenuId;405cellDeleteToolbar: MenuId;406cellInsertToolbar: MenuId;407cellTopInsertToolbar: MenuId;408cellExecuteToolbar: MenuId;409cellExecutePrimary?: MenuId;410};411readonly options?: NotebookOptions;412readonly codeWindow?: CodeWindow;413}414415export interface INotebookWebviewMessage {416readonly message: unknown;417}418419//#region Notebook View Model420export interface INotebookEditorViewState {421editingCells: { [key: number]: boolean };422collapsedInputCells: { [key: number]: boolean };423collapsedOutputCells: { [key: number]: boolean };424cellLineNumberStates: { [key: number]: 'on' | 'off' };425editorViewStates: { [key: number]: editorCommon.ICodeEditorViewState | null };426hiddenFoldingRanges?: ICellRange[];427cellTotalHeights?: { [key: number]: number };428scrollPosition?: { left: number; top: number };429focus?: number;430editorFocused?: boolean;431contributionsState?: { [id: string]: unknown };432selectedKernelId?: string;433}434435export interface ICellModelDecorations {436readonly ownerId: number;437readonly decorations: readonly string[];438}439440export interface ICellModelDeltaDecorations {441readonly ownerId: number;442readonly decorations: readonly IModelDeltaDecoration[];443}444445export interface IModelDecorationsChangeAccessor {446deltaDecorations(oldDecorations: ICellModelDecorations[], newDecorations: ICellModelDeltaDecorations[]): ICellModelDecorations[];447}448449export interface INotebookViewZone {450/**451* Use 0 to place a view zone before the first cell452*/453afterModelPosition: number;454domNode: HTMLElement;455456heightInPx: number;457}458459export interface INotebookViewZoneChangeAccessor {460addZone(zone: INotebookViewZone): string;461removeZone(id: string): void;462layoutZone(id: string): void;463}464465export interface INotebookCellOverlay {466cell: ICellViewModel;467domNode: HTMLElement;468}469470export interface INotebookCellOverlayChangeAccessor {471addOverlay(overlay: INotebookCellOverlay): string;472removeOverlay(id: string): void;473layoutOverlay(id: string): void;474}475476export type NotebookViewCellsSplice = [477number /* start */,478number /* delete count */,479ICellViewModel[]480];481482export interface INotebookViewCellsUpdateEvent {483readonly synchronous: boolean;484readonly splices: readonly NotebookViewCellsSplice[];485}486487export interface INotebookViewModel {488notebookDocument: NotebookTextModel;489readonly viewCells: ICellViewModel[];490layoutInfo: NotebookLayoutInfo | null;491viewType: string;492onDidChangeViewCells: Event<INotebookViewCellsUpdateEvent>;493onDidChangeSelection: Event<string>;494onDidFoldingStateChanged: Event<void>;495getNearestVisibleCellIndexUpwards(index: number): number;496getTrackedRange(id: string): ICellRange | null;497setTrackedRange(id: string | null, newRange: ICellRange | null, newStickiness: TrackedRangeStickiness): string | null;498getOverviewRulerDecorations(): INotebookDeltaViewZoneDecoration[];499getSelections(): ICellRange[];500getCellIndex(cell: ICellViewModel): number;501getMostRecentlyExecutedCell(): ICellViewModel | undefined;502deltaCellStatusBarItems(oldItems: string[], newItems: INotebookDeltaCellStatusBarItems[]): string[];503getFoldedLength(index: number): number;504getFoldingStartIndex(index: number): number;505replaceOne(cell: ICellViewModel, range: Range, text: string): Promise<void>;506replaceAll(matches: CellFindMatchWithIndex[], texts: string[]): Promise<void>;507}508//#endregion509510export interface INotebookEditor {511//#region Eventing512readonly onDidChangeCellState: Event<NotebookCellStateChangedEvent>;513readonly onDidChangeViewCells: Event<INotebookViewCellsUpdateEvent>;514readonly onDidChangeVisibleRanges: Event<void>;515readonly onDidChangeSelection: Event<void>;516readonly onDidChangeFocus: Event<void>;517/**518* An event emitted when the model of this editor has changed.519*/520readonly onDidChangeModel: Event<NotebookTextModel | undefined>;521readonly onDidAttachViewModel: Event<void>;522readonly onDidFocusWidget: Event<void>;523readonly onDidBlurWidget: Event<void>;524readonly onDidScroll: Event<void>;525readonly onDidChangeLayout: Event<void>;526readonly onDidChangeActiveCell: Event<void>;527readonly onDidChangeActiveEditor: Event<INotebookEditor>;528readonly onDidChangeActiveKernel: Event<void>;529readonly onMouseUp: Event<INotebookEditorMouseEvent>;530readonly onMouseDown: Event<INotebookEditorMouseEvent>;531//#endregion532533//#region readonly properties534readonly visibleRanges: ICellRange[];535readonly textModel?: NotebookTextModel;536readonly isVisible: boolean;537readonly isReadOnly: boolean;538readonly notebookOptions: NotebookOptions;539readonly isDisposed: boolean;540readonly activeKernel: INotebookKernel | undefined;541readonly scrollTop: number;542readonly scrollBottom: number;543readonly scopedContextKeyService: IContextKeyService;544/**545* Required for Composite Editor check. The interface should not be changed.546*/547readonly activeCodeEditor: ICodeEditor | undefined;548readonly codeEditors: [ICellViewModel, ICodeEditor][];549readonly activeCellAndCodeEditor: [ICellViewModel, ICodeEditor] | undefined;550//#endregion551552getLength(): number;553getSelections(): ICellRange[];554setSelections(selections: ICellRange[]): void;555getFocus(): ICellRange;556setFocus(focus: ICellRange): void;557getId(): string;558559getViewModel(): INotebookViewModel | undefined;560hasModel(): this is IActiveNotebookEditor;561dispose(): void;562getDomNode(): HTMLElement;563getInnerWebview(): IWebviewElement | undefined;564getSelectionViewModels(): ICellViewModel[];565getEditorViewState(): INotebookEditorViewState;566restoreListViewState(viewState: INotebookEditorViewState | undefined): void;567568getBaseCellEditorOptions(language: string): IBaseCellEditorOptions;569570/**571* Focus the active cell in notebook cell list572*/573focus(): void;574575/**576* Focus the notebook cell list container577*/578focusContainer(clearSelection?: boolean): void;579580hasEditorFocus(): boolean;581hasWebviewFocus(): boolean;582583hasOutputTextSelection(): boolean;584setOptions(options: INotebookEditorOptions | undefined): Promise<void>;585586/**587* Select & focus cell588*/589focusElement(cell: ICellViewModel): void;590591/**592* Layout info for the notebook editor593*/594getLayoutInfo(): NotebookLayoutInfo;595596getVisibleRangesPlusViewportAboveAndBelow(): ICellRange[];597598/**599* Focus the container of a cell (the monaco editor inside is not focused).600*/601focusNotebookCell(cell: ICellViewModel, focus: 'editor' | 'container' | 'output', options?: IFocusNotebookCellOptions): Promise<void>;602603/**604* Execute the given notebook cells605*/606executeNotebookCells(cells?: Iterable<ICellViewModel>): Promise<void>;607608/**609* Cancel the given notebook cells610*/611cancelNotebookCells(cells?: Iterable<ICellViewModel>): Promise<void>;612613/**614* Get current active cell615*/616getActiveCell(): ICellViewModel | undefined;617618/**619* Layout the cell with a new height620*/621layoutNotebookCell(cell: ICellViewModel, height: number): Promise<void>;622623/**624* Render the output in webview layer625*/626createOutput(cell: ICellViewModel, output: IInsetRenderOutput, offset: number, createWhenIdle: boolean): Promise<void>;627628/**629* Update the output in webview layer with latest content. It will delegate to `createOutput` is the output is not rendered yet630*/631updateOutput(cell: ICellViewModel, output: IInsetRenderOutput, offset: number): Promise<void>;632633/**634* Copy the image in the specific cell output to the clipboard635*/636copyOutputImage(cellOutput: ICellOutputViewModel): Promise<void>;637/**638* Select the contents of the first focused output of the cell.639* Implementation of Ctrl+A for an output item.640*/641selectOutputContent(cell: ICellViewModel): void;642/**643* Select the active input element of the first focused output of the cell.644* Implementation of Ctrl+A for an input element in an output item.645*/646selectInputContents(cell: ICellViewModel): void;647648readonly onDidReceiveMessage: Event<INotebookWebviewMessage>;649650/**651* Send message to the webview for outputs.652*/653postMessage(message: any): void;654655/**656* Remove class name on the notebook editor root DOM node.657*/658addClassName(className: string): void;659660/**661* Remove class name on the notebook editor root DOM node.662*/663removeClassName(className: string): void;664665/**666* Set scrollTop value of the notebook editor.667*/668setScrollTop(scrollTop: number): void;669670/**671* The range will be revealed with as little scrolling as possible.672*/673revealCellRangeInView(range: ICellRange): void;674675/**676* Reveal cell into viewport.677*/678revealInView(cell: ICellViewModel): Promise<void>;679680/**681* Reveal cell into the top of viewport.682*/683revealInViewAtTop(cell: ICellViewModel): void;684685/**686* Reveal cell into viewport center.687*/688revealInCenter(cell: ICellViewModel): void;689690/**691* Reveal cell into viewport center if cell is currently out of the viewport.692*/693revealInCenterIfOutsideViewport(cell: ICellViewModel): Promise<void>;694695/**696* Reveal the first line of the cell into the view if the cell is outside of the viewport.697*/698revealFirstLineIfOutsideViewport(cell: ICellViewModel): Promise<void>;699700/**701* Reveal a line in notebook cell into viewport with minimal scrolling.702*/703revealLineInViewAsync(cell: ICellViewModel, line: number): Promise<void>;704705/**706* Reveal a line in notebook cell into viewport center.707*/708revealLineInCenterAsync(cell: ICellViewModel, line: number): Promise<void>;709710/**711* Reveal a line in notebook cell into viewport center.712*/713revealLineInCenterIfOutsideViewportAsync(cell: ICellViewModel, line: number): Promise<void>;714715/**716* Reveal a range in notebook cell into viewport with minimal scrolling.717*/718revealRangeInViewAsync(cell: ICellViewModel, range: Selection | Range): Promise<void>;719720/**721* Reveal a range in notebook cell into viewport center.722*/723revealRangeInCenterAsync(cell: ICellViewModel, range: Selection | Range): Promise<void>;724725/**726* Reveal a range in notebook cell into viewport center.727*/728revealRangeInCenterIfOutsideViewportAsync(cell: ICellViewModel, range: Selection | Range): Promise<void>;729730/**731* Reveal a position with `offset` in a cell into viewport center.732*/733revealCellOffsetInCenter(cell: ICellViewModel, offset: number): void;734735/**736* Reveal `offset` in the list view into viewport center if it is outside of the viewport.737*/738revealOffsetInCenterIfOutsideViewport(offset: number): void;739740/**741* Convert the view range to model range742* @param startIndex Inclusive743* @param endIndex Exclusive744*/745getCellRangeFromViewRange(startIndex: number, endIndex: number): ICellRange | undefined;746747/**748* Set hidden areas on cell text models.749*/750setHiddenAreas(_ranges: ICellRange[]): boolean;751752/**753* Set selectiosn on the text editor attached to the cell754*/755756setCellEditorSelection(cell: ICellViewModel, selection: Range): void;757758/**759*Change the decorations on the notebook cell list760*/761762deltaCellDecorations(oldDecorations: string[], newDecorations: INotebookDeltaDecoration[]): string[];763764/**765* Change the decorations on cell editors.766* The notebook is virtualized and this method should be called to create/delete editor decorations safely.767*/768changeModelDecorations<T>(callback: (changeAccessor: IModelDecorationsChangeAccessor) => T): T | null;769770changeViewZones(callback: (accessor: INotebookViewZoneChangeAccessor) => void): void;771772changeCellOverlays(callback: (accessor: INotebookCellOverlayChangeAccessor) => void): void;773774getViewZoneLayoutInfo(id: string): { top: number; height: number } | null;775776/**777* Get a contribution of this editor.778* @id Unique identifier of the contribution.779* @return The contribution or null if contribution not found.780*/781getContribution<T extends INotebookEditorContribution>(id: string): T;782783/**784* Get the view index of a cell at model `index`785*/786getViewIndexByModelIndex(index: number): number;787getCellsInRange(range?: ICellRange): ReadonlyArray<ICellViewModel>;788cellAt(index: number): ICellViewModel | undefined;789getCellByHandle(handle: number): ICellViewModel | undefined;790getCellIndex(cell: ICellViewModel): number | undefined;791getNextVisibleCellIndex(index: number): number | undefined;792getPreviousVisibleCellIndex(index: number): number | undefined;793find(query: string, options: INotebookFindOptions, token: CancellationToken, skipWarmup?: boolean, shouldGetSearchPreviewInfo?: boolean, ownerID?: string): Promise<CellFindMatchWithIndex[]>;794findHighlightCurrent(matchIndex: number, ownerID?: string): Promise<number>;795findUnHighlightCurrent(matchIndex: number, ownerID?: string): Promise<void>;796findStop(ownerID?: string): void;797showProgress(): void;798hideProgress(): void;799800getAbsoluteTopOfElement(cell: ICellViewModel): number;801getAbsoluteBottomOfElement(cell: ICellViewModel): number;802getHeightOfElement(cell: ICellViewModel): number;803}804805export interface IActiveNotebookEditor extends INotebookEditor {806getViewModel(): INotebookViewModel;807textModel: NotebookTextModel;808getFocus(): ICellRange;809cellAt(index: number): ICellViewModel;810getCellIndex(cell: ICellViewModel): number;811getNextVisibleCellIndex(index: number): number;812}813814export interface INotebookEditorPane extends IEditorPaneWithSelection {815getControl(): INotebookEditor | undefined;816readonly onDidChangeModel: Event<void>;817textModel: NotebookTextModel | undefined;818}819820export interface IBaseCellEditorOptions extends IDisposable {821readonly value: IEditorOptions;822readonly onDidChange: Event<void>;823}824825/**826* A mix of public interface and internal one (used by internal rendering code, e.g., cellRenderer)827*/828export interface INotebookEditorDelegate extends INotebookEditor {829hasModel(): this is IActiveNotebookEditorDelegate;830831readonly creationOptions: INotebookEditorCreationOptions;832readonly onDidChangeOptions: Event<void>;833readonly onDidChangeDecorations: Event<void>;834createMarkupPreview(cell: ICellViewModel): Promise<void>;835unhideMarkupPreviews(cells: readonly ICellViewModel[]): Promise<void>;836hideMarkupPreviews(cells: readonly ICellViewModel[]): Promise<void>;837838/**839* Remove the output from the webview layer840*/841removeInset(output: IDisplayOutputViewModel): void;842843/**844* Hide the inset in the webview layer without removing it845*/846hideInset(output: IDisplayOutputViewModel): void;847deltaCellContainerClassNames(cellId: string, added: string[], removed: string[], cellKind: CellKind): void;848}849850export interface IActiveNotebookEditorDelegate extends INotebookEditorDelegate {851getViewModel(): INotebookViewModel;852textModel: NotebookTextModel;853getFocus(): ICellRange;854cellAt(index: number): ICellViewModel;855getCellIndex(cell: ICellViewModel): number;856getNextVisibleCellIndex(index: number): number;857}858859export interface ISearchPreviewInfo {860line: string;861range: {862start: number;863end: number;864};865}866867export interface CellWebviewFindMatch {868readonly index: number;869readonly searchPreviewInfo?: ISearchPreviewInfo;870}871872export type CellContentFindMatch = FindMatch;873874export interface CellFindMatch {875cell: ICellViewModel;876contentMatches: CellContentFindMatch[];877}878879export interface CellFindMatchWithIndex {880cell: ICellViewModel;881index: number;882length: number;883getMatch(index: number): FindMatch | CellWebviewFindMatch;884contentMatches: FindMatch[];885webviewMatches: CellWebviewFindMatch[];886}887888export enum CellEditState {889/**890* Default state.891* For markup cells, this is the renderer version of the markup.892* For code cell, the browser focus should be on the container instead of the editor893*/894Preview,895896/**897* Editing mode. Source for markup or code is rendered in editors and the state will be persistent.898*/899Editing900}901902export enum CellFocusMode {903Container,904Editor,905Output,906ChatInput907}908909export enum CursorAtBoundary {910None,911Top,912Bottom,913Both914}915916export enum CursorAtLineBoundary {917None,918Start,919End,920Both921}922923export function getNotebookEditorFromEditorPane(editorPane?: IEditorPane): INotebookEditor | undefined {924if (!editorPane) {925return;926}927928if (editorPane.getId() === NOTEBOOK_EDITOR_ID) {929return editorPane.getControl() as INotebookEditor | undefined;930}931932if (editorPane.getId() === NOTEBOOK_DIFF_EDITOR_ID) {933return (editorPane.getControl() as INotebookTextDiffEditor).inlineNotebookEditor;934}935936const input = editorPane.input;937938const isCompositeNotebook = input && isCompositeNotebookEditorInput(input);939940if (isCompositeNotebook) {941return (editorPane.getControl() as { notebookEditor: INotebookEditor | undefined } | undefined)?.notebookEditor;942}943944return undefined;945}946947/**948* ranges: model selections949* this will convert model selections to view indexes first, and then include the hidden ranges in the list view950*/951export function expandCellRangesWithHiddenCells(editor: INotebookEditor, ranges: ICellRange[]) {952// assuming ranges are sorted and no overlap953const indexes = cellRangesToIndexes(ranges);954const modelRanges: ICellRange[] = [];955indexes.forEach(index => {956const viewCell = editor.cellAt(index);957958if (!viewCell) {959return;960}961962const viewIndex = editor.getViewIndexByModelIndex(index);963if (viewIndex < 0) {964return;965}966967const nextViewIndex = viewIndex + 1;968const range = editor.getCellRangeFromViewRange(viewIndex, nextViewIndex);969970if (range) {971modelRanges.push(range);972}973});974975return reduceCellRanges(modelRanges);976}977978export function cellRangeToViewCells(editor: IActiveNotebookEditor, ranges: ICellRange[]) {979const cells: ICellViewModel[] = [];980reduceCellRanges(ranges).forEach(range => {981cells.push(...editor.getCellsInRange(range));982});983984return cells;985}986987//#region Cell Folding988export const enum CellFoldingState {989None,990Expanded,991Collapsed992}993994export interface EditorFoldingStateDelegate {995getCellIndex(cell: ICellViewModel): number;996getFoldingState(index: number): CellFoldingState;997}998//#endregion99910001001