Interface ICodeEditor

A rich code editor.

Hierarchy

Events

Properties

Methods

addContentWidget addGlyphMarginWidget addOverlayWidget applyFontInfo changeViewZones 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

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

Properties

onDidCompositionEnd: IEvent<void>

An event emitted after composition has ended.

onDidCompositionStart: IEvent<void>

An event emitted after composition has started.

Methods

  • 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

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

    Deprecated

    Use createDecorationsCollection

    See

    createDecorationsCollection

    Parameters

    Returns string[]

  • 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

  • Brings browser focus to the editor text

    Returns void

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

    Id

    Unique identifier of the contribution.

    Returns

    The action or null if action not found.

    Parameters

    • id: string

    Returns IEditorAction

  • 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.

    Id

    Unique identifier of the contribution.

    Returns

    The contribution or null if contribution not found.

    Type Parameters

    Parameters

    • id: string

    Returns T

  • Get all the decorations for a range (filtering out decorations from other editors).

    Parameters

    Returns IModelDecoration[]

  • 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 all the decorations on a line (filtering out decorations from other editors).

    Parameters

    • lineNumber: number

    Returns IModelDecoration[]

  • 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

  • Returns the editor's configuration (without any validation or defaults).

    Returns IEditorOptions

  • 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.

    Returns

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

    Parameters

    • clientX: number
    • clientY: number

    Returns IMouseTarget

  • 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.

    See

    getValue

    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 a content widget.

    Parameters

    Returns void

  • Remove previously added decorations.

    Parameters

    • decorationIds: string[]

    Returns void

  • Remove an overlay widget.

    Parameters

    Returns void

  • Force an editor render now.

    Parameters

    • Optional forceRedraw: boolean

    Returns void

  • Scroll vertically as necessary and reveal a line.

    Parameters

    • lineNumber: number
    • Optional scrollType: ScrollType

    Returns void

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

    Parameters

    • lineNumber: number
    • Optional scrollType: ScrollType

    Returns void

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

    Parameters

    • lineNumber: number
    • Optional scrollType: ScrollType

    Returns void

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

    Parameters

    • lineNumber: number
    • Optional scrollType: ScrollType

    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 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 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.

    See

    setValue

    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