Path: blob/main/src/vs/editor/browser/editorBrowser.ts
3292 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 { IKeyboardEvent } from '../../base/browser/keyboardEvent.js';6import { IMouseEvent, IMouseWheelEvent } from '../../base/browser/mouseEvent.js';7import { IBoundarySashes } from '../../base/browser/ui/sash/sash.js';8import { Event } from '../../base/common/event.js';9import { IEditorConstructionOptions } from './config/editorConfiguration.js';10import { ConfigurationChangedEvent, EditorLayoutInfo, EditorOption, FindComputedEditorOptionValueById, IComputedEditorOptions, IDiffEditorOptions, IEditorOptions, OverviewRulerPosition } from '../common/config/editorOptions.js';11import { IDimension } from '../common/core/2d/dimension.js';12import { IPosition, Position } from '../common/core/position.js';13import { IRange, Range } from '../common/core/range.js';14import { Selection } from '../common/core/selection.js';15import { IWordAtPosition } from '../common/core/wordHelper.js';16import { ICursorPositionChangedEvent, ICursorSelectionChangedEvent } from '../common/cursorEvents.js';17import { IDiffComputationResult, ILineChange } from '../common/diff/legacyLinesDiffComputer.js';18import * as editorCommon from '../common/editorCommon.js';19import { GlyphMarginLane, ICursorStateComputer, IIdentifiedSingleEditOperation, IModelDecoration, IModelDeltaDecoration, ITextModel, PositionAffinity } from '../common/model.js';20import { InjectedText } from '../common/modelLineProjectionData.js';21import { IModelContentChangedEvent, IModelDecorationsChangedEvent, IModelLanguageChangedEvent, IModelLanguageConfigurationChangedEvent, IModelOptionsChangedEvent, IModelTokensChangedEvent, ModelFontChangedEvent, ModelLineHeightChangedEvent } from '../common/textModelEvents.js';22import { IEditorWhitespace, IViewModel } from '../common/viewModel.js';23import { OverviewRulerZone } from '../common/viewModel/overviewZoneManager.js';24import { MenuId } from '../../platform/actions/common/actions.js';25import { IContextKeyService } from '../../platform/contextkey/common/contextkey.js';26import { ServicesAccessor } from '../../platform/instantiation/common/instantiation.js';27import { TextEdit } from '../common/core/edits/textEdit.js';28import { TextModelEditSource } from '../common/textModelEditSource.js';2930/**31* A view zone is a full horizontal rectangle that 'pushes' text down.32* The editor reserves space for view zones when rendering.33*/34export interface IViewZone {35/**36* The line number after which this zone should appear.37* Use 0 to place a view zone before the first line number.38*/39afterLineNumber: number;40/**41* The column after which this zone should appear.42* If not set, the maxLineColumn of `afterLineNumber` will be used.43* This is relevant for wrapped lines.44*/45afterColumn?: number;46/**47* If the `afterColumn` has multiple view columns, the affinity specifies which one to use. Defaults to `none`.48*/49afterColumnAffinity?: PositionAffinity;50/**51* Render the zone even when its line is hidden.52*/53showInHiddenAreas?: boolean;54/**55* Tiebreaker that is used when multiple view zones want to be after the same line.56* Defaults to `afterColumn` otherwise 10000;57*/58ordinal?: number;59/**60* Suppress mouse down events.61* If set, the editor will attach a mouse down listener to the view zone and .preventDefault on it.62* Defaults to false63*/64suppressMouseDown?: boolean;65/**66* The height in lines of the view zone.67* If specified, `heightInPx` will be used instead of this.68* If neither `heightInPx` nor `heightInLines` is specified, a default of `heightInLines` = 1 will be chosen.69*/70heightInLines?: number;71/**72* The height in px of the view zone.73* If this is set, the editor will give preference to it rather than `heightInLines` above.74* If neither `heightInPx` nor `heightInLines` is specified, a default of `heightInLines` = 1 will be chosen.75*/76heightInPx?: number;77/**78* The minimum width in px of the view zone.79* If this is set, the editor will ensure that the scroll width is >= than this value.80*/81minWidthInPx?: number;82/**83* The dom node of the view zone84*/85domNode: HTMLElement;86/**87* An optional dom node for the view zone that will be placed in the margin area.88*/89marginDomNode?: HTMLElement | null;90/**91* Callback which gives the relative top of the view zone as it appears (taking scrolling into account).92*/93onDomNodeTop?: (top: number) => void;94/**95* Callback which gives the height in pixels of the view zone.96*/97onComputedHeight?: (height: number) => void;98}99/**100* An accessor that allows for zones to be added or removed.101*/102export interface IViewZoneChangeAccessor {103/**104* Create a new view zone.105* @param zone Zone to create106* @return A unique identifier to the view zone.107*/108addZone(zone: IViewZone): string;109/**110* Remove a zone111* @param id A unique identifier to the view zone, as returned by the `addZone` call.112*/113removeZone(id: string): void;114/**115* Change a zone's position.116* The editor will rescan the `afterLineNumber` and `afterColumn` properties of a view zone.117*/118layoutZone(id: string): void;119}120121/**122* A positioning preference for rendering content widgets.123*/124export const enum ContentWidgetPositionPreference {125/**126* Place the content widget exactly at a position127*/128EXACT,129/**130* Place the content widget above a position131*/132ABOVE,133/**134* Place the content widget below a position135*/136BELOW137}138/**139* A position for rendering content widgets.140*/141export interface IContentWidgetPosition {142/**143* Desired position which serves as an anchor for placing the content widget.144* The widget will be placed above, at, or below the specified position, based on the145* provided preference. The widget will always touch this position.146*147* Given sufficient horizontal space, the widget will be placed to the right of the148* passed in position. This can be tweaked by providing a `secondaryPosition`.149*150* @see preference151* @see secondaryPosition152*/153position: IPosition | null;154/**155* Optionally, a secondary position can be provided to further define the placing of156* the content widget. The secondary position must have the same line number as the157* primary position. If possible, the widget will be placed such that it also touches158* the secondary position.159*/160secondaryPosition?: IPosition | null;161/**162* Placement preference for position, in order of preference.163*/164preference: ContentWidgetPositionPreference[];165166/**167* Placement preference when multiple view positions refer to the same (model) position.168* This plays a role when injected text is involved.169*/170positionAffinity?: PositionAffinity;171}172/**173* A content widget renders inline with the text and can be easily placed 'near' an editor position.174*/175export interface IContentWidget {176/**177* Render this content widget in a location where it could overflow the editor's view dom node.178*/179allowEditorOverflow?: boolean;180/**181* Call preventDefault() on mousedown events that target the content widget.182*/183suppressMouseDown?: boolean;184/**185* Get a unique identifier of the content widget.186*/187getId(): string;188/**189* Get the dom node of the content widget.190*/191getDomNode(): HTMLElement;192/**193* Get the placement of the content widget.194* If null is returned, the content widget will be placed off screen.195*/196getPosition(): IContentWidgetPosition | null;197/**198* Optional function that is invoked before rendering199* the content widget. If a dimension is returned the editor will200* attempt to use it.201*/202beforeRender?(): IDimension | null;203/**204* Optional function that is invoked after rendering the content205* widget. Is being invoked with the selected position preference206* or `null` if not rendered.207*/208afterRender?(position: ContentWidgetPositionPreference | null, coordinate: IContentWidgetRenderedCoordinate | null): void;209}210211/**212* Coordinatees passed in {@link IContentWidget.afterRender}213*/214export interface IContentWidgetRenderedCoordinate {215/**216* Top position relative to the editor content.217*/218readonly top: number;219220/**221* Left position relative to the editor content.222*/223readonly left: number;224}225226/**227* A positioning preference for rendering overlay widgets.228*/229export const enum OverlayWidgetPositionPreference {230/**231* Position the overlay widget in the top right corner232*/233TOP_RIGHT_CORNER,234235/**236* Position the overlay widget in the bottom right corner237*/238BOTTOM_RIGHT_CORNER,239240/**241* Position the overlay widget in the top center242*/243TOP_CENTER244}245246247/**248* Represents editor-relative coordinates of an overlay widget.249*/250export interface IOverlayWidgetPositionCoordinates {251/**252* The top position for the overlay widget, relative to the editor.253*/254top: number;255/**256* The left position for the overlay widget, relative to the editor.257*/258left: number;259}260261/**262* A position for rendering overlay widgets.263*/264export interface IOverlayWidgetPosition {265/**266* The position preference for the overlay widget.267*/268preference: OverlayWidgetPositionPreference | IOverlayWidgetPositionCoordinates | null;269270/**271* When set, stacks with other overlay widgets with the same preference,272* in an order determined by the ordinal value.273*/274stackOridinal?: number;275}276/**277* An overlay widgets renders on top of the text.278*/279export interface IOverlayWidget {280/**281* Event fired when the widget layout changes.282*/283onDidLayout?: Event<void>;284/**285* Render this overlay widget in a location where it could overflow the editor's view dom node.286*/287allowEditorOverflow?: boolean;288/**289* Get a unique identifier of the overlay widget.290*/291getId(): string;292/**293* Get the dom node of the overlay widget.294*/295getDomNode(): HTMLElement;296/**297* Get the placement of the overlay widget.298* If null is returned, the overlay widget is responsible to place itself.299*/300getPosition(): IOverlayWidgetPosition | null;301/**302* The editor will ensure that the scroll width is >= than this value.303*/304getMinContentWidthInPx?(): number;305}306307/**308* A glyph margin widget renders in the editor glyph margin.309*/310export interface IGlyphMarginWidget {311/**312* Get a unique identifier of the glyph widget.313*/314getId(): string;315/**316* Get the dom node of the glyph widget.317*/318getDomNode(): HTMLElement;319/**320* Get the placement of the glyph widget.321*/322getPosition(): IGlyphMarginWidgetPosition;323}324325/**326* A position for rendering glyph margin widgets.327*/328export interface IGlyphMarginWidgetPosition {329/**330* The glyph margin lane where the widget should be shown.331*/332lane: GlyphMarginLane;333/**334* The priority order of the widget, used for determining which widget335* to render when there are multiple.336*/337zIndex: number;338/**339* The editor range that this widget applies to.340*/341range: IRange;342}343344/**345* Type of hit element with the mouse in the editor.346*/347export const enum MouseTargetType {348/**349* Mouse is on top of an unknown element.350*/351UNKNOWN,352/**353* Mouse is on top of the textarea used for input.354*/355TEXTAREA,356/**357* Mouse is on top of the glyph margin358*/359GUTTER_GLYPH_MARGIN,360/**361* Mouse is on top of the line numbers362*/363GUTTER_LINE_NUMBERS,364/**365* Mouse is on top of the line decorations366*/367GUTTER_LINE_DECORATIONS,368/**369* Mouse is on top of the whitespace left in the gutter by a view zone.370*/371GUTTER_VIEW_ZONE,372/**373* Mouse is on top of text in the content.374*/375CONTENT_TEXT,376/**377* Mouse is on top of empty space in the content (e.g. after line text or below last line)378*/379CONTENT_EMPTY,380/**381* Mouse is on top of a view zone in the content.382*/383CONTENT_VIEW_ZONE,384/**385* Mouse is on top of a content widget.386*/387CONTENT_WIDGET,388/**389* Mouse is on top of the decorations overview ruler.390*/391OVERVIEW_RULER,392/**393* Mouse is on top of a scrollbar.394*/395SCROLLBAR,396/**397* Mouse is on top of an overlay widget.398*/399OVERLAY_WIDGET,400/**401* Mouse is outside of the editor.402*/403OUTSIDE_EDITOR,404}405export interface IBaseMouseTarget {406/**407* The target element408*/409readonly element: HTMLElement | null;410/**411* The 'approximate' editor position412*/413readonly position: Position | null;414/**415* Desired mouse column (e.g. when position.column gets clamped to text length -- clicking after text on a line).416*/417readonly mouseColumn: number;418/**419* The 'approximate' editor range420*/421readonly range: Range | null;422}423export interface IMouseTargetUnknown extends IBaseMouseTarget {424readonly type: MouseTargetType.UNKNOWN;425}426export interface IMouseTargetTextarea extends IBaseMouseTarget {427readonly type: MouseTargetType.TEXTAREA;428readonly position: null;429readonly range: null;430}431export interface IMouseTargetMarginData {432readonly isAfterLines: boolean;433readonly glyphMarginLeft: number;434readonly glyphMarginWidth: number;435readonly glyphMarginLane?: GlyphMarginLane;436readonly lineNumbersWidth: number;437readonly offsetX: number;438}439export interface IMouseTargetMargin extends IBaseMouseTarget {440readonly type: MouseTargetType.GUTTER_GLYPH_MARGIN | MouseTargetType.GUTTER_LINE_NUMBERS | MouseTargetType.GUTTER_LINE_DECORATIONS;441readonly position: Position;442readonly range: Range;443readonly detail: IMouseTargetMarginData;444}445export interface IMouseTargetViewZoneData {446readonly viewZoneId: string;447readonly positionBefore: Position | null;448readonly positionAfter: Position | null;449readonly position: Position;450readonly afterLineNumber: number;451}452export interface IMouseTargetViewZone extends IBaseMouseTarget {453readonly type: MouseTargetType.GUTTER_VIEW_ZONE | MouseTargetType.CONTENT_VIEW_ZONE;454readonly position: Position;455readonly range: Range;456readonly detail: IMouseTargetViewZoneData;457}458export interface IMouseTargetContentTextData {459readonly mightBeForeignElement: boolean;460/**461* @internal462*/463readonly injectedText: InjectedText | null;464}465export interface IMouseTargetContentText extends IBaseMouseTarget {466readonly type: MouseTargetType.CONTENT_TEXT;467readonly position: Position;468readonly range: Range;469readonly detail: IMouseTargetContentTextData;470}471export interface IMouseTargetContentEmptyData {472readonly isAfterLines: boolean;473readonly horizontalDistanceToText?: number;474}475export interface IMouseTargetContentEmpty extends IBaseMouseTarget {476readonly type: MouseTargetType.CONTENT_EMPTY;477readonly position: Position;478readonly range: Range;479readonly detail: IMouseTargetContentEmptyData;480}481export interface IMouseTargetContentWidget extends IBaseMouseTarget {482readonly type: MouseTargetType.CONTENT_WIDGET;483readonly position: null;484readonly range: null;485readonly detail: string;486}487export interface IMouseTargetOverlayWidget extends IBaseMouseTarget {488readonly type: MouseTargetType.OVERLAY_WIDGET;489readonly position: null;490readonly range: null;491readonly detail: string;492}493export interface IMouseTargetScrollbar extends IBaseMouseTarget {494readonly type: MouseTargetType.SCROLLBAR;495readonly position: Position;496readonly range: Range;497}498export interface IMouseTargetOverviewRuler extends IBaseMouseTarget {499readonly type: MouseTargetType.OVERVIEW_RULER;500}501export interface IMouseTargetOutsideEditor extends IBaseMouseTarget {502readonly type: MouseTargetType.OUTSIDE_EDITOR;503readonly outsidePosition: 'above' | 'below' | 'left' | 'right';504readonly outsideDistance: number;505}506/**507* Target hit with the mouse in the editor.508*/509export type IMouseTarget = (510IMouseTargetUnknown511| IMouseTargetTextarea512| IMouseTargetMargin513| IMouseTargetViewZone514| IMouseTargetContentText515| IMouseTargetContentEmpty516| IMouseTargetContentWidget517| IMouseTargetOverlayWidget518| IMouseTargetScrollbar519| IMouseTargetOverviewRuler520| IMouseTargetOutsideEditor521);522/**523* A mouse event originating from the editor.524*/525export interface IEditorMouseEvent {526readonly event: IMouseEvent;527readonly target: IMouseTarget;528}529export interface IPartialEditorMouseEvent {530readonly event: IMouseEvent;531readonly target: IMouseTarget | null;532}533534/**535* A paste event originating from the editor.536*/537export interface IPasteEvent {538readonly range: Range;539readonly languageId: string | null;540readonly clipboardEvent?: ClipboardEvent;541}542543/**544* @internal545*/546export interface PastePayload {547text: string;548pasteOnNewLine: boolean;549multicursorText: string[] | null;550mode: string | null;551clipboardEvent?: ClipboardEvent;552}553554/**555* An overview ruler556* @internal557*/558export interface IOverviewRuler {559getDomNode(): HTMLElement;560dispose(): void;561setZones(zones: OverviewRulerZone[]): void;562setLayout(position: OverviewRulerPosition): void;563}564565/**566* Editor aria options.567* @internal568*/569export interface IEditorAriaOptions {570activeDescendant: string | undefined;571role?: string;572}573574export interface IDiffEditorConstructionOptions extends IDiffEditorOptions, IEditorConstructionOptions {575/**576* Place overflow widgets inside an external DOM node.577* Defaults to an internal DOM node.578*/579overflowWidgetsDomNode?: HTMLElement;580581/**582* Aria label for original editor.583*/584originalAriaLabel?: string;585586/**587* Aria label for modified editor.588*/589modifiedAriaLabel?: string;590}591592/**593* A rich code editor.594*/595export interface ICodeEditor extends editorCommon.IEditor {596/**597* This editor is used as an alternative to an <input> box, i.e. as a simple widget.598* @internal599*/600readonly isSimpleWidget: boolean;601/**602* The context menu ID that should be used to lookup context menu actions.603* @internal604*/605readonly contextMenuId: MenuId;606/**607* The editor's scoped context key service.608* @internal609*/610readonly contextKeyService: IContextKeyService;611/**612* An event emitted when the content of the current model has changed.613* @event614*/615readonly onDidChangeModelContent: Event<IModelContentChangedEvent>;616/**617* An event emitted when the language of the current model has changed.618* @event619*/620readonly onDidChangeModelLanguage: Event<IModelLanguageChangedEvent>;621/**622* An event emitted when the language configuration of the current model has changed.623* @event624*/625readonly onDidChangeModelLanguageConfiguration: Event<IModelLanguageConfigurationChangedEvent>;626/**627* An event emitted when the options of the current model has changed.628* @event629*/630readonly onDidChangeModelOptions: Event<IModelOptionsChangedEvent>;631/**632* An event emitted when the configuration of the editor has changed. (e.g. `editor.updateOptions()`)633* @event634*/635readonly onDidChangeConfiguration: Event<ConfigurationChangedEvent>;636/**637* An event emitted when the cursor position has changed.638* @event639*/640readonly onDidChangeCursorPosition: Event<ICursorPositionChangedEvent>;641/**642* An event emitted when the cursor selection has changed.643* @event644*/645readonly onDidChangeCursorSelection: Event<ICursorSelectionChangedEvent>;646/**647* An event emitted when the model of this editor is about to change (e.g. from `editor.setModel()`).648* @event649*/650readonly onWillChangeModel: Event<editorCommon.IModelChangedEvent>;651/**652* An event emitted when the model of this editor has changed (e.g. `editor.setModel()`).653* @event654*/655readonly onDidChangeModel: Event<editorCommon.IModelChangedEvent>;656/**657* An event emitted when the decorations of the current model have changed.658* @event659*/660readonly onDidChangeModelDecorations: Event<IModelDecorationsChangedEvent>;661/**662* An event emitted when the tokens of the current model have changed.663* @internal664*/665readonly onDidChangeModelTokens: Event<IModelTokensChangedEvent>;666/**667* An event emitted when the text inside this editor gained focus (i.e. cursor starts blinking).668* @event669*/670readonly onDidFocusEditorText: Event<void>;671/**672* An event emitted when the text inside this editor lost focus (i.e. cursor stops blinking).673* @event674*/675readonly onDidBlurEditorText: Event<void>;676/**677* An event emitted when the text inside this editor or an editor widget gained focus.678* @event679*/680readonly onDidFocusEditorWidget: Event<void>;681/**682* An event emitted when the text inside this editor or an editor widget lost focus.683* @event684*/685readonly onDidBlurEditorWidget: Event<void>;686/**687* An event emitted before interpreting typed characters (on the keyboard).688* @event689* @internal690*/691readonly onWillType: Event<string>;692/**693* An event emitted after interpreting typed characters (on the keyboard).694* @event695* @internal696*/697readonly onDidType: Event<string>;698/**699* Boolean indicating whether input is in composition700*/701readonly inComposition: boolean;702/**703* An event emitted after composition has started.704*/705readonly onDidCompositionStart: Event<void>;706/**707* An event emitted after composition has ended.708*/709readonly onDidCompositionEnd: Event<void>;710/**711* An event emitted when editing failed because the editor is read-only.712* @event713*/714readonly onDidAttemptReadOnlyEdit: Event<void>;715/**716* An event emitted when users paste text in the editor.717* @event718*/719readonly onDidPaste: Event<IPasteEvent>;720/**721* An event emitted on a "mouseup".722* @event723*/724readonly onMouseUp: Event<IEditorMouseEvent>;725/**726* An event emitted on a "mousedown".727* @event728*/729readonly onMouseDown: Event<IEditorMouseEvent>;730/**731* An event emitted on a "mousedrag".732* @internal733* @event734*/735readonly onMouseDrag: Event<IEditorMouseEvent>;736/**737* An event emitted on a "mousedrop".738* @internal739* @event740*/741readonly onMouseDrop: Event<IPartialEditorMouseEvent>;742/**743* An event emitted on a "mousedropcanceled".744* @internal745* @event746*/747readonly onMouseDropCanceled: Event<void>;748/**749* An event emitted when content is dropped into the editor.750* @internal751* @event752*/753readonly onDropIntoEditor: Event<{ readonly position: IPosition; readonly event: DragEvent }>;754/**755* An event emitted on a "contextmenu".756* @event757*/758readonly onContextMenu: Event<IEditorMouseEvent>;759/**760* An event emitted on a "mousemove".761* @event762*/763readonly onMouseMove: Event<IEditorMouseEvent>;764/**765* An event emitted on a "mouseleave".766* @event767*/768readonly onMouseLeave: Event<IPartialEditorMouseEvent>;769/**770* An event emitted on a "mousewheel"771* @event772* @internal773*/774readonly onMouseWheel: Event<IMouseWheelEvent>;775/**776* An event emitted on a "keyup".777* @event778*/779readonly onKeyUp: Event<IKeyboardEvent>;780/**781* An event emitted on a "keydown".782* @event783*/784readonly onKeyDown: Event<IKeyboardEvent>;785/**786* An event emitted when the layout of the editor has changed.787* @event788*/789readonly onDidLayoutChange: Event<EditorLayoutInfo>;790/**791* An event emitted when the content width or content height in the editor has changed.792* @event793*/794readonly onDidContentSizeChange: Event<editorCommon.IContentSizeChangedEvent>;795/**796* An event emitted when the scroll in the editor has changed.797* @event798*/799readonly onDidScrollChange: Event<editorCommon.IScrollEvent>;800801/**802* An event emitted when hidden areas change in the editor (e.g. due to folding).803* @event804*/805readonly onDidChangeHiddenAreas: Event<void>;806807/**808* An event emitted before an editor809* @internal810*/811readonly onWillTriggerEditorOperationEvent: Event<editorCommon.ITriggerEditorOperationEvent>;812813/**814* Some editor operations fire multiple events at once.815* To allow users to react to multiple events fired by a single operation,816* the editor fires a begin update before the operation and an end update after the operation.817* Whenever the editor fires `onBeginUpdate`, it will also fire `onEndUpdate` once the operation finishes.818* Note that not all operations are bracketed by `onBeginUpdate` and `onEndUpdate`.819*/820readonly onBeginUpdate: Event<void>;821822/**823* Fires after the editor completes the operation it fired `onBeginUpdate` for.824*/825readonly onEndUpdate: Event<void>;826827/**828* Saves current view state of the editor in a serializable object.829*/830saveViewState(): editorCommon.ICodeEditorViewState | null;831832/**833* Restores the view state of the editor from a serializable object generated by `saveViewState`.834*/835restoreViewState(state: editorCommon.ICodeEditorViewState | null): void;836837/**838* Returns true if the text inside this editor or an editor widget has focus.839*/840hasWidgetFocus(): boolean;841842/**843* Get a contribution of this editor.844* @id Unique identifier of the contribution.845* @return The contribution or null if contribution not found.846*/847getContribution<T extends editorCommon.IEditorContribution>(id: string): T | null;848849/**850* Execute `fn` with the editor's services.851* @internal852*/853invokeWithinContext<T>(fn: (accessor: ServicesAccessor) => T): T;854855/**856* Type the getModel() of IEditor.857*/858getModel(): ITextModel | null;859860/**861* Sets the current model attached to this editor.862* If the previous model was created by the editor via the value key in the options863* literal object, it will be destroyed. Otherwise, if the previous model was set864* via setModel, or the model key in the options literal object, the previous model865* will not be destroyed.866* It is safe to call setModel(null) to simply detach the current model from the editor.867*/868setModel(model: ITextModel | null): void;869870/**871* Gets all the editor computed options.872*/873getOptions(): IComputedEditorOptions;874875/**876* Gets a specific editor option.877*/878getOption<T extends EditorOption>(id: T): FindComputedEditorOptionValueById<T>;879880/**881* Returns the editor's configuration (without any validation or defaults).882*/883getRawOptions(): IEditorOptions;884885/**886* @internal887*/888getOverflowWidgetsDomNode(): HTMLElement | undefined;889890/**891* @internal892*/893getConfiguredWordAtPosition(position: Position): IWordAtPosition | null;894895/**896* An event emitted when line heights from decorations change897* @internal898* @event899*/900onDidChangeLineHeight: Event<ModelLineHeightChangedEvent>;901902/**903* An event emitted when the font of the editor has changed.904* @internal905* @event906*/907onDidChangeFont: Event<ModelFontChangedEvent>;908909/**910* Get value of the current model attached to this editor.911* @see {@link ITextModel.getValue}912*/913getValue(options?: { preserveBOM: boolean; lineEnding: string }): string;914915/**916* Set the value of the current model attached to this editor.917* @see {@link ITextModel.setValue}918*/919setValue(newValue: string): void;920921/**922* Get the width of the editor's content.923* This is information that is "erased" when computing `scrollWidth = Math.max(contentWidth, width)`924*/925getContentWidth(): number;926/**927* Get the scrollWidth of the editor's viewport.928*/929getScrollWidth(): number;930/**931* Get the scrollLeft of the editor's viewport.932*/933getScrollLeft(): number;934935/**936* Get the height of the editor's content.937* This is information that is "erased" when computing `scrollHeight = Math.max(contentHeight, height)`938*/939getContentHeight(): number;940/**941* Get the scrollHeight of the editor's viewport.942*/943getScrollHeight(): number;944/**945* Get the scrollTop of the editor's viewport.946*/947getScrollTop(): number;948949/**950* Change the scrollLeft of the editor's viewport.951*/952setScrollLeft(newScrollLeft: number, scrollType?: editorCommon.ScrollType): void;953/**954* Change the scrollTop of the editor's viewport.955*/956setScrollTop(newScrollTop: number, scrollType?: editorCommon.ScrollType): void;957/**958* Change the scroll position of the editor's viewport.959*/960setScrollPosition(position: editorCommon.INewScrollPosition, scrollType?: editorCommon.ScrollType): void;961/**962* Check if the editor is currently scrolling towards a different scroll position.963*/964hasPendingScrollAnimation(): boolean;965966/**967* Get an action that is a contribution to this editor.968* @id Unique identifier of the contribution.969* @return The action or null if action not found.970*/971getAction(id: string): editorCommon.IEditorAction | null;972973/**974* Execute a command on the editor.975* The edits will land on the undo-redo stack, but no "undo stop" will be pushed.976* @param source The source of the call.977* @param command The command to execute978*/979executeCommand(source: string | null | undefined, command: editorCommon.ICommand): void;980981/**982* Create an "undo stop" in the undo-redo stack.983*/984pushUndoStop(): boolean;985986/**987* Remove the "undo stop" in the undo-redo stack.988*/989popUndoStop(): boolean;990991/**992* Execute edits on the editor.993* The edits will land on the undo-redo stack, but no "undo stop" will be pushed.994* @param source The source of the call.995* @param edits The edits to execute.996* @param endCursorState Cursor state after the edits were applied.997*/998executeEdits(source: string | null | undefined, edits: IIdentifiedSingleEditOperation[], endCursorState?: ICursorStateComputer | Selection[]): boolean;999/** @internal */1000executeEdits(source: TextModelEditSource | undefined, edits: IIdentifiedSingleEditOperation[], endCursorState?: ICursorStateComputer | Selection[]): boolean;10011002/**1003* @internal1004*/1005edit(edit: TextEdit, reason: TextModelEditSource): void;10061007/**1008* Execute multiple (concomitant) commands on the editor.1009* @param source The source of the call.1010* @param command The commands to execute1011*/1012executeCommands(source: string | null | undefined, commands: (editorCommon.ICommand | null)[]): void;10131014/**1015* @internal1016*/1017_getViewModel(): IViewModel | null;10181019/**1020* Get all the decorations on a line (filtering out decorations from other editors).1021*/1022getLineDecorations(lineNumber: number): IModelDecoration[] | null;10231024/**1025* Get all the decorations for a range (filtering out decorations from other editors).1026*/1027getDecorationsInRange(range: Range): IModelDecoration[] | null;10281029/**1030* Get the font size at a given position1031* @param position the position for which to fetch the font size1032*/1033getFontSizeAtPosition(position: IPosition): string | null;10341035/**1036* All decorations added through this call will get the ownerId of this editor.1037* @deprecated Use `createDecorationsCollection`1038* @see createDecorationsCollection1039*/1040deltaDecorations(oldDecorations: string[], newDecorations: IModelDeltaDecoration[]): string[];10411042/**1043* Remove previously added decorations.1044*/1045removeDecorations(decorationIds: string[]): void;10461047/**1048* @internal1049*/1050setDecorationsByType(description: string, decorationTypeKey: string, ranges: editorCommon.IDecorationOptions[]): readonly string[];10511052/**1053* @internal1054*/1055setDecorationsByTypeFast(decorationTypeKey: string, ranges: IRange[]): void;10561057/**1058* @internal1059*/1060removeDecorationsByType(decorationTypeKey: string): void;10611062/**1063* Get the layout info for the editor.1064*/1065getLayoutInfo(): EditorLayoutInfo;10661067/**1068* Returns the ranges that are currently visible.1069* Does not account for horizontal scrolling.1070*/1071getVisibleRanges(): Range[];10721073/**1074* @internal1075*/1076getVisibleRangesPlusViewportAboveBelow(): Range[];10771078/**1079* Get the view zones.1080* @internal1081*/1082getWhitespaces(): IEditorWhitespace[];10831084/**1085* Get the vertical position (top offset) for the line's top w.r.t. to the first line.1086*/1087getTopForLineNumber(lineNumber: number, includeViewZones?: boolean): number;10881089/**1090* Get the vertical position (top offset) for the line's bottom w.r.t. to the first line.1091*/1092getBottomForLineNumber(lineNumber: number): number;10931094/**1095* Get the vertical position (top offset) for the position w.r.t. to the first line.1096*/1097getTopForPosition(lineNumber: number, column: number): number;10981099/**1100* Get the line height for a model position.1101*/1102getLineHeightForPosition(position: IPosition): number;11031104/**1105* Set the model ranges that will be hidden in the view.1106* Hidden areas are stored per source.1107* @internal1108*/1109setHiddenAreas(ranges: IRange[], source?: unknown): void;11101111/**1112* Sets the editor aria options, primarily the active descendent.1113* @internal1114*/1115setAriaOptions(options: IEditorAriaOptions): void;11161117/**1118* Write the screen reader content to be the current selection1119*/1120writeScreenReaderContent(reason: string): void;11211122/**1123* @internal1124*/1125getTelemetryData(): { [key: string]: any } | undefined;11261127/**1128* Returns the editor's container dom node1129*/1130getContainerDomNode(): HTMLElement;11311132/**1133* Returns the editor's dom node1134*/1135getDomNode(): HTMLElement | null;11361137/**1138* Add a content widget. Widgets must have unique ids, otherwise they will be overwritten.1139*/1140addContentWidget(widget: IContentWidget): void;1141/**1142* Layout/Reposition a content widget. This is a ping to the editor to call widget.getPosition()1143* and update appropriately.1144*/1145layoutContentWidget(widget: IContentWidget): void;1146/**1147* Remove a content widget.1148*/1149removeContentWidget(widget: IContentWidget): void;11501151/**1152* Add an overlay widget. Widgets must have unique ids, otherwise they will be overwritten.1153*/1154addOverlayWidget(widget: IOverlayWidget): void;1155/**1156* Layout/Reposition an overlay widget. This is a ping to the editor to call widget.getPosition()1157* and update appropriately.1158*/1159layoutOverlayWidget(widget: IOverlayWidget): void;1160/**1161* Remove an overlay widget.1162*/1163removeOverlayWidget(widget: IOverlayWidget): void;11641165/**1166* Add a glyph margin widget. Widgets must have unique ids, otherwise they will be overwritten.1167*/1168addGlyphMarginWidget(widget: IGlyphMarginWidget): void;1169/**1170* Layout/Reposition a glyph margin widget. This is a ping to the editor to call widget.getPosition()1171* and update appropriately.1172*/1173layoutGlyphMarginWidget(widget: IGlyphMarginWidget): void;1174/**1175* Remove a glyph margin widget.1176*/1177removeGlyphMarginWidget(widget: IGlyphMarginWidget): void;11781179/**1180* Change the view zones. View zones are lost when a new model is attached to the editor.1181*/1182changeViewZones(callback: (accessor: IViewZoneChangeAccessor) => void): void;11831184/**1185* Get the horizontal position (left offset) for the column w.r.t to the beginning of the line.1186* This method works only if the line `lineNumber` is currently rendered (in the editor's viewport).1187* Use this method with caution.1188*/1189getOffsetForColumn(lineNumber: number, column: number): number;11901191/**1192* Force an editor render now.1193*/1194render(forceRedraw?: boolean): void;11951196/**1197* Get the hit test target at coordinates `clientX` and `clientY`.1198* The coordinates are relative to the top-left of the viewport.1199*1200* @returns Hit test target or null if the coordinates fall outside the editor or the editor has no model.1201*/1202getTargetAtClientPoint(clientX: number, clientY: number): IMouseTarget | null;12031204/**1205* Get the visible position for `position`.1206* The result position takes scrolling into account and is relative to the top left corner of the editor.1207* Explanation 1: the results of this method will change for the same `position` if the user scrolls the editor.1208* Explanation 2: the results of this method will not change if the container of the editor gets repositioned.1209* Warning: the results of this method are inaccurate for positions that are outside the current editor viewport.1210*/1211getScrolledVisiblePosition(position: IPosition): { top: number; left: number; height: number } | null;12121213/**1214* Apply the same font settings as the editor to `target`.1215*/1216applyFontInfo(target: HTMLElement): void;12171218/**1219* Check if the current instance has a model attached.1220* @internal1221*/1222hasModel(): this is IActiveCodeEditor;12231224setBanner(bannerDomNode: HTMLElement | null, height: number): void;12251226/**1227* Is called when the model has been set, view state was restored and options are updated.1228* This is the best place to compute data for the viewport (such as tokens).1229*/1230handleInitialized?(): void;1231}12321233/**1234* @internal1235*/1236export interface IActiveCodeEditor extends ICodeEditor {1237/**1238* Returns the primary position of the cursor.1239*/1240getPosition(): Position;12411242/**1243* Returns the primary selection of the editor.1244*/1245getSelection(): Selection;12461247/**1248* Returns all the selections of the editor.1249*/1250getSelections(): Selection[];12511252/**1253* Saves current view state of the editor in a serializable object.1254*/1255saveViewState(): editorCommon.ICodeEditorViewState;12561257/**1258* Type the getModel() of IEditor.1259*/1260getModel(): ITextModel;12611262/**1263* @internal1264*/1265_getViewModel(): IViewModel;12661267/**1268* Get all the decorations on a line (filtering out decorations from other editors).1269*/1270getLineDecorations(lineNumber: number): IModelDecoration[];12711272/**1273* Returns the editor's dom node1274*/1275getDomNode(): HTMLElement;12761277/**1278* Get the visible position for `position`.1279* The result position takes scrolling into account and is relative to the top left corner of the editor.1280* Explanation 1: the results of this method will change for the same `position` if the user scrolls the editor.1281* Explanation 2: the results of this method will not change if the container of the editor gets repositioned.1282* Warning: the results of this method are inaccurate for positions that are outside the current editor viewport.1283*/1284getScrolledVisiblePosition(position: IPosition): { top: number; left: number; height: number };1285}12861287/**1288* @internal1289*/1290export const enum DiffEditorState {1291Idle,1292ComputingDiff,1293DiffComputed1294}12951296/**1297* A rich diff editor.1298*/1299export interface IDiffEditor extends editorCommon.IEditor {13001301/**1302* Returns whether the diff editor is ignoring trim whitespace or not.1303* @internal1304*/1305readonly ignoreTrimWhitespace: boolean;1306/**1307* Returns whether the diff editor is rendering side by side or inline.1308* @internal1309*/1310readonly renderSideBySide: boolean;1311/**1312* Timeout in milliseconds after which diff computation is cancelled.1313* @internal1314*/1315readonly maxComputationTime: number;13161317/**1318* @see {@link ICodeEditor.getContainerDomNode}1319*/1320getContainerDomNode(): HTMLElement;13211322/**1323* An event emitted when the diff information computed by this diff editor has been updated.1324* @event1325*/1326readonly onDidUpdateDiff: Event<void>;13271328/**1329* An event emitted when the diff model is changed (i.e. the diff editor shows new content).1330* @event1331*/1332readonly onDidChangeModel: Event<void>;13331334/**1335* Saves current view state of the editor in a serializable object.1336*/1337saveViewState(): editorCommon.IDiffEditorViewState | null;13381339/**1340* Restores the view state of the editor from a serializable object generated by `saveViewState`.1341*/1342restoreViewState(state: editorCommon.IDiffEditorViewState | null): void;13431344/**1345* Type the getModel() of IEditor.1346*/1347getModel(): editorCommon.IDiffEditorModel | null;13481349createViewModel(model: editorCommon.IDiffEditorModel): editorCommon.IDiffEditorViewModel;13501351/**1352* Sets the current model attached to this editor.1353* If the previous model was created by the editor via the value key in the options1354* literal object, it will be destroyed. Otherwise, if the previous model was set1355* via setModel, or the model key in the options literal object, the previous model1356* will not be destroyed.1357* It is safe to call setModel(null) to simply detach the current model from the editor.1358*/1359setModel(model: editorCommon.IDiffEditorModel | editorCommon.IDiffEditorViewModel | null): void;13601361/**1362* Get the `original` editor.1363*/1364getOriginalEditor(): ICodeEditor;13651366/**1367* Get the `modified` editor.1368*/1369getModifiedEditor(): ICodeEditor;13701371/**1372* Get the computed diff information.1373*/1374getLineChanges(): ILineChange[] | null;13751376/**1377* Get the computed diff information.1378* @internal1379*/1380getDiffComputationResult(): IDiffComputationResult | null;13811382/**1383* Update the editor's options after the editor has been created.1384*/1385updateOptions(newOptions: IDiffEditorOptions): void;13861387/**1388* @internal1389*/1390setBoundarySashes(sashes: IBoundarySashes): void;13911392/**1393* Jumps to the next or previous diff.1394*/1395goToDiff(target: 'next' | 'previous'): void;13961397/**1398* Scrolls to the first diff.1399* (Waits until the diff computation finished.)1400*/1401revealFirstDiff(): unknown;14021403accessibleDiffViewerNext(): void;14041405accessibleDiffViewerPrev(): void;14061407handleInitialized(): void;1408}14091410/**1411*@internal1412*/1413export function isCodeEditor(thing: unknown): thing is ICodeEditor {1414if (thing && typeof (<ICodeEditor>thing).getEditorType === 'function') {1415return (<ICodeEditor>thing).getEditorType() === editorCommon.EditorType.ICodeEditor;1416} else {1417return false;1418}1419}14201421/**1422*@internal1423*/1424export function isDiffEditor(thing: unknown): thing is IDiffEditor {1425if (thing && typeof (<IDiffEditor>thing).getEditorType === 'function') {1426return (<IDiffEditor>thing).getEditorType() === editorCommon.EditorType.IDiffEditor;1427} else {1428return false;1429}1430}14311432/**1433*@internal1434*/1435export function isCompositeEditor(thing: unknown): thing is editorCommon.ICompositeCodeEditor {1436return !!thing1437&& typeof thing === 'object'1438&& typeof (<editorCommon.ICompositeCodeEditor>thing).onDidChangeActiveEditor === 'function';14391440}14411442/**1443*@internal1444*/1445export function getCodeEditor(thing: unknown): ICodeEditor | null {1446if (isCodeEditor(thing)) {1447return thing;1448}14491450if (isDiffEditor(thing)) {1451return thing.getModifiedEditor();1452}14531454if (isCompositeEditor(thing) && isCodeEditor(thing.activeCodeEditor)) {1455return thing.activeCodeEditor;1456}14571458return null;1459}14601461/**1462*@internal1463*/1464export function getIEditor(thing: any): editorCommon.IEditor | null {1465if (isCodeEditor(thing) || isDiffEditor(thing)) {1466return thing;1467}14681469return null;1470}147114721473