Interface IStandaloneCodeEditor

A rich code editor.

interface IStandaloneCodeEditor {
    onBeginUpdate: IEvent<void>;
    onContextMenu: IEvent<IEditorMouseEvent>;
    onDidAttemptReadOnlyEdit: IEvent<void>;
    onDidBlurEditorText: IEvent<void>;
    onDidBlurEditorWidget: IEvent<void>;
    onDidChangeConfiguration: IEvent<ConfigurationChangedEvent>;
    onDidChangeCursorPosition: IEvent<ICursorPositionChangedEvent>;
    onDidChangeCursorSelection: IEvent<ICursorSelectionChangedEvent>;
    onDidChangeHiddenAreas: IEvent<void>;
    onDidChangeModel: IEvent<IModelChangedEvent>;
    onDidChangeModelContent: IEvent<IModelContentChangedEvent>;
    onDidChangeModelDecorations: IEvent<IModelDecorationsChangedEvent>;
    onDidChangeModelLanguage: IEvent<IModelLanguageChangedEvent>;
    onDidChangeModelLanguageConfiguration: IEvent<IModelLanguageConfigurationChangedEvent>;
    onDidChangeModelOptions: IEvent<IModelOptionsChangedEvent>;
    onDidCompositionEnd: IEvent<void>;
    onDidCompositionStart: IEvent<void>;
    onDidContentSizeChange: IEvent<IContentSizeChangedEvent>;
    onDidFocusEditorText: IEvent<void>;
    onDidFocusEditorWidget: IEvent<void>;
    onDidLayoutChange: IEvent<EditorLayoutInfo>;
    onDidPaste: IEvent<IPasteEvent>;
    onDidScrollChange: IEvent<IScrollEvent>;
    onEndUpdate: IEvent<void>;
    onKeyDown: IEvent<IKeyboardEvent>;
    onKeyUp: IEvent<IKeyboardEvent>;
    onMouseDown: IEvent<IEditorMouseEvent>;
    onMouseLeave: IEvent<IPartialEditorMouseEvent>;
    onMouseMove: IEvent<IEditorMouseEvent>;
    onMouseUp: IEvent<IEditorMouseEvent>;
    onWillChangeModel: IEvent<IModelChangedEvent>;
    addAction(descriptor): IDisposable;
    addCommand(keybinding, handler, context?): string;
    addContentWidget(widget): void;
    addGlyphMarginWidget(widget): void;
    addOverlayWidget(widget): void;
    applyFontInfo(target): void;
    changeViewZones(callback): void;
    createContextKey<T>(key, defaultValue): IContextKey<T>;
    createDecorationsCollection(decorations?): IEditorDecorationsCollection;
    deltaDecorations(oldDecorations, newDecorations): string[];
    dispose(): void;
    executeCommand(source, command): void;
    executeCommands(source, commands): void;
    executeEdits(source, edits, endCursorState?): boolean;
    focus(): void;
    getAction(id): IEditorAction;
    getBottomForLineNumber(lineNumber): number;
    getContainerDomNode(): HTMLElement;
    getContentHeight(): number;
    getContentWidth(): number;
    getContribution<T>(id): T;
    getDecorationsInRange(range): IModelDecoration[];
    getDomNode(): HTMLElement;
    getEditorType(): string;
    getId(): string;
    getLayoutInfo(): EditorLayoutInfo;
    getLineDecorations(lineNumber): IModelDecoration[];
    getModel(): ITextModel;
    getOffsetForColumn(lineNumber, column): number;
    getOption<T>(id): FindComputedEditorOptionValueById<T>;
    getOptions(): IComputedEditorOptions;
    getPosition(): Position;
    getRawOptions(): IEditorOptions;
    getScrollHeight(): number;
    getScrollLeft(): number;
    getScrollTop(): number;
    getScrollWidth(): number;
    getScrolledVisiblePosition(position): {
        height: number;
        left: number;
        top: number;
    };
    getSelection(): Selection;
    getSelections(): Selection[];
    getSupportedActions(): IEditorAction[];
    getTargetAtClientPoint(clientX, clientY): IMouseTarget;
    getTopForLineNumber(lineNumber, includeViewZones?): number;
    getTopForPosition(lineNumber, column): number;
    getValue(options?): string;
    getVisibleColumnFromPosition(position): number;
    getVisibleRanges(): Range[];
    handleInitialized?(): void;
    hasPendingScrollAnimation(): boolean;
    hasTextFocus(): boolean;
    hasWidgetFocus(): boolean;
    layout(dimension?, postponeRendering?): void;
    layoutContentWidget(widget): void;
    layoutGlyphMarginWidget(widget): void;
    layoutOverlayWidget(widget): void;
    onDidDispose(listener): IDisposable;
    popUndoStop(): boolean;
    pushUndoStop(): boolean;
    removeContentWidget(widget): void;
    removeDecorations(decorationIds): void;
    removeGlyphMarginWidget(widget): void;
    removeOverlayWidget(widget): void;
    render(forceRedraw?): void;
    restoreViewState(state): void;
    revealLine(lineNumber, scrollType?): void;
    revealLineInCenter(lineNumber, scrollType?): void;
    revealLineInCenterIfOutsideViewport(lineNumber, scrollType?): void;
    revealLineNearTop(lineNumber, scrollType?): void;
    revealLines(startLineNumber, endLineNumber, scrollType?): void;
    revealLinesInCenter(lineNumber, endLineNumber, scrollType?): void;
    revealLinesInCenterIfOutsideViewport(lineNumber, endLineNumber, scrollType?): void;
    revealLinesNearTop(lineNumber, endLineNumber, scrollType?): void;
    revealPosition(position, scrollType?): void;
    revealPositionInCenter(position, scrollType?): void;
    revealPositionInCenterIfOutsideViewport(position, scrollType?): void;
    revealPositionNearTop(position, scrollType?): void;
    revealRange(range, scrollType?): void;
    revealRangeAtTop(range, scrollType?): void;
    revealRangeInCenter(range, scrollType?): void;
    revealRangeInCenterIfOutsideViewport(range, scrollType?): void;
    revealRangeNearTop(range, scrollType?): void;
    revealRangeNearTopIfOutsideViewport(range, scrollType?): void;
    saveViewState(): ICodeEditorViewState;
    setBanner(bannerDomNode, height): void;
    setModel(model): void;
    setPosition(position, source?): void;
    setScrollLeft(newScrollLeft, scrollType?): void;
    setScrollPosition(position, scrollType?): void;
    setScrollTop(newScrollTop, scrollType?): void;
    setSelection(selection, source?): void;
    setSelection(selection, source?): void;
    setSelection(selection, source?): void;
    setSelection(selection, source?): void;
    setSelections(selections, source?): void;
    setValue(newValue): void;
    trigger(source, handlerId, payload): void;
    updateOptions(newOptions): void;
    writeScreenReaderContent(reason): void;
}

