Path: blob/main/src/vs/editor/browser/editorBrowser.ts
5237 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 { MenuId } from '../../platform/actions/common/actions.js';10import { IContextKeyService } from '../../platform/contextkey/common/contextkey.js';11import { ServicesAccessor } from '../../platform/instantiation/common/instantiation.js';12import { ConfigurationChangedEvent, EditorLayoutInfo, EditorOption, FindComputedEditorOptionValueById, IComputedEditorOptions, IDiffEditorOptions, IEditorOptions, OverviewRulerPosition } from '../common/config/editorOptions.js';13import { IDimension } from '../common/core/2d/dimension.js';14import { TextEdit } from '../common/core/edits/textEdit.js';15import { IPosition, Position } from '../common/core/position.js';16import { IRange, Range } from '../common/core/range.js';17import { Selection } from '../common/core/selection.js';18import { IWordAtPosition } from '../common/core/wordHelper.js';19import { ICursorPositionChangedEvent, ICursorSelectionChangedEvent } from '../common/cursorEvents.js';20import { IDiffComputationResult, ILineChange } from '../common/diff/legacyLinesDiffComputer.js';21import * as editorCommon from '../common/editorCommon.js';22import { GlyphMarginLane, ICursorStateComputer, IIdentifiedSingleEditOperation, IModelDecoration, IModelDecorationsChangeAccessor, IModelDeltaDecoration, ITextModel, PositionAffinity } from '../common/model.js';23import { InjectedText } from '../common/modelLineProjectionData.js';24import { TextModelEditSource } from '../common/textModelEditSource.js';25import { IModelContentChangedEvent, IModelDecorationsChangedEvent, IModelLanguageChangedEvent, IModelLanguageConfigurationChangedEvent, IModelOptionsChangedEvent, IModelTokensChangedEvent, ModelFontChangedEvent, ModelLineHeightChangedEvent } from '../common/textModelEvents.js';26import { IEditorWhitespace, IViewModel } from '../common/viewModel.js';27import { OverviewRulerZone } from '../common/viewModel/overviewZoneManager.js';28import { IEditorConstructionOptions } from './config/editorConfiguration.js';29import { IClipboardCopyEvent, IClipboardPasteEvent } from './controller/editContext/clipboardUtils.js';3031/**32* A view zone is a full horizontal rectangle that 'pushes' text down.33* The editor reserves space for view zones when rendering.34*/35export interface IViewZone {36/**37* The line number after which this zone should appear.38* Use 0 to place a view zone before the first line number.39*/40afterLineNumber: number;41/**42* The column after which this zone should appear.43* If not set, the maxLineColumn of `afterLineNumber` will be used.44* This is relevant for wrapped lines.45*/46afterColumn?: number;47/**48* If the `afterColumn` has multiple view columns, the affinity specifies which one to use. Defaults to `none`.49*/50afterColumnAffinity?: PositionAffinity;51/**52* Render the zone even when its line is hidden.53*/54showInHiddenAreas?: boolean;55/**56* Tiebreaker that is used when multiple view zones want to be after the same line.57* Defaults to `afterColumn` otherwise 10000;58*/59ordinal?: number;60/**61* Suppress mouse down events.62* If set, the editor will attach a mouse down listener to the view zone and .preventDefault on it.63* Defaults to false64*/65suppressMouseDown?: boolean;66/**67* The height in lines of the view zone.68* If specified, `heightInPx` will be used instead of this.69* If neither `heightInPx` nor `heightInLines` is specified, a default of `heightInLines` = 1 will be chosen.70*/71heightInLines?: number;72/**73* The height in px of the view zone.74* If this is set, the editor will give preference to it rather than `heightInLines` above.75* If neither `heightInPx` nor `heightInLines` is specified, a default of `heightInLines` = 1 will be chosen.76*/77heightInPx?: number;78/**79* The minimum width in px of the view zone.80* If this is set, the editor will ensure that the scroll width is >= than this value.81*/82minWidthInPx?: number;83/**84* The dom node of the view zone85*/86domNode: HTMLElement;87/**88* An optional dom node for the view zone that will be placed in the margin area.89*/90marginDomNode?: HTMLElement | null;91/**92* Callback which gives the relative top of the view zone as it appears (taking scrolling into account).93*/94onDomNodeTop?: (top: number) => void;95/**96* Callback which gives the height in pixels of the view zone.97*/98onComputedHeight?: (height: number) => void;99}100/**101* An accessor that allows for zones to be added or removed.102*/103export interface IViewZoneChangeAccessor {104/**105* Create a new view zone.106* @param zone Zone to create107* @return A unique identifier to the view zone.108*/109addZone(zone: IViewZone): string;110/**111* Remove a zone112* @param id A unique identifier to the view zone, as returned by the `addZone` call.113*/114removeZone(id: string): void;115/**116* Change a zone's position.117* The editor will rescan the `afterLineNumber` and `afterColumn` properties of a view zone.118*/119layoutZone(id: string): void;120}121122/**123* A positioning preference for rendering content widgets.124*/125export const enum ContentWidgetPositionPreference {126/**127* Place the content widget exactly at a position128*/129EXACT,130/**131* Place the content widget above a position132*/133ABOVE,134/**135* Place the content widget below a position136*/137BELOW138}139/**140* A position for rendering content widgets.141*/142export interface IContentWidgetPosition {143/**144* Desired position which serves as an anchor for placing the content widget.145* The widget will be placed above, at, or below the specified position, based on the146* provided preference. The widget will always touch this position.147*148* Given sufficient horizontal space, the widget will be placed to the right of the149* passed in position. This can be tweaked by providing a `secondaryPosition`.150*151* @see preference152* @see secondaryPosition153*/154position: IPosition | null;155/**156* Optionally, a secondary position can be provided to further define the placing of157* the content widget. The secondary position must have the same line number as the158* primary position. If possible, the widget will be placed such that it also touches159* the secondary position.160*/161secondaryPosition?: IPosition | null;162/**163* Placement preference for position, in order of preference.164*/165preference: ContentWidgetPositionPreference[];166167/**168* Placement preference when multiple view positions refer to the same (model) position.169* This plays a role when injected text is involved.170*/171positionAffinity?: PositionAffinity;172}173/**174* A content widget renders inline with the text and can be easily placed 'near' an editor position.175*/176export interface IContentWidget {177/**178* Render this content widget in a location where it could overflow the editor's view dom node.179*/180allowEditorOverflow?: boolean;181182/**183* If true, this widget doesn't have a visual representation.184* The element will have display set to 'none'.185*/186useDisplayNone?: boolean;187188/**189* Call preventDefault() on mousedown events that target the content widget.190*/191suppressMouseDown?: boolean;192/**193* Get a unique identifier of the content widget.194*/195getId(): string;196/**197* Get the dom node of the content widget.198*/199getDomNode(): HTMLElement;200/**201* Get the placement of the content widget.202* If null is returned, the content widget will be placed off screen.203*/204getPosition(): IContentWidgetPosition | null;205/**206* Optional function that is invoked before rendering207* the content widget. If a dimension is returned the editor will208* attempt to use it.209*/210beforeRender?(): IDimension | null;211/**212* Optional function that is invoked after rendering the content213* widget. Is being invoked with the selected position preference214* or `null` if not rendered.215*/216afterRender?(position: ContentWidgetPositionPreference | null, coordinate: IContentWidgetRenderedCoordinate | null): void;217}218219/**220* Coordinatees passed in {@link IContentWidget.afterRender}221*/222export interface IContentWidgetRenderedCoordinate {223/**224* Top position relative to the editor content.225*/226readonly top: number;227228/**229* Left position relative to the editor content.230*/231readonly left: number;232}233234/**235* A positioning preference for rendering overlay widgets.236*/237export const enum OverlayWidgetPositionPreference {238/**239* Position the overlay widget in the top right corner240*/241TOP_RIGHT_CORNER,242243/**244* Position the overlay widget in the bottom right corner245*/246BOTTOM_RIGHT_CORNER,247248/**249* Position the overlay widget in the top center250*/251TOP_CENTER252}253254255/**256* Represents editor-relative coordinates of an overlay widget.257*/258export interface IOverlayWidgetPositionCoordinates {259/**260* The top position for the overlay widget, relative to the editor.261*/262top: number;263/**264* The left position for the overlay widget, relative to the editor.265*/266left: number;267}268269270271/**272* A position for rendering overlay widgets.273*/274export interface IOverlayWidgetPosition {275/**276* The position preference for the overlay widget.277*/278preference: OverlayWidgetPositionPreference | IOverlayWidgetPositionCoordinates | null;279280/**281* When set, stacks with other overlay widgets with the same preference,282* in an order determined by the ordinal value.283*/284stackOrdinal?: number;285}286/**287* An overlay widgets renders on top of the text.288*/289export interface IOverlayWidget {290/**291* Event fired when the widget layout changes.292*/293readonly onDidLayout?: Event<void>;294/**295* Render this overlay widget in a location where it could overflow the editor's view dom node.296*/297allowEditorOverflow?: boolean;298/**299* Get a unique identifier of the overlay widget.300*/301getId(): string;302/**303* Get the dom node of the overlay widget.304*/305getDomNode(): HTMLElement;306/**307* Get the placement of the overlay widget.308* If null is returned, the overlay widget is responsible to place itself.309*/310getPosition(): IOverlayWidgetPosition | null;311/**312* The editor will ensure that the scroll width is >= than this value.313*/314getMinContentWidthInPx?(): number;315}316317/**318* A glyph margin widget renders in the editor glyph margin.319*/320export interface IGlyphMarginWidget {321/**322* Get a unique identifier of the glyph widget.323*/324getId(): string;325/**326* Get the dom node of the glyph widget.327*/328getDomNode(): HTMLElement;329/**330* Get the placement of the glyph widget.331*/332getPosition(): IGlyphMarginWidgetPosition;333}334335/**336* A position for rendering glyph margin widgets.337*/338export interface IGlyphMarginWidgetPosition {339/**340* The glyph margin lane where the widget should be shown.341*/342lane: GlyphMarginLane;343/**344* The priority order of the widget, used for determining which widget345* to render when there are multiple.346*/347zIndex: number;348/**349* The editor range that this widget applies to.350*/351range: IRange;352}353354/**355* Type of hit element with the mouse in the editor.356*/357export const enum MouseTargetType {358/**359* Mouse is on top of an unknown element.360*/361UNKNOWN,362/**363* Mouse is on top of the textarea used for input.364*/365TEXTAREA,366/**367* Mouse is on top of the glyph margin368*/369GUTTER_GLYPH_MARGIN,370/**371* Mouse is on top of the line numbers372*/373GUTTER_LINE_NUMBERS,374/**375* Mouse is on top of the line decorations376*/377GUTTER_LINE_DECORATIONS,378/**379* Mouse is on top of the whitespace left in the gutter by a view zone.380*/381GUTTER_VIEW_ZONE,382/**383* Mouse is on top of text in the content.384*/385CONTENT_TEXT,386/**387* Mouse is on top of empty space in the content (e.g. after line text or below last line)388*/389CONTENT_EMPTY,390/**391* Mouse is on top of a view zone in the content.392*/393CONTENT_VIEW_ZONE,394/**395* Mouse is on top of a content widget.396*/397CONTENT_WIDGET,398/**399* Mouse is on top of the decorations overview ruler.400*/401OVERVIEW_RULER,402/**403* Mouse is on top of a scrollbar.404*/405SCROLLBAR,406/**407* Mouse is on top of an overlay widget.408*/409OVERLAY_WIDGET,410/**411* Mouse is outside of the editor.412*/413OUTSIDE_EDITOR,414}415export interface IBaseMouseTarget {416/**417* The target element418*/419readonly element: HTMLElement | null;420/**421* The 'approximate' editor position422*/423readonly position: Position | null;424/**425* Desired mouse column (e.g. when position.column gets clamped to text length -- clicking after text on a line).426*/427readonly mouseColumn: number;428/**429* The 'approximate' editor range430*/431readonly range: Range | null;432}433export interface IMouseTargetUnknown extends IBaseMouseTarget {434readonly type: MouseTargetType.UNKNOWN;435}436export interface IMouseTargetTextarea extends IBaseMouseTarget {437readonly type: MouseTargetType.TEXTAREA;438readonly position: null;439readonly range: null;440}441export interface IMouseTargetMarginData {442readonly isAfterLines: boolean;443readonly glyphMarginLeft: number;444readonly glyphMarginWidth: number;445readonly glyphMarginLane?: GlyphMarginLane;446readonly lineNumbersWidth: number;447readonly offsetX: number;448}449export interface IMouseTargetMargin extends IBaseMouseTarget {450readonly type: MouseTargetType.GUTTER_GLYPH_MARGIN | MouseTargetType.GUTTER_LINE_NUMBERS | MouseTargetType.GUTTER_LINE_DECORATIONS;451readonly position: Position;452readonly range: Range;453readonly detail: IMouseTargetMarginData;454}455export interface IMouseTargetViewZoneData {456readonly viewZoneId: string;457readonly positionBefore: Position | null;458readonly positionAfter: Position | null;459readonly position: Position;460readonly afterLineNumber: number;461}462export interface IMouseTargetViewZone extends IBaseMouseTarget {463readonly type: MouseTargetType.GUTTER_VIEW_ZONE | MouseTargetType.CONTENT_VIEW_ZONE;464readonly position: Position;465readonly range: Range;466readonly detail: IMouseTargetViewZoneData;467}468export interface IMouseTargetContentTextData {469readonly mightBeForeignElement: boolean;470/**471* @internal472*/473readonly injectedText: InjectedText | null;474}475export interface IMouseTargetContentText extends IBaseMouseTarget {476readonly type: MouseTargetType.CONTENT_TEXT;477readonly position: Position;478readonly range: Range;479readonly detail: IMouseTargetContentTextData;480}481export interface IMouseTargetContentEmptyData {482readonly isAfterLines: boolean;483readonly horizontalDistanceToText?: number;484}485export interface IMouseTargetContentEmpty extends IBaseMouseTarget {486readonly type: MouseTargetType.CONTENT_EMPTY;487readonly position: Position;488readonly range: Range;489readonly detail: IMouseTargetContentEmptyData;490}491export interface IMouseTargetContentWidget extends IBaseMouseTarget {492readonly type: MouseTargetType.CONTENT_WIDGET;493readonly position: null;494readonly range: null;495readonly detail: string;496}497export interface IMouseTargetOverlayWidget extends IBaseMouseTarget {498readonly type: MouseTargetType.OVERLAY_WIDGET;499readonly position: null;500readonly range: null;501readonly detail: string;502}503export interface IMouseTargetScrollbar extends IBaseMouseTarget {504readonly type: MouseTargetType.SCROLLBAR;505readonly position: Position;506readonly range: Range;507}508export interface IMouseTargetOverviewRuler extends IBaseMouseTarget {509readonly type: MouseTargetType.OVERVIEW_RULER;510}511export interface IMouseTargetOutsideEditor extends IBaseMouseTarget {512readonly type: MouseTargetType.OUTSIDE_EDITOR;513readonly outsidePosition: 'above' | 'below' | 'left' | 'right';514readonly outsideDistance: number;515}516/**517* Target hit with the mouse in the editor.518*/519export type IMouseTarget = (520IMouseTargetUnknown521| IMouseTargetTextarea522| IMouseTargetMargin523| IMouseTargetViewZone524| IMouseTargetContentText525| IMouseTargetContentEmpty526| IMouseTargetContentWidget527| IMouseTargetOverlayWidget528| IMouseTargetScrollbar529| IMouseTargetOverviewRuler530| IMouseTargetOutsideEditor531);532/**533* A mouse event originating from the editor.534*/535export interface IEditorMouseEvent {536readonly event: IMouseEvent;537readonly target: IMouseTarget;538}539export interface IPartialEditorMouseEvent {540readonly event: IMouseEvent;541readonly target: IMouseTarget | null;542}543544/**545* A paste event originating from the editor.546*/547export interface IPasteEvent {548readonly range: Range;549readonly languageId: string | null;550readonly clipboardEvent?: ClipboardEvent;551}552553/**554* @internal555*/556export interface PastePayload {557text: string;558pasteOnNewLine: boolean;559multicursorText: string[] | null;560mode: string | null;561clipboardEvent?: ClipboardEvent;562}563564/**565* An overview ruler566* @internal567*/568export interface IOverviewRuler {569getDomNode(): HTMLElement;570dispose(): void;571setZones(zones: OverviewRulerZone[]): void;572setLayout(position: OverviewRulerPosition): void;573}574575/**576* Editor aria options.577* @internal578*/579export interface IEditorAriaOptions {580activeDescendant: string | undefined;581role?: string;582}583584export interface IDiffEditorConstructionOptions extends IDiffEditorOptions, IEditorConstructionOptions {585/**586* Place overflow widgets inside an external DOM node.587* Defaults to an internal DOM node.588*/589overflowWidgetsDomNode?: HTMLElement;590591/**592* Aria label for original editor.593*/594originalAriaLabel?: string;595596/**597* Aria label for modified editor.598*/599modifiedAriaLabel?: string;600}601602/**603* A rich code editor.604*/605export interface ICodeEditor extends editorCommon.IEditor {606/**607* This editor is used as an alternative to an <input> box, i.e. as a simple widget.608* @internal609*/610readonly isSimpleWidget: boolean;611/**612* The context menu ID that should be used to lookup context menu actions.613* @internal614*/615readonly contextMenuId: MenuId;616/**617* The editor's scoped context key service.618* @internal619*/620readonly contextKeyService: IContextKeyService;621/**622* An event emitted when the content of the current model has changed.623* @event624*/625readonly onDidChangeModelContent: Event<IModelContentChangedEvent>;626/**627* An event emitted when the language of the current model has changed.628* @event629*/630readonly onDidChangeModelLanguage: Event<IModelLanguageChangedEvent>;631/**632* An event emitted when the language configuration of the current model has changed.633* @event634*/635readonly onDidChangeModelLanguageConfiguration: Event<IModelLanguageConfigurationChangedEvent>;636/**637* An event emitted when the options of the current model has changed.638* @event639*/640readonly onDidChangeModelOptions: Event<IModelOptionsChangedEvent>;641/**642* An event emitted when the configuration of the editor has changed. (e.g. `editor.updateOptions()`)643* @event644*/645readonly onDidChangeConfiguration: Event<ConfigurationChangedEvent>;646/**647* An event emitted when the cursor position has changed.648* @event649*/650readonly onDidChangeCursorPosition: Event<ICursorPositionChangedEvent>;651/**652* An event emitted when the cursor selection has changed.653* @event654*/655readonly onDidChangeCursorSelection: Event<ICursorSelectionChangedEvent>;656/**657* An event emitted when the model of this editor is about to change (e.g. from `editor.setModel()`).658* @event659*/660readonly onWillChangeModel: Event<editorCommon.IModelChangedEvent>;661/**662* An event emitted when the model of this editor has changed (e.g. `editor.setModel()`).663* @event664*/665readonly onDidChangeModel: Event<editorCommon.IModelChangedEvent>;666/**667* An event emitted when the decorations of the current model have changed.668* @event669*/670readonly onDidChangeModelDecorations: Event<IModelDecorationsChangedEvent>;671/**672* An event emitted when the tokens of the current model have changed.673* @internal674*/675readonly onDidChangeModelTokens: Event<IModelTokensChangedEvent>;676/**677* An event emitted when the text inside this editor gained focus (i.e. cursor starts blinking).678* @event679*/680readonly onDidFocusEditorText: Event<void>;681/**682* An event emitted when the text inside this editor lost focus (i.e. cursor stops blinking).683* @event684*/685readonly onDidBlurEditorText: Event<void>;686/**687* An event emitted when the text inside this editor or an editor widget gained focus.688* @event689*/690readonly onDidFocusEditorWidget: Event<void>;691/**692* An event emitted when the text inside this editor or an editor widget lost focus.693* @event694*/695readonly onDidBlurEditorWidget: Event<void>;696/**697* An event emitted before interpreting typed characters (on the keyboard).698* @event699* @internal700*/701readonly onWillType: Event<string>;702/**703* An event emitted after interpreting typed characters (on the keyboard).704* @event705* @internal706*/707readonly onDidType: Event<string>;708/**709* Boolean indicating whether input is in composition710*/711readonly inComposition: boolean;712/**713* An event emitted after composition has started.714*/715readonly onDidCompositionStart: Event<void>;716/**717* An event emitted after composition has ended.718*/719readonly onDidCompositionEnd: Event<void>;720/**721* An event emitted when editing failed because the editor is read-only.722* @event723*/724readonly onDidAttemptReadOnlyEdit: Event<void>;725/**726* An event emitted when users paste text in the editor.727* @event728*/729readonly onDidPaste: Event<IPasteEvent>;730/**731* An event emitted before clipboard copy operation starts.732* @internal733* @event734*/735readonly onWillCopy: Event<IClipboardCopyEvent>;736/**737* An event emitted before clipboard cut operation starts.738* @internal739* @event740*/741readonly onWillCut: Event<IClipboardCopyEvent>;742/**743* An event emitted before clipboard paste operation starts.744* @internal745* @event746*/747readonly onWillPaste: Event<IClipboardPasteEvent>;748/**749* An event emitted on a "mouseup".750* @event751*/752readonly onMouseUp: Event<IEditorMouseEvent>;753/**754* An event emitted on a "mousedown".755* @event756*/757readonly onMouseDown: Event<IEditorMouseEvent>;758/**759* An event emitted on a "mousedrag".760* @internal761* @event762*/763readonly onMouseDrag: Event<IEditorMouseEvent>;764/**765* An event emitted on a "mousedrop".766* @internal767* @event768*/769readonly onMouseDrop: Event<IPartialEditorMouseEvent>;770/**771* An event emitted on a "mousedropcanceled".772* @internal773* @event774*/775readonly onMouseDropCanceled: Event<void>;776/**777* An event emitted when content is dropped into the editor.778* @internal779* @event780*/781readonly onDropIntoEditor: Event<{ readonly position: IPosition; readonly event: DragEvent }>;782/**783* An event emitted on a "contextmenu".784* @event785*/786readonly onContextMenu: Event<IEditorMouseEvent>;787/**788* An event emitted on a "mousemove".789* @event790*/791readonly onMouseMove: Event<IEditorMouseEvent>;792/**793* An event emitted on a "mouseleave".794* @event795*/796readonly onMouseLeave: Event<IPartialEditorMouseEvent>;797/**798* An event emitted on a "mousewheel"799* @event800* @internal801*/802readonly onMouseWheel: Event<IMouseWheelEvent>;803/**804* An event emitted on a "keyup".805* @event806*/807readonly onKeyUp: Event<IKeyboardEvent>;808/**809* An event emitted on a "keydown".810* @event811*/812readonly onKeyDown: Event<IKeyboardEvent>;813/**814* An event emitted when the layout of the editor has changed.815* @event816*/817readonly onDidLayoutChange: Event<EditorLayoutInfo>;818/**819* An event emitted when the content width or content height in the editor has changed.820* @event821*/822readonly onDidContentSizeChange: Event<editorCommon.IContentSizeChangedEvent>;823/**824* An event emitted when the scroll in the editor has changed.825* @event826*/827readonly onDidScrollChange: Event<editorCommon.IScrollEvent>;828829/**830* An event emitted when hidden areas change in the editor (e.g. due to folding).831* @event832*/833readonly onDidChangeHiddenAreas: Event<void>;834835/**836* An event emitted before an editor837* @internal838*/839readonly onWillTriggerEditorOperationEvent: Event<editorCommon.ITriggerEditorOperationEvent>;840841/**842* Some editor operations fire multiple events at once.843* To allow users to react to multiple events fired by a single operation,844* the editor fires a begin update before the operation and an end update after the operation.845* Whenever the editor fires `onBeginUpdate`, it will also fire `onEndUpdate` once the operation finishes.846* Note that not all operations are bracketed by `onBeginUpdate` and `onEndUpdate`.847*/848readonly onBeginUpdate: Event<void>;849850/**851* Fires after the editor completes the operation it fired `onBeginUpdate` for.852*/853readonly onEndUpdate: Event<void>;854855readonly onDidChangeViewZones: Event<void>;856857/**858* Saves current view state of the editor in a serializable object.859*/860saveViewState(): editorCommon.ICodeEditorViewState | null;861862/**863* Restores the view state of the editor from a serializable object generated by `saveViewState`.864*/865restoreViewState(state: editorCommon.ICodeEditorViewState | null): void;866867/**868* Returns true if the text inside this editor or an editor widget has focus.869*/870hasWidgetFocus(): boolean;871872/**873* Get a contribution of this editor.874* @id Unique identifier of the contribution.875* @return The contribution or null if contribution not found.876*/877getContribution<T extends editorCommon.IEditorContribution>(id: string): T | null;878879/**880* Execute `fn` with the editor's services.881* @internal882*/883invokeWithinContext<T>(fn: (accessor: ServicesAccessor) => T): T;884885/**886* Type the getModel() of IEditor.887*/888getModel(): ITextModel | null;889890/**891* Sets the current model attached to this editor.892* If the previous model was created by the editor via the value key in the options893* literal object, it will be destroyed. Otherwise, if the previous model was set894* via setModel, or the model key in the options literal object, the previous model895* will not be destroyed.896* It is safe to call setModel(null) to simply detach the current model from the editor.897*/898setModel(model: ITextModel | null): void;899900/**901* Gets all the editor computed options.902*/903getOptions(): IComputedEditorOptions;904905/**906* Gets a specific editor option.907*/908getOption<T extends EditorOption>(id: T): FindComputedEditorOptionValueById<T>;909910/**911* Returns the editor's configuration (without any validation or defaults).912*/913getRawOptions(): IEditorOptions;914915/**916* @internal917*/918getOverflowWidgetsDomNode(): HTMLElement | undefined;919920/**921* @internal922*/923getConfiguredWordAtPosition(position: Position): IWordAtPosition | null;924925/**926* An event emitted when line heights from decorations change927* @internal928* @event929*/930readonly onDidChangeLineHeight: Event<ModelLineHeightChangedEvent>;931932/**933* An event emitted when the font of the editor has changed.934* @internal935* @event936*/937readonly onDidChangeFont: Event<ModelFontChangedEvent>;938939/**940* Get value of the current model attached to this editor.941* @see {@link ITextModel.getValue}942*/943getValue(options?: { preserveBOM: boolean; lineEnding: string }): string;944945/**946* Set the value of the current model attached to this editor.947* @see {@link ITextModel.setValue}948*/949setValue(newValue: string): void;950951/**952* Get the width of the editor's content.953* This is information that is "erased" when computing `scrollWidth = Math.max(contentWidth, width)`954*/955getContentWidth(): number;956/**957* Get the scrollWidth of the editor's viewport.958*/959getScrollWidth(): number;960/**961* Get the scrollLeft of the editor's viewport.962*/963getScrollLeft(): number;964965/**966* Get the height of the editor's content.967* This is information that is "erased" when computing `scrollHeight = Math.max(contentHeight, height)`968*/969getContentHeight(): number;970/**971* Get the scrollHeight of the editor's viewport.972*/973getScrollHeight(): number;974/**975* Get the scrollTop of the editor's viewport.976*/977getScrollTop(): number;978979/**980* Change the scrollLeft of the editor's viewport.981*/982setScrollLeft(newScrollLeft: number, scrollType?: editorCommon.ScrollType): void;983/**984* Change the scrollTop of the editor's viewport.985*/986setScrollTop(newScrollTop: number, scrollType?: editorCommon.ScrollType): void;987/**988* Change the scroll position of the editor's viewport.989*/990setScrollPosition(position: editorCommon.INewScrollPosition, scrollType?: editorCommon.ScrollType): void;991/**992* Check if the editor is currently scrolling towards a different scroll position.993*/994hasPendingScrollAnimation(): boolean;995996/**997* Get an action that is a contribution to this editor.998* @id Unique identifier of the contribution.999* @return The action or null if action not found.1000*/1001getAction(id: string): editorCommon.IEditorAction | null;10021003/**1004* Execute a command on the editor.1005* The edits will land on the undo-redo stack, but no "undo stop" will be pushed.1006* @param source The source of the call.1007* @param command The command to execute1008*/1009executeCommand(source: string | null | undefined, command: editorCommon.ICommand): void;10101011/**1012* Create an "undo stop" in the undo-redo stack.1013*/1014pushUndoStop(): boolean;10151016/**1017* Remove the "undo stop" in the undo-redo stack.1018*/1019popUndoStop(): boolean;10201021/**1022* Execute edits on the editor.1023* The edits will land on the undo-redo stack, but no "undo stop" will be pushed.1024* @param source The source of the call.1025* @param edits The edits to execute.1026* @param endCursorState Cursor state after the edits were applied.1027*/1028executeEdits(source: string | null | undefined, edits: IIdentifiedSingleEditOperation[], endCursorState?: ICursorStateComputer | Selection[]): boolean;1029/** @internal */1030executeEdits(source: TextModelEditSource | undefined, edits: IIdentifiedSingleEditOperation[], endCursorState?: ICursorStateComputer | Selection[]): boolean;10311032/**1033* @internal1034*/1035edit(edit: TextEdit, reason: TextModelEditSource): void;10361037/**1038* Execute multiple (concomitant) commands on the editor.1039* @param source The source of the call.1040* @param command The commands to execute1041*/1042executeCommands(source: string | null | undefined, commands: (editorCommon.ICommand | null)[]): void;10431044/**1045* Scroll vertically or horizontally as necessary and reveal the current cursors.1046*/1047revealAllCursors(revealHorizontal: boolean, minimalReveal?: boolean): void;10481049/**1050* @internal1051*/1052_getViewModel(): IViewModel | null;10531054/**1055* Get all the decorations on a line (filtering out decorations from other editors).1056*/1057getLineDecorations(lineNumber: number): IModelDecoration[] | null;10581059/**1060* Get all the decorations for a range (filtering out decorations from other editors).1061*/1062getDecorationsInRange(range: Range): IModelDecoration[] | null;10631064/**1065* Get the font size at a given position1066* @param position the position for which to fetch the font size1067*/1068getFontSizeAtPosition(position: IPosition): string | null;10691070/**1071* All decorations added through this call will get the ownerId of this editor.1072* @deprecated Use `createDecorationsCollection`1073* @see createDecorationsCollection1074*/1075deltaDecorations(oldDecorations: string[], newDecorations: IModelDeltaDecoration[]): string[];10761077/**1078* Remove previously added decorations.1079*/1080removeDecorations(decorationIds: string[]): void;10811082/**1083* @internal1084*/1085setDecorationsByType(description: string, decorationTypeKey: string, ranges: editorCommon.IDecorationOptions[]): readonly string[];10861087/**1088* @internal1089*/1090setDecorationsByTypeFast(decorationTypeKey: string, ranges: IRange[]): void;10911092/**1093* @internal1094*/1095removeDecorationsByType(decorationTypeKey: string): void;10961097/**1098* Get the layout info for the editor.1099*/1100getLayoutInfo(): EditorLayoutInfo;11011102/**1103* Returns the ranges that are currently visible.1104* Does not account for horizontal scrolling.1105*/1106getVisibleRanges(): Range[];11071108/**1109* @internal1110*/1111getVisibleRangesPlusViewportAboveBelow(): Range[];11121113/**1114* Get the view zones.1115* @internal1116*/1117getWhitespaces(): IEditorWhitespace[];11181119/**1120* Get the vertical position (top offset) for the line's top w.r.t. to the first line.1121*/1122getTopForLineNumber(lineNumber: number, includeViewZones?: boolean): number;11231124/**1125* Get the vertical position (top offset) for the line's bottom w.r.t. to the first line.1126*/1127getBottomForLineNumber(lineNumber: number): number;11281129/**1130* Get the vertical position (top offset) for the position w.r.t. to the first line.1131*/1132getTopForPosition(lineNumber: number, column: number): number;11331134/**1135* Get the line height for a model position.1136*/1137getLineHeightForPosition(position: IPosition): number;11381139/**1140* Set the model ranges that will be hidden in the view.1141* Hidden areas are stored per source.1142* @internal1143*/1144setHiddenAreas(ranges: IRange[], source?: unknown): void;11451146/**1147* Sets the editor aria options, primarily the active descendent.1148* @internal1149*/1150setAriaOptions(options: IEditorAriaOptions): void;11511152/**1153* Write the screen reader content to be the current selection1154*/1155writeScreenReaderContent(reason: string): void;11561157/**1158* @internal1159*/1160getTelemetryData(): object | undefined;11611162/**1163* Returns the editor's container dom node1164*/1165getContainerDomNode(): HTMLElement;11661167/**1168* Returns the editor's dom node1169*/1170getDomNode(): HTMLElement | null;11711172/**1173* Add a content widget. Widgets must have unique ids, otherwise they will be overwritten.1174*/1175addContentWidget(widget: IContentWidget): void;1176/**1177* Layout/Reposition a content widget. This is a ping to the editor to call widget.getPosition()1178* and update appropriately.1179*/1180layoutContentWidget(widget: IContentWidget): void;1181/**1182* Remove a content widget.1183*/1184removeContentWidget(widget: IContentWidget): void;11851186/**1187* Add an overlay widget. Widgets must have unique ids, otherwise they will be overwritten.1188*/1189addOverlayWidget(widget: IOverlayWidget): void;1190/**1191* Layout/Reposition an overlay widget. This is a ping to the editor to call widget.getPosition()1192* and update appropriately.1193*/1194layoutOverlayWidget(widget: IOverlayWidget): void;1195/**1196* Remove an overlay widget.1197*/1198removeOverlayWidget(widget: IOverlayWidget): void;11991200/**1201* Add a glyph margin widget. Widgets must have unique ids, otherwise they will be overwritten.1202*/1203addGlyphMarginWidget(widget: IGlyphMarginWidget): void;1204/**1205* Layout/Reposition a glyph margin widget. This is a ping to the editor to call widget.getPosition()1206* and update appropriately.1207*/1208layoutGlyphMarginWidget(widget: IGlyphMarginWidget): void;1209/**1210* Remove a glyph margin widget.1211*/1212removeGlyphMarginWidget(widget: IGlyphMarginWidget): void;12131214/**1215* Change the view zones. View zones are lost when a new model is attached to the editor.1216*/1217changeViewZones(callback: (accessor: IViewZoneChangeAccessor) => void): void;12181219/**1220* Get the horizontal position (left offset) for the column w.r.t to the beginning of the line.1221* This method works only if the line `lineNumber` is currently rendered (in the editor's viewport).1222* Use this method with caution.1223*/1224getOffsetForColumn(lineNumber: number, column: number): number;12251226getWidthOfLine(lineNumber: number): number;12271228/**1229* Reset cached line widths. Call this when the editor becomes visible after being hidden.1230* @internal1231*/1232resetLineWidthCaches(): void;12331234/**1235* Force an editor render now.1236*/1237render(forceRedraw?: boolean): void;12381239/**1240* Render the editor at the next animation frame.1241*/1242renderAsync(forceRedraw?: boolean): void;12431244/**1245* Get the hit test target at coordinates `clientX` and `clientY`.1246* The coordinates are relative to the top-left of the viewport.1247*1248* @returns Hit test target or null if the coordinates fall outside the editor or the editor has no model.1249*/1250getTargetAtClientPoint(clientX: number, clientY: number): IMouseTarget | null;12511252/**1253* Get the visible position for `position`.1254* The result position takes scrolling into account and is relative to the top left corner of the editor.1255* Explanation 1: the results of this method will change for the same `position` if the user scrolls the editor.1256* Explanation 2: the results of this method will not change if the container of the editor gets repositioned.1257* Warning: the results of this method are inaccurate for positions that are outside the current editor viewport.1258*/1259getScrolledVisiblePosition(position: IPosition): { top: number; left: number; height: number } | null;12601261/**1262* Apply the same font settings as the editor to `target`.1263*/1264applyFontInfo(target: HTMLElement): void;12651266/**1267* Check if the current instance has a model attached.1268* @internal1269*/1270hasModel(): this is IActiveCodeEditor;12711272setBanner(bannerDomNode: HTMLElement | null, height: number): void;12731274/**1275* Is called when the model has been set, view state was restored and options are updated.1276* This is the best place to compute data for the viewport (such as tokens).1277*/1278handleInitialized?(): void;1279}12801281/**1282* @internal1283*/1284export interface IActiveCodeEditor extends ICodeEditor {1285/**1286* Returns the primary position of the cursor.1287*/1288getPosition(): Position;12891290/**1291* Returns the primary selection of the editor.1292*/1293getSelection(): Selection;12941295/**1296* Returns all the selections of the editor.1297*/1298getSelections(): Selection[];12991300/**1301* Saves current view state of the editor in a serializable object.1302*/1303saveViewState(): editorCommon.ICodeEditorViewState;13041305/**1306* Type the getModel() of IEditor.1307*/1308getModel(): ITextModel;13091310/**1311* @internal1312*/1313_getViewModel(): IViewModel;13141315/**1316* Get all the decorations on a line (filtering out decorations from other editors).1317*/1318getLineDecorations(lineNumber: number): IModelDecoration[];13191320/**1321* Returns the editor's dom node1322*/1323getDomNode(): HTMLElement;13241325/**1326* Get the visible position for `position`.1327* The result position takes scrolling into account and is relative to the top left corner of the editor.1328* Explanation 1: the results of this method will change for the same `position` if the user scrolls the editor.1329* Explanation 2: the results of this method will not change if the container of the editor gets repositioned.1330* Warning: the results of this method are inaccurate for positions that are outside the current editor viewport.1331*/1332getScrolledVisiblePosition(position: IPosition): { top: number; left: number; height: number };13331334/**1335* Change the decorations. All decorations added through this changeAccessor1336* will get the ownerId of the editor (meaning they will not show up in other1337* editors).1338* @see {@link ITextModel.changeDecorations}1339* @internal1340*/1341changeDecorations<T>(callback: (changeAccessor: IModelDecorationsChangeAccessor) => T): T;1342}13431344/**1345* @internal1346*/1347export const enum DiffEditorState {1348Idle,1349ComputingDiff,1350DiffComputed1351}13521353/**1354* A rich diff editor.1355*/1356export interface IDiffEditor extends editorCommon.IEditor {13571358/**1359* Returns whether the diff editor is ignoring trim whitespace or not.1360* @internal1361*/1362readonly ignoreTrimWhitespace: boolean;1363/**1364* Returns whether the diff editor is rendering side by side or inline.1365* @internal1366*/1367readonly renderSideBySide: boolean;1368/**1369* Timeout in milliseconds after which diff computation is cancelled.1370* @internal1371*/1372readonly maxComputationTime: number;13731374/**1375* @see {@link ICodeEditor.getContainerDomNode}1376*/1377getContainerDomNode(): HTMLElement;13781379/**1380* An event emitted when the diff information computed by this diff editor has been updated.1381* @event1382*/1383readonly onDidUpdateDiff: Event<void>;13841385/**1386* An event emitted when the diff model is changed (i.e. the diff editor shows new content).1387* @event1388*/1389readonly onDidChangeModel: Event<void>;13901391/**1392* Saves current view state of the editor in a serializable object.1393*/1394saveViewState(): editorCommon.IDiffEditorViewState | null;13951396/**1397* Restores the view state of the editor from a serializable object generated by `saveViewState`.1398*/1399restoreViewState(state: editorCommon.IDiffEditorViewState | null): void;14001401/**1402* Type the getModel() of IEditor.1403*/1404getModel(): editorCommon.IDiffEditorModel | null;14051406createViewModel(model: editorCommon.IDiffEditorModel): editorCommon.IDiffEditorViewModel;14071408/**1409* Sets the current model attached to this editor.1410* If the previous model was created by the editor via the value key in the options1411* literal object, it will be destroyed. Otherwise, if the previous model was set1412* via setModel, or the model key in the options literal object, the previous model1413* will not be destroyed.1414* It is safe to call setModel(null) to simply detach the current model from the editor.1415*/1416setModel(model: editorCommon.IDiffEditorModel | editorCommon.IDiffEditorViewModel | null): void;14171418/**1419* Get the `original` editor.1420*/1421getOriginalEditor(): ICodeEditor;14221423/**1424* Get the `modified` editor.1425*/1426getModifiedEditor(): ICodeEditor;14271428/**1429* Get the computed diff information.1430*/1431getLineChanges(): ILineChange[] | null;14321433/**1434* Get the computed diff information.1435* @internal1436*/1437getDiffComputationResult(): IDiffComputationResult | null;14381439/**1440* Update the editor's options after the editor has been created.1441*/1442updateOptions(newOptions: IDiffEditorOptions): void;14431444/**1445* @internal1446*/1447setBoundarySashes(sashes: IBoundarySashes): void;14481449/**1450* Jumps to the next or previous diff.1451*/1452goToDiff(target: 'next' | 'previous'): void;14531454/**1455* Scrolls to the first diff.1456* (Waits until the diff computation finished.)1457*/1458revealFirstDiff(): unknown;14591460accessibleDiffViewerNext(): void;14611462accessibleDiffViewerPrev(): void;14631464handleInitialized(): void;1465}14661467/**1468*@internal1469*/1470export function isCodeEditor(thing: unknown): thing is ICodeEditor {1471if (thing && typeof (<ICodeEditor>thing).getEditorType === 'function') {1472return (<ICodeEditor>thing).getEditorType() === editorCommon.EditorType.ICodeEditor;1473} else {1474return false;1475}1476}14771478/**1479*@internal1480*/1481export function isDiffEditor(thing: unknown): thing is IDiffEditor {1482if (thing && typeof (<IDiffEditor>thing).getEditorType === 'function') {1483return (<IDiffEditor>thing).getEditorType() === editorCommon.EditorType.IDiffEditor;1484} else {1485return false;1486}1487}14881489/**1490*@internal1491*/1492export function isCompositeEditor(thing: unknown): thing is editorCommon.ICompositeCodeEditor {1493return !!thing1494&& typeof thing === 'object'1495&& typeof (<editorCommon.ICompositeCodeEditor>thing).onDidChangeActiveEditor === 'function';14961497}14981499/**1500*@internal1501*/1502export function getCodeEditor(thing: unknown): ICodeEditor | null {1503if (isCodeEditor(thing)) {1504return thing;1505}15061507if (isDiffEditor(thing)) {1508return thing.getModifiedEditor();1509}15101511if (isCompositeEditor(thing) && isCodeEditor(thing.activeCodeEditor)) {1512return thing.activeCodeEditor;1513}15141515return null;1516}15171518/**1519*@internal1520*/1521export function getIEditor(thing: unknown): editorCommon.IEditor | null {1522if (isCodeEditor(thing) || isDiffEditor(thing)) {1523return thing;1524}15251526return null;1527}15281529/**1530*@internal1531*/1532export function isIOverlayWidgetPositionCoordinates(thing: unknown): thing is IOverlayWidgetPositionCoordinates {1533return !!thing1534&& typeof thing === 'object'1535&& typeof (<IOverlayWidgetPositionCoordinates>thing).top === 'number'1536&& typeof (<IOverlayWidgetPositionCoordinates>thing).left === 'number';1537}153815391540