/*---------------------------------------------------------------------------------------------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 { Event } from '../../base/common/event.js';6import { IMarkdownString } from '../../base/common/htmlContent.js';7import { IDisposable } from '../../base/common/lifecycle.js';8import { ThemeColor } from '../../base/common/themables.js';9import { URI, UriComponents } from '../../base/common/uri.js';10import { IEditorOptions } from './config/editorOptions.js';11import { IDimension } from './core/2d/dimension.js';12import { IPosition, Position } from './core/position.js';13import { IRange, Range } from './core/range.js';14import { ISelection, Selection } from './core/selection.js';15import { IModelDecoration, IModelDecorationsChangeAccessor, IModelDeltaDecoration, ITextModel, IValidEditOperation, OverviewRulerLane, TrackedRangeStickiness } from './model.js';16import { IModelDecorationsChangedEvent } from './textModelEvents.js';17import { ICommandMetadata } from '../../platform/commands/common/commands.js';1819/**20* A builder and helper for edit operations for a command.21*/22export interface IEditOperationBuilder {23/**24* Add a new edit operation (a replace operation).25* @param range The range to replace (delete). May be empty to represent a simple insert.26* @param text The text to replace with. May be null to represent a simple delete.27*/28addEditOperation(range: IRange, text: string | null, forceMoveMarkers?: boolean): void;2930/**31* Add a new edit operation (a replace operation).32* The inverse edits will be accessible in `ICursorStateComputerData.getInverseEditOperations()`33* @param range The range to replace (delete). May be empty to represent a simple insert.34* @param text The text to replace with. May be null to represent a simple delete.35*/36addTrackedEditOperation(range: IRange, text: string | null, forceMoveMarkers?: boolean): void;3738/**39* Track `selection` when applying edit operations.40* A best effort will be made to not grow/expand the selection.41* An empty selection will clamp to a nearby character.42* @param selection The selection to track.43* @param trackPreviousOnEmpty If set, and the selection is empty, indicates whether the selection44* should clamp to the previous or the next character.45* @return A unique identifier.46*/47trackSelection(selection: Selection, trackPreviousOnEmpty?: boolean): string;48}4950/**51* A helper for computing cursor state after a command.52*/53export interface ICursorStateComputerData {54/**55* Get the inverse edit operations of the added edit operations.56*/57getInverseEditOperations(): IValidEditOperation[];58/**59* Get a previously tracked selection.60* @param id The unique identifier returned by `trackSelection`.61* @return The selection.62*/63getTrackedSelection(id: string): Selection;64}6566/**67* A command that modifies text / cursor state on a model.68*/69export interface ICommand {7071/**72* Signal that this command is inserting automatic whitespace that should be trimmed if possible.73* @internal74*/75readonly insertsAutoWhitespace?: boolean;7677/**78* Get the edit operations needed to execute this command.79* @param model The model the command will execute on.80* @param builder A helper to collect the needed edit operations and to track selections.81*/82getEditOperations(model: ITextModel, builder: IEditOperationBuilder): void;8384/**85* Compute the cursor state after the edit operations were applied.86* @param model The model the command has executed on.87* @param helper A helper to get inverse edit operations and to get previously tracked selections.88* @return The cursor state after the command executed.89*/90computeCursorState(model: ITextModel, helper: ICursorStateComputerData): Selection;91}9293/**94* A model for the diff editor.95*/96export interface IDiffEditorModel {97/**98* Original model.99*/100original: ITextModel;101/**102* Modified model.103*/104modified: ITextModel;105}106107export interface IDiffEditorViewModel extends IDisposable {108readonly model: IDiffEditorModel;109110waitForDiff(): Promise<void>;111}112113/**114* An event describing that an editor has had its model reset (i.e. `editor.setModel()`).115*/116export interface IModelChangedEvent {117/**118* The `uri` of the previous model or null.119*/120readonly oldModelUrl: URI | null;121/**122* The `uri` of the new model or null.123*/124readonly newModelUrl: URI | null;125}126127// --- view128129export interface IScrollEvent {130readonly scrollTop: number;131readonly scrollLeft: number;132readonly scrollWidth: number;133readonly scrollHeight: number;134135readonly scrollTopChanged: boolean;136readonly scrollLeftChanged: boolean;137readonly scrollWidthChanged: boolean;138readonly scrollHeightChanged: boolean;139}140141export interface IContentSizeChangedEvent {142readonly contentWidth: number;143readonly contentHeight: number;144145readonly contentWidthChanged: boolean;146readonly contentHeightChanged: boolean;147}148149/**150* @internal151*/152export interface ITriggerEditorOperationEvent {153source: string | null | undefined;154handlerId: string;155payload: unknown;156}157158export interface INewScrollPosition {159scrollLeft?: number;160scrollTop?: number;161}162163export interface IEditorAction {164readonly id: string;165readonly label: string;166readonly alias: string;167readonly metadata: ICommandMetadata | undefined;168isSupported(): boolean;169run(args?: unknown): Promise<void>;170}171172export type IEditorModel = ITextModel | IDiffEditorModel | IDiffEditorViewModel;173174/**175* A (serializable) state of the cursors.176*/177export interface ICursorState {178inSelectionMode: boolean;179selectionStart: IPosition;180position: IPosition;181}182/**183* A (serializable) state of the view.184*/185export interface IViewState {186/** written by previous versions */187scrollTop?: number;188/** written by previous versions */189scrollTopWithoutViewZones?: number;190scrollLeft: number;191firstPosition: IPosition;192firstPositionDeltaTop: number;193}194/**195* A (serializable) state of the code editor.196*/197export interface ICodeEditorViewState {198cursorState: ICursorState[];199viewState: IViewState;200contributionsState: { [id: string]: any };201}202/**203* (Serializable) View state for the diff editor.204*/205export interface IDiffEditorViewState {206original: ICodeEditorViewState | null;207modified: ICodeEditorViewState | null;208modelState?: unknown;209}210/**211* An editor view state.212*/213export type IEditorViewState = ICodeEditorViewState | IDiffEditorViewState;214215export const enum ScrollType {216Smooth = 0,217Immediate = 1,218}219220/**221* An editor.222*/223export interface IEditor {224/**225* An event emitted when the editor has been disposed.226* @event227*/228onDidDispose(listener: () => void): IDisposable;229230/**231* Dispose the editor.232*/233dispose(): void;234235/**236* Get a unique id for this editor instance.237*/238getId(): string;239240/**241* Get the editor type. Please see `EditorType`.242* This is to avoid an instanceof check243*/244getEditorType(): string;245246/**247* Update the editor's options after the editor has been created.248*/249updateOptions(newOptions: IEditorOptions): void;250251/**252* Indicates that the editor becomes visible.253* @internal254*/255onVisible(): void;256257/**258* Indicates that the editor becomes hidden.259* @internal260*/261onHide(): void;262263/**264* Instructs the editor to remeasure its container. This method should265* be called when the container of the editor gets resized.266*267* If a dimension is passed in, the passed in value will be used.268*269* By default, this will also render the editor immediately.270* If you prefer to delay rendering to the next animation frame, use postponeRendering == true.271*/272layout(dimension?: IDimension, postponeRendering?: boolean): void;273274/**275* Brings browser focus to the editor text276*/277focus(): void;278279/**280* Returns true if the text inside this editor is focused (i.e. cursor is blinking).281*/282hasTextFocus(): boolean;283284/**285* Returns all actions associated with this editor.286*/287getSupportedActions(): IEditorAction[];288289/**290* Saves current view state of the editor in a serializable object.291*/292saveViewState(): IEditorViewState | null;293294/**295* Restores the view state of the editor from a serializable object generated by `saveViewState`.296*/297restoreViewState(state: IEditorViewState | null): void;298299/**300* Given a position, returns a column number that takes tab-widths into account.301*/302getVisibleColumnFromPosition(position: IPosition): number;303304/**305* Given a position, returns a column number that takes tab-widths into account.306* @internal307*/308getStatusbarColumn(position: IPosition): number;309310/**311* Returns the primary position of the cursor.312*/313getPosition(): Position | null;314315/**316* Set the primary position of the cursor. This will remove any secondary cursors.317* @param position New primary cursor's position318* @param source Source of the call that caused the position319*/320setPosition(position: IPosition, source?: string): void;321322/**323* Scroll vertically as necessary and reveal a line.324*/325revealLine(lineNumber: number, scrollType?: ScrollType): void;326327/**328* Scroll vertically as necessary and reveal a line centered vertically.329*/330revealLineInCenter(lineNumber: number, scrollType?: ScrollType): void;331332/**333* Scroll vertically as necessary and reveal a line centered vertically only if it lies outside the viewport.334*/335revealLineInCenterIfOutsideViewport(lineNumber: number, scrollType?: ScrollType): void;336337/**338* Scroll vertically as necessary and reveal a line close to the top of the viewport,339* optimized for viewing a code definition.340*/341revealLineNearTop(lineNumber: number, scrollType?: ScrollType): void;342343/**344* Scroll vertically or horizontally as necessary and reveal a position.345*/346revealPosition(position: IPosition, scrollType?: ScrollType): void;347348/**349* Scroll vertically or horizontally as necessary and reveal a position centered vertically.350*/351revealPositionInCenter(position: IPosition, scrollType?: ScrollType): void;352353/**354* Scroll vertically or horizontally as necessary and reveal a position centered vertically only if it lies outside the viewport.355*/356revealPositionInCenterIfOutsideViewport(position: IPosition, scrollType?: ScrollType): void;357358/**359* Scroll vertically or horizontally as necessary and reveal a position close to the top of the viewport,360* optimized for viewing a code definition.361*/362revealPositionNearTop(position: IPosition, scrollType?: ScrollType): void;363364/**365* Returns the primary selection of the editor.366*/367getSelection(): Selection | null;368369/**370* Returns all the selections of the editor.371*/372getSelections(): Selection[] | null;373374/**375* Set the primary selection of the editor. This will remove any secondary cursors.376* @param selection The new selection377* @param source Source of the call that caused the selection378*/379setSelection(selection: IRange, source?: string): void;380/**381* Set the primary selection of the editor. This will remove any secondary cursors.382* @param selection The new selection383* @param source Source of the call that caused the selection384*/385setSelection(selection: Range, source?: string): void;386/**387* Set the primary selection of the editor. This will remove any secondary cursors.388* @param selection The new selection389* @param source Source of the call that caused the selection390*/391setSelection(selection: ISelection, source?: string): void;392/**393* Set the primary selection of the editor. This will remove any secondary cursors.394* @param selection The new selection395* @param source Source of the call that caused the selection396*/397setSelection(selection: Selection, source?: string): void;398399/**400* Set the selections for all the cursors of the editor.401* Cursors will be removed or added, as necessary.402* @param selections The new selection403* @param source Source of the call that caused the selection404*/405setSelections(selections: readonly ISelection[], source?: string): void;406407/**408* Scroll vertically as necessary and reveal lines.409*/410revealLines(startLineNumber: number, endLineNumber: number, scrollType?: ScrollType): void;411412/**413* Scroll vertically as necessary and reveal lines centered vertically.414*/415revealLinesInCenter(lineNumber: number, endLineNumber: number, scrollType?: ScrollType): void;416417/**418* Scroll vertically as necessary and reveal lines centered vertically only if it lies outside the viewport.419*/420revealLinesInCenterIfOutsideViewport(lineNumber: number, endLineNumber: number, scrollType?: ScrollType): void;421422/**423* Scroll vertically as necessary and reveal lines close to the top of the viewport,424* optimized for viewing a code definition.425*/426revealLinesNearTop(lineNumber: number, endLineNumber: number, scrollType?: ScrollType): void;427428/**429* Scroll vertically or horizontally as necessary and reveal a range.430*/431revealRange(range: IRange, scrollType?: ScrollType): void;432433/**434* Scroll vertically or horizontally as necessary and reveal a range centered vertically.435*/436revealRangeInCenter(range: IRange, scrollType?: ScrollType): void;437438/**439* Scroll vertically or horizontally as necessary and reveal a range at the top of the viewport.440*/441revealRangeAtTop(range: IRange, scrollType?: ScrollType): void;442443/**444* Scroll vertically or horizontally as necessary and reveal a range centered vertically only if it lies outside the viewport.445*/446revealRangeInCenterIfOutsideViewport(range: IRange, scrollType?: ScrollType): void;447448/**449* Scroll vertically or horizontally as necessary and reveal a range close to the top of the viewport,450* optimized for viewing a code definition.451*/452revealRangeNearTop(range: IRange, scrollType?: ScrollType): void;453454/**455* Scroll vertically or horizontally as necessary and reveal a range close to the top of the viewport,456* optimized for viewing a code definition. Only if it lies outside the viewport.457*/458revealRangeNearTopIfOutsideViewport(range: IRange, scrollType?: ScrollType): void;459460/**461* Directly trigger a handler or an editor action.462* @param source The source of the call.463* @param handlerId The id of the handler or the id of a contribution.464* @param payload Extra data to be sent to the handler.465*/466trigger(source: string | null | undefined, handlerId: string, payload: any): void;467468/**469* Gets the current model attached to this editor.470*/471getModel(): IEditorModel | null;472473/**474* Sets the current model attached to this editor.475* If the previous model was created by the editor via the value key in the options476* literal object, it will be destroyed. Otherwise, if the previous model was set477* via setModel, or the model key in the options literal object, the previous model478* will not be destroyed.479* It is safe to call setModel(null) to simply detach the current model from the editor.480*/481setModel(model: IEditorModel | null): void;482483/**484* Create a collection of decorations. All decorations added through this collection485* will get the ownerId of the editor (meaning they will not show up in other editors).486* These decorations will be automatically cleared when the editor's model changes.487*/488createDecorationsCollection(decorations?: IModelDeltaDecoration[]): IEditorDecorationsCollection;489490/**491* Change the decorations. All decorations added through this changeAccessor492* will get the ownerId of the editor (meaning they will not show up in other493* editors).494* @see {@link ITextModel.changeDecorations}495* @internal496*/497changeDecorations(callback: (changeAccessor: IModelDecorationsChangeAccessor) => any): any;498}499500/**501* A diff editor.502*503* @internal504*/505export interface IDiffEditor extends IEditor {506507/**508* Type the getModel() of IEditor.509*/510getModel(): IDiffEditorModel | null;511512/**513* Get the `original` editor.514*/515getOriginalEditor(): IEditor;516517/**518* Get the `modified` editor.519*/520getModifiedEditor(): IEditor;521}522523/**524* @internal525*/526export interface ICompositeCodeEditor {527528/**529* An event that signals that the active editor has changed530*/531readonly onDidChangeActiveEditor: Event<ICompositeCodeEditor>;532533/**534* The active code editor iff any535*/536readonly activeCodeEditor: IEditor | undefined;537// readonly editors: readonly ICodeEditor[] maybe supported with uris538}539540/**541* A collection of decorations542*/543export interface IEditorDecorationsCollection {544/**545* An event emitted when decorations change in the editor,546* but the change is not caused by us setting or clearing the collection.547*/548onDidChange: Event<IModelDecorationsChangedEvent>;549/**550* Get the decorations count.551*/552length: number;553/**554* Get the range for a decoration.555*/556getRange(index: number): Range | null;557/**558* Get all ranges for decorations.559*/560getRanges(): Range[];561/**562* Determine if a decoration is in this collection.563*/564has(decoration: IModelDecoration): boolean;565/**566* Replace all previous decorations with `newDecorations`.567*/568set(newDecorations: readonly IModelDeltaDecoration[]): string[];569/**570* Append `newDecorations` to this collection.571*/572append(newDecorations: readonly IModelDeltaDecoration[]): string[];573/**574* Remove all previous decorations.575*/576clear(): void;577}578579/**580* An editor contribution that gets created every time a new editor gets created and gets disposed when the editor gets disposed.581*/582export interface IEditorContribution {583/**584* Dispose this contribution.585*/586dispose(): void;587/**588* Store view state.589*/590saveViewState?(): any;591/**592* Restore view state.593*/594restoreViewState?(state: any): void;595}596597/**598* A diff editor contribution that gets created every time a new diffeditor gets created and gets disposed when the diff editor gets disposed.599* @internal600*/601export interface IDiffEditorContribution {602/**603* Dispose this contribution.604*/605dispose(): void;606}607608/**609* @internal610*/611export function isThemeColor(o: any): o is ThemeColor {612return o && typeof o.id === 'string';613}614615/**616* @internal617*/618export interface IThemeDecorationRenderOptions {619backgroundColor?: string | ThemeColor;620621outline?: string;622outlineColor?: string | ThemeColor;623outlineStyle?: string;624outlineWidth?: string;625626border?: string;627borderColor?: string | ThemeColor;628borderRadius?: string;629borderSpacing?: string;630borderStyle?: string;631borderWidth?: string;632633fontStyle?: string;634fontWeight?: string;635fontFamily?: string;636fontSize?: string;637lineHeight?: number;638textDecoration?: string;639cursor?: string;640color?: string | ThemeColor;641opacity?: string;642letterSpacing?: string;643644gutterIconPath?: UriComponents;645gutterIconSize?: string;646647overviewRulerColor?: string | ThemeColor;648649/**650* @deprecated651*/652before?: IContentDecorationRenderOptions;653/**654* @deprecated655*/656after?: IContentDecorationRenderOptions;657658/**659* @deprecated660*/661beforeInjectedText?: IContentDecorationRenderOptions & { affectsLetterSpacing?: boolean };662/**663* @deprecated664*/665afterInjectedText?: IContentDecorationRenderOptions & { affectsLetterSpacing?: boolean };666}667668/**669* @internal670*/671export interface IContentDecorationRenderOptions {672contentText?: string;673contentIconPath?: UriComponents;674675border?: string;676borderColor?: string | ThemeColor;677borderRadius?: string;678fontStyle?: string;679fontWeight?: string;680fontSize?: string;681fontFamily?: string;682textDecoration?: string;683color?: string | ThemeColor;684backgroundColor?: string | ThemeColor;685opacity?: string;686verticalAlign?: string;687688margin?: string;689padding?: string;690width?: string;691height?: string;692}693694/**695* @internal696*/697export interface IDecorationRenderOptions extends IThemeDecorationRenderOptions {698isWholeLine?: boolean;699rangeBehavior?: TrackedRangeStickiness;700overviewRulerLane?: OverviewRulerLane;701702light?: IThemeDecorationRenderOptions;703dark?: IThemeDecorationRenderOptions;704}705706/**707* @internal708*/709export interface IThemeDecorationInstanceRenderOptions {710/**711* @deprecated712*/713before?: IContentDecorationRenderOptions;714/**715* @deprecated716*/717after?: IContentDecorationRenderOptions;718}719720/**721* @internal722*/723export interface IDecorationInstanceRenderOptions extends IThemeDecorationInstanceRenderOptions {724light?: IThemeDecorationInstanceRenderOptions;725dark?: IThemeDecorationInstanceRenderOptions;726}727728/**729* @internal730*/731export interface IDecorationOptions {732range: IRange;733hoverMessage?: IMarkdownString | IMarkdownString[];734renderOptions?: IDecorationInstanceRenderOptions;735}736737/**738* The type of the `IEditor`.739*/740export const EditorType = {741ICodeEditor: 'vs.editor.ICodeEditor',742IDiffEditor: 'vs.editor.IDiffEditor'743};744745/**746* Built-in commands.747* @internal748*/749export const enum Handler {750CompositionStart = 'compositionStart',751CompositionEnd = 'compositionEnd',752Type = 'type',753ReplacePreviousChar = 'replacePreviousChar',754CompositionType = 'compositionType',755Paste = 'paste',756Cut = 'cut',757}758759/**760* @internal761*/762export interface TypePayload {763text: string;764}765766/**767* @internal768*/769export interface ReplacePreviousCharPayload {770text: string;771replaceCharCnt: number;772}773774/**775* @internal776*/777export interface CompositionTypePayload {778text: string;779replacePrevCharCnt: number;780replaceNextCharCnt: number;781positionDelta: number;782}783784785