Hierarchy (view full)

Properties

Methods

addAction addCommand addContentWidget addGlyphMarginWidget addOverlayWidget applyFontInfo changeViewZones createContextKey createDecorationsCollection deltaDecorations dispose executeCommand executeCommands executeEdits focus getAction getBottomForLineNumber getContainerDomNode getContentHeight getContentWidth getContribution getDecorationsInRange getDomNode getEditorType getId getLayoutInfo getLineDecorations getModel getOffsetForColumn getOption getOptions getPosition getRawOptions getScrollHeight getScrollLeft getScrollTop getScrollWidth getScrolledVisiblePosition getSelection getSelections getSupportedActions getTargetAtClientPoint getTopForLineNumber getTopForPosition getValue getVisibleColumnFromPosition getVisibleRanges handleInitialized? hasPendingScrollAnimation hasTextFocus hasWidgetFocus layout layoutContentWidget layoutGlyphMarginWidget layoutOverlayWidget popUndoStop pushUndoStop removeContentWidget removeDecorations removeGlyphMarginWidget removeOverlayWidget render restoreViewState revealLine revealLineInCenter revealLineInCenterIfOutsideViewport revealLineNearTop revealLines revealLinesInCenter revealLinesInCenterIfOutsideViewport revealLinesNearTop revealPosition revealPositionInCenter revealPositionInCenterIfOutsideViewport revealPositionNearTop revealRange revealRangeAtTop revealRangeInCenter revealRangeInCenterIfOutsideViewport revealRangeNearTop revealRangeNearTopIfOutsideViewport saveViewState setBanner setModel setPosition setScrollLeft setScrollPosition setScrollTop setSelection setSelections setValue trigger updateOptions writeScreenReaderContent

Events

Properties

onBeginUpdate: IEvent<void>

Some editor operations fire multiple events at once. To allow users to react to multiple events fired by a single operation, the editor fires a begin update before the operation and an end update after the operation. Whenever the editor fires onBeginUpdate, it will also fire onEndUpdate once the operation finishes. Note that not all operations are bracketed by onBeginUpdate and onEndUpdate.

onDidCompositionEnd: IEvent<void>

An event emitted after composition has ended.

onDidCompositionStart: IEvent<void>

An event emitted after composition has started.

onEndUpdate: IEvent<void>

