Path: blob/main/src/vs/workbench/contrib/notebook/browser/notebookBrowser.ts
5245 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;190readonly topMargin: number;191readonly bottomMargin: number;192readonly outlineWidth: number;193}194195export interface CellLayoutChangeEvent {196readonly font?: FontInfo;197readonly outerWidth?: number;198readonly commentHeight?: boolean;199}200201export interface CodeCellLayoutInfo extends CellLayoutInfo {202readonly estimatedHasHorizontalScrolling: boolean;203readonly outputContainerOffset: number;204readonly outputTotalHeight: number;205readonly outputShowMoreContainerHeight: number;206readonly outputShowMoreContainerOffset: number;207readonly codeIndicatorHeight: number;208readonly outputIndicatorHeight: number;209}210211export interface CodeCellLayoutChangeEvent extends CellLayoutChangeEvent {212readonly source?: string;213readonly chatHeight?: boolean;214readonly editorHeight?: boolean;215readonly outputHeight?: boolean;216readonly outputShowMoreContainerHeight?: number;217readonly totalHeight?: boolean;218}219220export interface MarkupCellLayoutInfo extends CellLayoutInfo {221readonly previewHeight: number;222readonly foldHintHeight: number;223}224225export enum CellLayoutContext {226Fold227}228229export interface MarkupCellLayoutChangeEvent extends CellLayoutChangeEvent {230readonly editorHeight?: number;231readonly previewHeight?: number;232totalHeight?: number;233readonly context?: CellLayoutContext;234}235236export interface ICommonCellViewModelLayoutChangeInfo {237readonly totalHeight?: boolean | number;238readonly outerWidth?: number;239readonly context?: CellLayoutContext;240}241export interface ICellViewModel extends IGenericCellViewModel {242readonly model: NotebookCellTextModel;243readonly id: string;244readonly textBuffer: IReadonlyTextBuffer;245readonly layoutInfo: CellLayoutInfo;246readonly onDidChangeLayout: Event<ICommonCellViewModelLayoutChangeInfo>;247readonly onDidChangeCellStatusBarItems: Event<void>;248readonly onCellDecorationsChanged: Event<{ added: INotebookCellDecorationOptions[]; removed: INotebookCellDecorationOptions[] }>;249readonly onDidChangeState: Event<CellViewModelStateChangeEvent>;250readonly onDidChangeEditorAttachState: Event<void>;251readonly editStateSource: string;252readonly editorAttached: boolean;253isInputCollapsed: boolean;254isOutputCollapsed: boolean;255dragging: boolean;256handle: number;257uri: URI;258language: string;259readonly mime: string;260cellKind: CellKind;261lineNumbers: 'on' | 'off' | 'inherit';262commentOptions: IEditorCommentsOptions;263chatHeight: number;264commentHeight: number;265focusMode: CellFocusMode;266focusedOutputId?: string | undefined;267outputIsHovered: boolean;268getText(): string;269getAlternativeId(): number;270getTextLength(): number;271getHeight(lineHeight: number): number;272metadata: NotebookCellMetadata;273internalMetadata: NotebookCellInternalMetadata;274textModel: ITextModel | undefined;275hasModel(): this is IEditableCellViewModel;276resolveTextModel(): Promise<ITextModel>;277getSelections(): Selection[];278setSelections(selections: Selection[]): void;279getSelectionsStartPosition(): IPosition[] | undefined;280getCellDecorations(): INotebookCellDecorationOptions[];281getCellStatusBarItems(): INotebookCellStatusBarItem[];282getEditState(): CellEditState;283updateEditState(state: CellEditState, source: string): void;284deltaModelDecorations(oldDecorations: readonly string[], newDecorations: readonly IModelDeltaDecoration[]): string[];285getCellDecorationRange(id: string): Range | null;286enableAutoLanguageDetection(): void;287}288289export interface IEditableCellViewModel extends ICellViewModel {290textModel: ITextModel;291}292293export interface INotebookEditorMouseEvent {294readonly event: MouseEvent;295readonly target: ICellViewModel;296}297298export interface INotebookEditorContribution {299/**300* Dispose this contribution.301*/302dispose(): void;303/**304* Store view state.305*/306saveViewState?(): unknown;307/**308* Restore view state.309*/310restoreViewState?(state: unknown): void;311}312313/**314* Vertical Lane in the overview ruler of the notebook editor.315*/316export enum NotebookOverviewRulerLane {317Left = 1,318Center = 2,319Right = 4,320Full = 7321}322323export interface INotebookCellDecorationOptions {324className?: string;325gutterClassName?: string;326outputClassName?: string;327topClassName?: string;328overviewRuler?: {329color: string;330modelRanges: IRange[];331includeOutput: boolean;332position: NotebookOverviewRulerLane;333};334}335336export interface INotebookViewZoneDecorationOptions {337overviewRuler?: {338color: string;339position: NotebookOverviewRulerLane;340};341}342343export interface INotebookDeltaCellDecoration {344readonly handle: number;345readonly options: INotebookCellDecorationOptions;346}347348export interface INotebookDeltaViewZoneDecoration {349readonly viewZoneId: string;350readonly options: INotebookViewZoneDecorationOptions;351}352353export function isNotebookCellDecoration(obj: unknown): obj is INotebookDeltaCellDecoration {354return !!obj && typeof (obj as INotebookDeltaCellDecoration).handle === 'number';355}356357export function isNotebookViewZoneDecoration(obj: unknown): obj is INotebookDeltaViewZoneDecoration {358return !!obj && typeof (obj as INotebookDeltaViewZoneDecoration).viewZoneId === 'string';359}360361export type INotebookDeltaDecoration = INotebookDeltaCellDecoration | INotebookDeltaViewZoneDecoration;362363export interface INotebookDeltaCellStatusBarItems {364readonly handle: number;365readonly items: readonly INotebookCellStatusBarItem[];366}367368export const enum CellRevealType {369Default = 1,370Top = 2,371Center = 3,372CenterIfOutsideViewport = 4,373NearTopIfOutsideViewport = 5,374FirstLineIfOutsideViewport = 6375}376377export enum CellRevealRangeType {378Default = 1,379Center = 2,380CenterIfOutsideViewport = 3,381}382383export interface INotebookEditorOptions extends ITextEditorOptions {384readonly cellOptions?: ITextResourceEditorInput;385readonly cellRevealType?: CellRevealType;386readonly cellSelections?: ICellRange[];387readonly isReadOnly?: boolean;388readonly viewState?: INotebookEditorViewState;389readonly indexedCellOptions?: { index: number; selection?: IRange };390readonly label?: string;391}392393export type INotebookEditorContributionCtor = IConstructorSignature<INotebookEditorContribution, [INotebookEditor]>;394395export interface INotebookEditorContributionDescription {396id: string;397ctor: INotebookEditorContributionCtor;398}399400export interface INotebookEditorCreationOptions {401readonly isReplHistory?: boolean;402readonly isReadOnly?: boolean;403readonly contributions?: INotebookEditorContributionDescription[];404readonly cellEditorContributions?: IEditorContributionDescription[];405readonly menuIds: {406notebookToolbar: MenuId;407cellTitleToolbar: MenuId;408cellDeleteToolbar: MenuId;409cellInsertToolbar: MenuId;410cellTopInsertToolbar: MenuId;411cellExecuteToolbar: MenuId;412cellExecutePrimary?: MenuId;413};414readonly options?: NotebookOptions;415readonly codeWindow?: CodeWindow;416}417418export interface INotebookWebviewMessage {419readonly message: unknown;420}421422//#region Notebook View Model423export interface INotebookEditorViewState {424editingCells: { [key: number]: boolean };425collapsedInputCells: { [key: number]: boolean };426collapsedOutputCells: { [key: number]: boolean };427cellLineNumberStates: { [key: number]: 'on' | 'off' };428editorViewStates: { [key: number]: editorCommon.ICodeEditorViewState | null };429hiddenFoldingRanges?: ICellRange[];430cellTotalHeights?: { [key: number]: number };431scrollPosition?: { left: number; top: number };432focus?: number;433editorFocused?: boolean;434contributionsState?: { [id: string]: unknown };435selectedKernelId?: string;436}437438export interface ICellModelDecorations {439readonly ownerId: number;440readonly decorations: readonly string[];441}442443export interface ICellModelDeltaDecorations {444readonly ownerId: number;445readonly decorations: readonly IModelDeltaDecoration[];446}447448export interface IModelDecorationsChangeAccessor {449deltaDecorations(oldDecorations: ICellModelDecorations[], newDecorations: ICellModelDeltaDecorations[]): ICellModelDecorations[];450}451452export interface INotebookViewZone {453/**454* Use 0 to place a view zone before the first cell455*/456afterModelPosition: number;457domNode: HTMLElement;458459heightInPx: number;460}461462export interface INotebookViewZoneChangeAccessor {463addZone(zone: INotebookViewZone): string;464removeZone(id: string): void;465layoutZone(id: string): void;466}467468export interface INotebookCellOverlay {469cell: ICellViewModel;470domNode: HTMLElement;471}472473export interface INotebookCellOverlayChangeAccessor {474addOverlay(overlay: INotebookCellOverlay): string;475removeOverlay(id: string): void;476layoutOverlay(id: string): void;477}478479export type NotebookViewCellsSplice = [480number /* start */,481number /* delete count */,482ICellViewModel[]483];484485export interface INotebookViewCellsUpdateEvent {486readonly synchronous: boolean;487readonly splices: readonly NotebookViewCellsSplice[];488}489490export interface INotebookViewModel {491notebookDocument: NotebookTextModel;492readonly viewCells: ICellViewModel[];493layoutInfo: NotebookLayoutInfo | null;494viewType: string;495readonly onDidChangeViewCells: Event<INotebookViewCellsUpdateEvent>;496readonly onDidChangeSelection: Event<string>;497readonly onDidFoldingStateChanged: Event<void>;498getNearestVisibleCellIndexUpwards(index: number): number;499getTrackedRange(id: string): ICellRange | null;500setTrackedRange(id: string | null, newRange: ICellRange | null, newStickiness: TrackedRangeStickiness): string | null;501getOverviewRulerDecorations(): INotebookDeltaViewZoneDecoration[];502getSelections(): ICellRange[];503getCellIndex(cell: ICellViewModel): number;504getMostRecentlyExecutedCell(): ICellViewModel | undefined;505deltaCellStatusBarItems(oldItems: string[], newItems: INotebookDeltaCellStatusBarItems[]): string[];506getFoldedLength(index: number): number;507getFoldingStartIndex(index: number): number;508replaceOne(cell: ICellViewModel, range: Range, text: string): Promise<void>;509replaceAll(matches: CellFindMatchWithIndex[], texts: string[]): Promise<void>;510}511//#endregion512513export interface INotebookEditor {514//#region Eventing515readonly onDidChangeCellState: Event<NotebookCellStateChangedEvent>;516readonly onDidChangeViewCells: Event<INotebookViewCellsUpdateEvent>;517readonly onDidChangeVisibleRanges: Event<void>;518readonly onDidChangeSelection: Event<void>;519readonly onDidChangeFocus: Event<void>;520/**521* An event emitted when the model of this editor has changed.522*/523readonly onDidChangeModel: Event<NotebookTextModel | undefined>;524readonly onDidAttachViewModel: Event<void>;525readonly onDidFocusWidget: Event<void>;526readonly onDidBlurWidget: Event<void>;527readonly onDidScroll: Event<void>;528readonly onDidChangeLayout: Event<void>;529readonly onDidChangeActiveCell: Event<void>;530readonly onDidChangeActiveEditor: Event<INotebookEditor>;531readonly onDidChangeActiveKernel: Event<void>;532readonly onMouseUp: Event<INotebookEditorMouseEvent>;533readonly onMouseDown: Event<INotebookEditorMouseEvent>;534//#endregion535536//#region readonly properties537readonly visibleRanges: ICellRange[];538readonly textModel?: NotebookTextModel;539readonly isVisible: boolean;540readonly isReadOnly: boolean;541readonly isReplHistory: boolean;542readonly notebookOptions: NotebookOptions;543readonly isDisposed: boolean;544readonly activeKernel: INotebookKernel | undefined;545readonly scrollTop: number;546readonly scrollBottom: number;547readonly scopedContextKeyService: IContextKeyService;548/**549* Required for Composite Editor check. The interface should not be changed.550*/551readonly activeCodeEditor: ICodeEditor | undefined;552readonly codeEditors: [ICellViewModel, ICodeEditor][];553readonly activeCellAndCodeEditor: [ICellViewModel, ICodeEditor] | undefined;554//#endregion555556getLength(): number;557getSelections(): ICellRange[];558setSelections(selections: ICellRange[]): void;559getFocus(): ICellRange;560setFocus(focus: ICellRange): void;561getId(): string;562563getViewModel(): INotebookViewModel | undefined;564hasModel(): this is IActiveNotebookEditor;565dispose(): void;566getDomNode(): HTMLElement;567getInnerWebview(): IWebviewElement | undefined;568getSelectionViewModels(): ICellViewModel[];569getEditorViewState(): INotebookEditorViewState;570restoreListViewState(viewState: INotebookEditorViewState | undefined): void;571572getBaseCellEditorOptions(language: string): IBaseCellEditorOptions;573574/**575* Focus the active cell in notebook cell list576*/577focus(): void;578579/**580* Focus the notebook cell list container581*/582focusContainer(clearSelection?: boolean): void;583584hasEditorFocus(): boolean;585hasWebviewFocus(): boolean;586587hasOutputTextSelection(): boolean;588setOptions(options: INotebookEditorOptions | undefined): Promise<void>;589590/**591* Select & focus cell592*/593focusElement(cell: ICellViewModel): void;594595/**596* Layout info for the notebook editor597*/598getLayoutInfo(): NotebookLayoutInfo;599600getVisibleRangesPlusViewportAboveAndBelow(): ICellRange[];601602/**603* Focus the container of a cell (the monaco editor inside is not focused).604*/605focusNotebookCell(cell: ICellViewModel, focus: 'editor' | 'container' | 'output', options?: IFocusNotebookCellOptions): Promise<void>;606607/**608* Execute the given notebook cells609*/610executeNotebookCells(cells?: Iterable<ICellViewModel>): Promise<void>;611612/**613* Cancel the given notebook cells614*/615cancelNotebookCells(cells?: Iterable<ICellViewModel>): Promise<void>;616617/**618* Get current active cell619*/620getActiveCell(): ICellViewModel | undefined;621622/**623* Layout the cell with a new height624*/625layoutNotebookCell(cell: ICellViewModel, height: number): Promise<void>;626627/**628* Render the output in webview layer629*/630createOutput(cell: ICellViewModel, output: IInsetRenderOutput, offset: number, createWhenIdle: boolean): Promise<void>;631632/**633* Update the output in webview layer with latest content. It will delegate to `createOutput` is the output is not rendered yet634*/635updateOutput(cell: ICellViewModel, output: IInsetRenderOutput, offset: number): Promise<void>;636637/**638* Copy the image in the specific cell output to the clipboard639*/640copyOutputImage(cellOutput: ICellOutputViewModel): Promise<void>;641/**642* Select the contents of the first focused output of the cell.643* Implementation of Ctrl+A for an output item.644*/645selectOutputContent(cell: ICellViewModel): void;646/**647* Select the active input element of the first focused output of the cell.648* Implementation of Ctrl+A for an input element in an output item.649*/650selectInputContents(cell: ICellViewModel): void;651652readonly onDidReceiveMessage: Event<INotebookWebviewMessage>;653654/**655* Send message to the webview for outputs.656*/657postMessage(message: any): void;658659/**660* Remove class name on the notebook editor root DOM node.661*/662addClassName(className: string): void;663664/**665* Remove class name on the notebook editor root DOM node.666*/667removeClassName(className: string): void;668669/**670* Set scrollTop value of the notebook editor.671*/672setScrollTop(scrollTop: number): void;673674/**675* The range will be revealed with as little scrolling as possible.676*/677revealCellRangeInView(range: ICellRange): void;678679/**680* Reveal cell into viewport.681*/682revealInView(cell: ICellViewModel): Promise<void>;683684/**685* Reveal cell into the top of viewport.686*/687revealInViewAtTop(cell: ICellViewModel): void;688689/**690* Reveal cell into viewport center.691*/692revealInCenter(cell: ICellViewModel): void;693694/**695* Reveal cell into viewport center if cell is currently out of the viewport.696*/697revealInCenterIfOutsideViewport(cell: ICellViewModel): Promise<void>;698699/**700* Reveal the first line of the cell into the view if the cell is outside of the viewport.701*/702revealFirstLineIfOutsideViewport(cell: ICellViewModel): Promise<void>;703704/**705* Reveal a line in notebook cell into viewport with minimal scrolling.706*/707revealLineInViewAsync(cell: ICellViewModel, line: number): Promise<void>;708709/**710* Reveal a line in notebook cell into viewport center.711*/712revealLineInCenterAsync(cell: ICellViewModel, line: number): Promise<void>;713714/**715* Reveal a line in notebook cell into viewport center.716*/717revealLineInCenterIfOutsideViewportAsync(cell: ICellViewModel, line: number): Promise<void>;718719/**720* Reveal a range in notebook cell into viewport with minimal scrolling.721*/722revealRangeInViewAsync(cell: ICellViewModel, range: Selection | Range): Promise<void>;723724/**725* Reveal a range in notebook cell into viewport center.726*/727revealRangeInCenterAsync(cell: ICellViewModel, range: Selection | Range): Promise<void>;728729/**730* Reveal a range in notebook cell into viewport center.731*/732revealRangeInCenterIfOutsideViewportAsync(cell: ICellViewModel, range: Selection | Range): Promise<void>;733734/**735* Reveal a position with `offset` in a cell into viewport center.736*/737revealCellOffsetInCenter(cell: ICellViewModel, offset: number): void;738739/**740* Reveal `offset` in the list view into viewport center if it is outside of the viewport.741*/742revealOffsetInCenterIfOutsideViewport(offset: number): void;743744/**745* Convert the view range to model range746* @param startIndex Inclusive747* @param endIndex Exclusive748*/749getCellRangeFromViewRange(startIndex: number, endIndex: number): ICellRange | undefined;750751/**752* Set hidden areas on cell text models.753*/754setHiddenAreas(_ranges: ICellRange[]): boolean;755756/**757* Set selectiosn on the text editor attached to the cell758*/759760setCellEditorSelection(cell: ICellViewModel, selection: Range): void;761762/**763*Change the decorations on the notebook cell list764*/765766deltaCellDecorations(oldDecorations: string[], newDecorations: INotebookDeltaDecoration[]): string[];767768/**769* Change the decorations on cell editors.770* The notebook is virtualized and this method should be called to create/delete editor decorations safely.771*/772changeModelDecorations<T>(callback: (changeAccessor: IModelDecorationsChangeAccessor) => T): T | null;773774changeViewZones(callback: (accessor: INotebookViewZoneChangeAccessor) => void): void;775776changeCellOverlays(callback: (accessor: INotebookCellOverlayChangeAccessor) => void): void;777778getViewZoneLayoutInfo(id: string): { top: number; height: number } | null;779780/**781* Get a contribution of this editor.782* @id Unique identifier of the contribution.783* @return The contribution or null if contribution not found.784*/785getContribution<T extends INotebookEditorContribution>(id: string): T;786787/**788* Get the view index of a cell at model `index`789*/790getViewIndexByModelIndex(index: number): number;791getCellsInRange(range?: ICellRange): ReadonlyArray<ICellViewModel>;792cellAt(index: number): ICellViewModel | undefined;793getCellByHandle(handle: number): ICellViewModel | undefined;794getCellIndex(cell: ICellViewModel): number | undefined;795getNextVisibleCellIndex(index: number): number | undefined;796getPreviousVisibleCellIndex(index: number): number | undefined;797find(query: string, options: INotebookFindOptions, token: CancellationToken, skipWarmup?: boolean, shouldGetSearchPreviewInfo?: boolean, ownerID?: string): Promise<CellFindMatchWithIndex[]>;798findHighlightCurrent(matchIndex: number, ownerID?: string): Promise<number>;799findUnHighlightCurrent(matchIndex: number, ownerID?: string): Promise<void>;800findStop(ownerID?: string): void;801showProgress(): void;802hideProgress(): void;803804getAbsoluteTopOfElement(cell: ICellViewModel): number;805getAbsoluteBottomOfElement(cell: ICellViewModel): number;806getHeightOfElement(cell: ICellViewModel): number;807}808809export interface IActiveNotebookEditor extends INotebookEditor {810getViewModel(): INotebookViewModel;811textModel: NotebookTextModel;812getFocus(): ICellRange;813cellAt(index: number): ICellViewModel;814getCellIndex(cell: ICellViewModel): number;815getNextVisibleCellIndex(index: number): number;816}817818export interface INotebookEditorPane extends IEditorPaneWithSelection {819getControl(): INotebookEditor | undefined;820readonly onDidChangeModel: Event<void>;821textModel: NotebookTextModel | undefined;822}823824export interface IBaseCellEditorOptions extends IDisposable {825readonly value: IEditorOptions;826readonly onDidChange: Event<void>;827}828829/**830* A mix of public interface and internal one (used by internal rendering code, e.g., cellRenderer)831*/832export interface INotebookEditorDelegate extends INotebookEditor {833hasModel(): this is IActiveNotebookEditorDelegate;834835readonly creationOptions: INotebookEditorCreationOptions;836readonly onDidChangeOptions: Event<void>;837readonly onDidChangeDecorations: Event<void>;838createMarkupPreview(cell: ICellViewModel): Promise<void>;839unhideMarkupPreviews(cells: readonly ICellViewModel[]): Promise<void>;840hideMarkupPreviews(cells: readonly ICellViewModel[]): Promise<void>;841842/**843* Remove the output from the webview layer844*/845removeInset(output: IDisplayOutputViewModel): void;846847/**848* Hide the inset in the webview layer without removing it849*/850hideInset(output: IDisplayOutputViewModel): void;851deltaCellContainerClassNames(cellId: string, added: string[], removed: string[], cellKind: CellKind): void;852}853854export interface IActiveNotebookEditorDelegate extends INotebookEditorDelegate {855getViewModel(): INotebookViewModel;856textModel: NotebookTextModel;857getFocus(): ICellRange;858cellAt(index: number): ICellViewModel;859getCellIndex(cell: ICellViewModel): number;860getNextVisibleCellIndex(index: number): number;861}862863export interface ISearchPreviewInfo {864line: string;865range: {866start: number;867end: number;868};869}870871export interface CellWebviewFindMatch {872readonly index: number;873readonly searchPreviewInfo?: ISearchPreviewInfo;874}875876export type CellContentFindMatch = FindMatch;877878export interface CellFindMatch {879cell: ICellViewModel;880contentMatches: CellContentFindMatch[];881}882883export interface CellFindMatchWithIndex {884cell: ICellViewModel;885index: number;886length: number;887getMatch(index: number): FindMatch | CellWebviewFindMatch;888contentMatches: FindMatch[];889webviewMatches: CellWebviewFindMatch[];890}891892export enum CellEditState {893/**894* Default state.895* For markup cells, this is the renderer version of the markup.896* For code cell, the browser focus should be on the container instead of the editor897*/898Preview,899900/**901* Editing mode. Source for markup or code is rendered in editors and the state will be persistent.902*/903Editing904}905906export enum CellFocusMode {907Container,908Editor,909Output,910ChatInput911}912913export enum CursorAtBoundary {914None,915Top,916Bottom,917Both918}919920export enum CursorAtLineBoundary {921None,922Start,923End,924Both925}926927export function getNotebookEditorFromEditorPane(editorPane?: IEditorPane): INotebookEditor | undefined {928if (!editorPane) {929return;930}931932if (editorPane.getId() === NOTEBOOK_EDITOR_ID) {933return editorPane.getControl() as INotebookEditor | undefined;934}935936if (editorPane.getId() === NOTEBOOK_DIFF_EDITOR_ID) {937return (editorPane.getControl() as INotebookTextDiffEditor).inlineNotebookEditor;938}939940const input = editorPane.input;941942const isCompositeNotebook = input && isCompositeNotebookEditorInput(input);943944if (isCompositeNotebook) {945return (editorPane.getControl() as { notebookEditor: INotebookEditor | undefined } | undefined)?.notebookEditor;946}947948return undefined;949}950951/**952* ranges: model selections953* this will convert model selections to view indexes first, and then include the hidden ranges in the list view954*/955export function expandCellRangesWithHiddenCells(editor: INotebookEditor, ranges: ICellRange[]) {956// assuming ranges are sorted and no overlap957const indexes = cellRangesToIndexes(ranges);958const modelRanges: ICellRange[] = [];959indexes.forEach(index => {960const viewCell = editor.cellAt(index);961962if (!viewCell) {963return;964}965966const viewIndex = editor.getViewIndexByModelIndex(index);967if (viewIndex < 0) {968return;969}970971const nextViewIndex = viewIndex + 1;972const range = editor.getCellRangeFromViewRange(viewIndex, nextViewIndex);973974if (range) {975modelRanges.push(range);976}977});978979return reduceCellRanges(modelRanges);980}981982export function cellRangeToViewCells(editor: IActiveNotebookEditor, ranges: ICellRange[]) {983const cells: ICellViewModel[] = [];984reduceCellRanges(ranges).forEach(range => {985cells.push(...editor.getCellsInRange(range));986});987988return cells;989}990991//#region Cell Folding992export const enum CellFoldingState {993None,994Expanded,995Collapsed996}997998export interface EditorFoldingStateDelegate {999getCellIndex(cell: ICellViewModel): number;1000getFoldingState(index: number): CellFoldingState;1001}1002//#endregion100310041005