Fires after the editor completes the operation it fired onBeginUpdate for.

Methods

  • Parameters

    Returns string

  • Add a content widget. Widgets must have unique ids, otherwise they will be overwritten.

    Parameters

    Returns void

  • Add a glyph margin widget. Widgets must have unique ids, otherwise they will be overwritten.

    Parameters

    Returns void

  • Add an overlay widget. Widgets must have unique ids, otherwise they will be overwritten.

    Parameters

    Returns void

  • Apply the same font settings as the editor to target.

    Parameters

    • target: HTMLElement

    Returns void

  • Change the view zones. View zones are lost when a new model is attached to the editor.

    Parameters

    Returns void

  • All decorations added through this call will get the ownerId of this editor.

    Parameters

    Returns string[]

    Deprecated

    Use createDecorationsCollection

    See

    createDecorationsCollection

  • Dispose the editor.

    Returns void

  • Execute a command on the editor. The edits will land on the undo-redo stack, but no "undo stop" will be pushed.

    Parameters

    • source: string

      The source of the call.

    • command: ICommand

      The command to execute

    Returns void

  • Execute multiple (concomitant) commands on the editor.

    Parameters

    • source: string

      The source of the call.

    • commands: ICommand[]

    Returns void

  • Execute edits on the editor. The edits will land on the undo-redo stack, but no "undo stop" will be pushed.

    Parameters

    Returns boolean

  • Brings browser focus to the editor text

    Returns void

  • Get an action that is a contribution to this editor.

    Parameters

    • id: string

    Returns IEditorAction

    The action or null if action not found.

    Id

    Unique identifier of the contribution.

  • Get the vertical position (top offset) for the line's bottom w.r.t. to the first line.

    Parameters

    • lineNumber: number

    Returns number

  • Returns the editor's container dom node

    Returns HTMLElement

  • Get the height of the editor's content. This is information that is "erased" when computing scrollHeight = Math.max(contentHeight, height)

    Returns number

  • Get the width of the editor's content. This is information that is "erased" when computing scrollWidth = Math.max(contentWidth, width)

    Returns number

  • Get a contribution of this editor.

    Type Parameters

    Parameters

    • id: string

    Returns T

    The contribution or null if contribution not found.

    Id

    Unique identifier of the contribution.

  • Returns the editor's dom node

    Returns HTMLElement

  • Get the editor type. Please see EditorType. This is to avoid an instanceof check

    Returns string

  • Get a unique id for this editor instance.

    Returns string

  • Get the horizontal position (left offset) for the column w.r.t to the beginning of the line. This method works only if the line lineNumber is currently rendered (in the editor's viewport). Use this method with caution.

    Parameters

    • lineNumber: number
    • column: number

    Returns number

  • Get the scrollHeight of the editor's viewport.

    Returns number

  • Get the scrollLeft of the editor's viewport.

    Returns number

  • Get the scrollTop of the editor's viewport.

    Returns number

  • Get the scrollWidth of the editor's viewport.

    Returns number

  • Get the visible position for position. The result position takes scrolling into account and is relative to the top left corner of the editor. Explanation 1: the results of this method will change for the same position if the user scrolls the editor. Explanation 2: the results of this method will not change if the container of the editor gets repositioned. Warning: the results of this method are inaccurate for positions that are outside the current editor viewport.

    Parameters

    Returns {
        height: number;
        left: number;
        top: number;
    }

    • height: number
    • left: number
    • top: number
  • Get the hit test target at coordinates clientX and clientY. The coordinates are relative to the top-left of the viewport.

    Parameters

    • clientX: number
    • clientY: number

    Returns IMouseTarget

    Hit test target or null if the coordinates fall outside the editor or the editor has no model.

  • Get the vertical position (top offset) for the line's top w.r.t. to the first line.

    Parameters

    • lineNumber: number
    • Optional includeViewZones: boolean

    Returns number

  • Get the vertical position (top offset) for the position w.r.t. to the first line.

    Parameters

    • lineNumber: number
    • column: number

    Returns number

  • Get value of the current model attached to this editor.

    Parameters

    • Optional options: {
          lineEnding: string;
          preserveBOM: boolean;
      }
      • lineEnding: string
      • preserveBOM: boolean

    Returns string

  • Given a position, returns a column number that takes tab-widths into account.

    Parameters

    Returns number

  • Returns the ranges that are currently visible. Does not account for horizontal scrolling.

    Returns Range[]

  • Is called when the model has been set, view state was restored and options are updated. This is the best place to compute data for the viewport (such as tokens).

    Returns void

  • Check if the editor is currently scrolling towards a different scroll position.

    Returns boolean

  • Returns true if the text inside this editor is focused (i.e. cursor is blinking).

    Returns boolean

  • Returns true if the text inside this editor or an editor widget has focus.

    Returns boolean

  • Instructs the editor to remeasure its container. This method should be called when the container of the editor gets resized.

    If a dimension is passed in, the passed in value will be used.

    By default, this will also render the editor immediately. If you prefer to delay rendering to the next animation frame, use postponeRendering == true.

    Parameters

    • Optional dimension: IDimension
    • Optional postponeRendering: boolean

    Returns void

  • Layout/Reposition a content widget. This is a ping to the editor to call widget.getPosition() and update appropriately.

    Parameters

    Returns void

  • Layout/Reposition a glyph margin widget. This is a ping to the editor to call widget.getPosition() and update appropriately.

    Parameters

    Returns void

  • Layout/Reposition an overlay widget. This is a ping to the editor to call widget.getPosition() and update appropriately.

    Parameters

    Returns void

  • Remove the "undo stop" in the undo-redo stack.

    Returns boolean

  • Create an "undo stop" in the undo-redo stack.

    Returns boolean

  • Remove previously added decorations.

    Parameters

    • decorationIds: string[]

    Returns void

  • Force an editor render now.

    Parameters

    • Optional forceRedraw: boolean

    Returns void

  • Restores the view state of the editor from a serializable object generated by saveViewState.

    Parameters

    Returns void

  • Scroll vertically as necessary and reveal a line.

    Parameters

    Returns void

  • Scroll vertically as necessary and reveal a line centered vertically.

    Parameters

    Returns void

  • Scroll vertically as necessary and reveal a line centered vertically only if it lies outside the viewport.

    Parameters

    Returns void

  • Scroll vertically as necessary and reveal a line close to the top of the viewport, optimized for viewing a code definition.

    Parameters

    Returns void

  • Scroll vertically as necessary and reveal lines.

    Parameters

    • startLineNumber: number
    • endLineNumber: number
    • Optional scrollType: ScrollType

    Returns void

  • Scroll vertically as necessary and reveal lines centered vertically.

    Parameters

    • lineNumber: number
    • endLineNumber: number
    • Optional scrollType: ScrollType

    Returns void

  • Scroll vertically as necessary and reveal lines centered vertically only if it lies outside the viewport.

    Parameters

    • lineNumber: number
    • endLineNumber: number
    • Optional scrollType: ScrollType

    Returns void

  • Scroll vertically as necessary and reveal lines close to the top of the viewport, optimized for viewing a code definition.

    Parameters

    • lineNumber: number
    • endLineNumber: number
    • Optional scrollType: ScrollType

    Returns void

  • Scroll vertically or horizontally as necessary and reveal a position.

    Parameters

    Returns void

  • Scroll vertically or horizontally as necessary and reveal a position centered vertically.

    Parameters

    Returns void

  • Scroll vertically or horizontally as necessary and reveal a position centered vertically only if it lies outside the viewport.

    Parameters

    Returns void

  • Scroll vertically or horizontally as necessary and reveal a position close to the top of the viewport, optimized for viewing a code definition.

    Parameters

    Returns void

  • Scroll vertically or horizontally as necessary and reveal a range.

    Parameters

    Returns void

  • Scroll vertically or horizontally as necessary and reveal a range at the top of the viewport.

    Parameters

    Returns void

  • Scroll vertically or horizontally as necessary and reveal a range centered vertically.

    Parameters

    Returns void

  • Scroll vertically or horizontally as necessary and reveal a range centered vertically only if it lies outside the viewport.

    Parameters

    Returns void

  • Scroll vertically or horizontally as necessary and reveal a range close to the top of the viewport, optimized for viewing a code definition.

    Parameters

    Returns void

  • Scroll vertically or horizontally as necessary and reveal a range close to the top of the viewport, optimized for viewing a code definition. Only if it lies outside the viewport.

    Parameters

    Returns void

  • Parameters

    • bannerDomNode: HTMLElement
    • height: number

    Returns void

  • Sets the current model attached to this editor. If the previous model was created by the editor via the value key in the options literal object, it will be destroyed. Otherwise, if the previous model was set via setModel, or the model key in the options literal object, the previous model will not be destroyed. It is safe to call setModel(null) to simply detach the current model from the editor.

    Parameters

    Returns void

  • Set the primary position of the cursor. This will remove any secondary cursors.

    Parameters

    • position: IPosition

      New primary cursor's position

    • Optional source: string

      Source of the call that caused the position

    Returns void

  • Change the scrollLeft of the editor's viewport.

    Parameters

    • newScrollLeft: number
    • Optional scrollType: ScrollType

    Returns void

  • Change the scrollTop of the editor's viewport.

    Parameters

    • newScrollTop: number
    • Optional scrollType: ScrollType

    Returns void

  • Set the primary selection of the editor. This will remove any secondary cursors.

    Parameters

    • selection: IRange

      The new selection

    • Optional source: string

      Source of the call that caused the selection

    Returns void

  • Set the primary selection of the editor. This will remove any secondary cursors.

    Parameters

    • selection: Range

      The new selection

    • Optional source: string

      Source of the call that caused the selection

    Returns void

  • Set the primary selection of the editor. This will remove any secondary cursors.

    Parameters

    • selection: ISelection

      The new selection

    • Optional source: string

      Source of the call that caused the selection

    Returns void

  • Set the primary selection of the editor. This will remove any secondary cursors.

    Parameters

    • selection: Selection

      The new selection

    • Optional source: string

      Source of the call that caused the selection

    Returns void

  • Set the selections for all the cursors of the editor. Cursors will be removed or added, as necessary.

    Parameters

    • selections: readonly ISelection[]

      The new selection

    • Optional source: string

      Source of the call that caused the selection

    Returns void

  • Set the value of the current model attached to this editor.

    Parameters

    • newValue: string

    Returns void

  • Directly trigger a handler or an editor action.

    Parameters

    • source: string

      The source of the call.

    • handlerId: string

      The id of the handler or the id of a contribution.

    • payload: any

      Extra data to be sent to the handler.

    Returns void

  • Write the screen reader content to be the current selection

    Parameters

    • reason: string

    Returns void

Events

onContextMenu: IEvent<IEditorMouseEvent>

An event emitted on a "contextmenu".

onDidAttemptReadOnlyEdit: IEvent<void>

An event emitted when editing failed because the editor is read-only.

onDidBlurEditorText: IEvent<void>

An event emitted when the text inside this editor lost focus (i.e. cursor stops blinking).

onDidBlurEditorWidget: IEvent<void>

An event emitted when the text inside this editor or an editor widget lost focus.

onDidChangeConfiguration: IEvent<ConfigurationChangedEvent>

An event emitted when the configuration of the editor has changed. (e.g. editor.updateOptions())

onDidChangeCursorPosition: IEvent<ICursorPositionChangedEvent>

An event emitted when the cursor position has changed.

onDidChangeCursorSelection: IEvent<ICursorSelectionChangedEvent>

An event emitted when the cursor selection has changed.

onDidChangeHiddenAreas: IEvent<void>

An event emitted when hidden areas change in the editor (e.g. due to folding).

onDidChangeModel: IEvent<IModelChangedEvent>

An event emitted when the model of this editor has changed (e.g. editor.setModel()).

onDidChangeModelContent: IEvent<IModelContentChangedEvent>

An event emitted when the content of the current model has changed.

onDidChangeModelDecorations: IEvent<IModelDecorationsChangedEvent>

An event emitted when the decorations of the current model have changed.

onDidChangeModelLanguage: IEvent<IModelLanguageChangedEvent>

An event emitted when the language of the current model has changed.

onDidChangeModelLanguageConfiguration: IEvent<IModelLanguageConfigurationChangedEvent>

An event emitted when the language configuration of the current model has changed.

onDidChangeModelOptions: IEvent<IModelOptionsChangedEvent>

An event emitted when the options of the current model has changed.

onDidContentSizeChange: IEvent<IContentSizeChangedEvent>

An event emitted when the content width or content height in the editor has changed.

onDidFocusEditorText: IEvent<void>

An event emitted when the text inside this editor gained focus (i.e. cursor starts blinking).

onDidFocusEditorWidget: IEvent<void>

An event emitted when the text inside this editor or an editor widget gained focus.

onDidLayoutChange: IEvent<EditorLayoutInfo>

An event emitted when the layout of the editor has changed.

onDidPaste: IEvent<IPasteEvent>

An event emitted when users paste text in the editor.

onDidScrollChange: IEvent<IScrollEvent>

An event emitted when the scroll in the editor has changed.

An event emitted on a "keydown".

An event emitted on a "keyup".

An event emitted on a "mousedown".

An event emitted on a "mouseleave".

An event emitted on a "mousemove".

An event emitted on a "mouseup".

onWillChangeModel: IEvent<IModelChangedEvent>

An event emitted when the model of this editor is about to change (e.g. from editor.setModel()).

  • An event emitted when the editor has been disposed.

    Parameters

    • listener: (() => void)
        • (): void
        • Returns void

    Returns IDisposable