Options
All
  • Public
  • Public/Protected
  • All
Menu

Class CodeMirrorEditor

CodeMirror editor. The namespace for CodeMirrorEditor statics.

Hierarchy

  • CodeMirrorEditor

Implements

  • IEditor

Index

Constructors

constructor

Properties

Private _caretHover

_caretHover: HTMLElement | null

Private _changeGuard

_changeGuard: boolean = false

Private _config

_config: IConfig

Private _editor

_editor: Editor

Private _hoverId

_hoverId: string

Private _hoverTimeout

_hoverTimeout: number

Private _isDisposed

_isDisposed: boolean = false

Private _keydownHandlers

_keydownHandlers: function[] = new Array<CodeEditor.KeydownHandler>()

Private _lastChange

_lastChange: EditorChange | null = null

Private _model

_model: IModel

Private _needsRefresh

_needsRefresh: boolean = false

Private _poll

_poll: Poll

Private _selectionStyle

_selectionStyle: ISelectionStyle

Private _uuid

_uuid: string = ""

edgeRequested

edgeRequested: Signal<this, "top" | "topLine" | "bottom"> = new Signal<this, CodeEditor.EdgeLocation>(this)

A signal emitted when either the top or bottom edge is requested.

host

host: HTMLElement

The DOM node that hosts the editor.

Protected selectionMarkers

selectionMarkers: object

Type declaration

  • [key: string]: TextMarker[] | undefined

Accessors

charWidth

  • get charWidth(): number
  • The widget of a character in the editor in pixels.

    Returns number

doc

  • get doc(): Doc
  • Get the codemirror doc wrapped by the widget.

    Returns Doc

editor

  • get editor(): Editor
  • Get the codemirror editor wrapped by the editor.

    Returns Editor

isDisposed

  • get isDisposed(): boolean
  • Tests whether the editor is disposed.

    Returns boolean

lineCount

  • get lineCount(): number
  • Get the number of lines in the editor.

    Returns number

lineHeight

  • get lineHeight(): number
  • The height of a line in the editor in pixels.

    Returns number

model

  • get model(): IModel
  • Returns a model for this editor.

    Returns IModel

selectionStyle

  • get selectionStyle(): ISelectionStyle
  • set selectionStyle(value: ISelectionStyle): void
  • The selection style of this editor.

    Returns ISelectionStyle

  • The selection style of this editor.

    Parameters

    • value: ISelectionStyle

    Returns void

state

  • get state(): any

uuid

  • get uuid(): string
  • set uuid(value: string): void
  • The uuid of this editor;

    Returns string

  • The uuid of this editor;

    Parameters

    • value: string

    Returns void

Methods

Private _beforeDocChanged

  • _beforeDocChanged(doc: Doc, change: EditorChange): void
  • Handles document changes.

    Parameters

    • doc: Doc
    • change: EditorChange

    Returns void

Private _checkSync

  • _checkSync(): void
  • Check for an out of sync editor.

    Returns void

Private _cleanSelections

  • _cleanSelections(uuid: string): void
  • Clean selections for the given uuid.

    Parameters

    • uuid: string

    Returns void

Private _clearHover

  • _clearHover(): void
  • Clear the hover for a caret, due to things like scrolling, resizing, deactivation, etc, where the position is no longer valid.

    Returns void

Private _evtBlur

  • _evtBlur(event: FocusEvent): void
  • Handle blur events for the editor.

    Parameters

    • event: FocusEvent

    Returns void

Private _evtFocus

  • _evtFocus(event: FocusEvent): void
  • Handle focus events for the editor.

    Parameters

    • event: FocusEvent

    Returns void

Private _evtScroll

  • _evtScroll(): void
  • Handle scroll events for the editor.

    Returns void

Private _getCaret

  • _getCaret(collaborator: ICollaborator): HTMLElement
  • Construct a caret element representing the position of a collaborator's cursor.

    Parameters

    • collaborator: ICollaborator

    Returns HTMLElement

Private _markSelections

  • _markSelections(uuid: string, selections: ITextSelection[]): void
  • Marks selections.

    Parameters

    • uuid: string
    • selections: ITextSelection[]

    Returns void

Private _onCursorActivity

  • _onCursorActivity(): void
  • Handles a cursor activity event.

    Returns void

Private _onMimeTypeChanged

  • _onMimeTypeChanged(): void
  • Handles a mime type change.

    Returns void

Private _onSelectionsChanged

  • _onSelectionsChanged(selections: IObservableMap<ITextSelection[]>, args: IChangedArgs<ITextSelection[]>): void
  • Handles a selections change.

    Parameters

    • selections: IObservableMap<ITextSelection[]>
    • args: IChangedArgs<ITextSelection[]>

    Returns void

Private _onValueChanged

  • _onValueChanged(value: IObservableString, args: IChangedArgs): void
  • Handle model value changes.

    Parameters

    • value: IObservableString
    • args: IChangedArgs

    Returns void

Private _toCodeMirrorPosition

  • _toCodeMirrorPosition(position: IPosition): object
  • Convert an editor position to a code mirror position.

    Parameters

    • position: IPosition

    Returns object

Private _toCodeMirrorSelection

  • _toCodeMirrorSelection(selection: IRange): Selection
  • Converts an editor selection to a code mirror selection.

    Parameters

    • selection: IRange

    Returns Selection

Private _toCodeMirrorSelections

  • _toCodeMirrorSelections(selections: IRange[]): Selection[]
  • Converts selections to code mirror selections.

    Parameters

    • selections: IRange[]

    Returns Selection[]

Private _toPosition

  • _toPosition(position: Position): object
  • Convert a code mirror position to an editor position.

    Parameters

    • position: Position

    Returns object

Private _toSelection

  • _toSelection(selection: Selection): ITextSelection
  • Converts a code mirror selection to an editor selection.

    Parameters

    • selection: Selection

    Returns ITextSelection

Private _toTextMarkerOptions

  • _toTextMarkerOptions(style: ISelectionStyle): TextMarkerOptions
  • Converts the selection style to a text marker options.

    Parameters

    • style: ISelectionStyle

    Returns TextMarkerOptions

addKeydownHandler

  • addKeydownHandler(handler: CodeEditor.KeydownHandler): IDisposable
  • Add a keydown handler to the editor.

    Parameters

    • handler: CodeEditor.KeydownHandler

      A keydown handler.

    Returns IDisposable

    A disposable that can be used to remove the handler.

addOverlay

  • addOverlay(mode: string | object, options?: object): void
  • Parameters

    • mode: string | object
    • Optional options: object

    Returns void

blur

  • blur(): void
  • Explicitly blur the editor.

    Returns void

clearHistory

  • clearHistory(): void

cursorCoords

  • cursorCoords(where: boolean, mode?: "window" | "page" | "local"): object
  • Parameters

    • where: boolean
    • Optional mode: "window" | "page" | "local"

    Returns object

dispose

  • dispose(): void
  • Dispose of the resources held by the widget.

    Returns void

execCommand

  • execCommand(command: string): void
  • Execute a codemirror command on the editor.

    Parameters

    • command: string

      The name of the command to execute.

    Returns void

firstLine

  • firstLine(): number

focus

  • focus(): void
  • Brings browser focus to this editor text.

    Returns void

getCoordinateForPosition

  • getCoordinateForPosition(position: IPosition): ICoordinate
  • Get the window coordinates given a cursor position.

    Parameters

    • position: IPosition

    Returns ICoordinate

getCursor

  • getCursor(start?: string): Position
  • Parameters

    • Optional start: string

    Returns Position

getCursorPosition

  • getCursorPosition(): IPosition
  • Returns the primary position of the cursor, never null.

    Returns IPosition

getLine

  • getLine(line: number): string | undefined
  • Returns the content for the given line number.

    Parameters

    • line: number

    Returns string | undefined

getOffsetAt

  • getOffsetAt(position: IPosition): number
  • Find an offset for the given position.

    Parameters

    • position: IPosition

    Returns number

getOption

  • getOption<K>(option: K): IConfig[K]
  • Get a config option for the editor.

    Type parameters

    • K: keyof IConfig

    Parameters

    • option: K

    Returns IConfig[K]

getPositionAt

  • getPositionAt(offset: number): IPosition
  • Find a position for the given offset.

    Parameters

    • offset: number

    Returns IPosition

getPositionForCoordinate

  • getPositionForCoordinate(coordinate: ICoordinate): IPosition | null
  • Get the cursor position given window coordinates.

    Parameters

    • coordinate: ICoordinate

      The desired coordinate.

    Returns IPosition | null

    The position of the coordinates, or null if not contained in the editor.

getRange

  • getRange(from: Position, to: Position, seperator?: string): string
  • Parameters

    • from: Position
    • to: Position
    • Optional seperator: string

    Returns string

getSearchCursor

  • getSearchCursor(query: string | RegExp, start?: Position, caseFold?: boolean): SearchCursor
  • Parameters

    • query: string | RegExp
    • Optional start: Position
    • Optional caseFold: boolean

    Returns SearchCursor

getSelection

  • getSelection(): ITextSelection
  • Returns the primary selection, never null.

    Returns ITextSelection

getSelections

  • getSelections(): ITextSelection[]
  • Gets the selections for all the cursors, never null or empty.

    Returns ITextSelection[]

getTokenForPosition

  • getTokenForPosition(position: IPosition): IToken
  • Get the token at a given editor position.

    Parameters

    • position: IPosition

    Returns IToken

getTokens

  • getTokens(): IToken[]
  • Get a list of tokens for the current editor text content.

    Returns IToken[]

handleEvent

  • handleEvent(event: Event): void
  • Handle the DOM events for the editor.

    Parameters

    • event: Event

      The DOM event sent to the editor.

      Notes

      This method implements the DOM EventListener interface and is called in response to events on the editor's DOM node. It should not be called directly by user code.

    Returns void

hasFocus

  • hasFocus(): boolean
  • Test whether the editor has keyboard focus.

    Returns boolean

lastLine

  • lastLine(): number

newIndentedLine

  • newIndentedLine(): void
  • Insert a new indented line at the current cursor position.

    Returns void

Protected onKeydown

  • onKeydown(event: KeyboardEvent): boolean
  • Handle keydown events from the editor.

    Parameters

    • event: KeyboardEvent

    Returns boolean

operation

  • operation<T>(fn: function): T
  • Type parameters

    • T

    Parameters

    • fn: function
        • (): T
        • Returns T

    Returns T

redo

  • redo(): void

refresh

  • refresh(): void

removeOverlay

  • removeOverlay(mode: string | object): void
  • Parameters

    • mode: string | object

    Returns void

resizeToFit

  • resizeToFit(): void
  • Refresh the editor if it is focused; otherwise postpone refreshing till focusing.

    Returns void

revealPosition

  • revealPosition(position: IPosition): void
  • Reveal the given position in the editor.

    Parameters

    • position: IPosition

    Returns void

revealSelection

  • revealSelection(selection: IRange): void
  • Reveal the given selection in the editor.

    Parameters

    • selection: IRange

    Returns void

scrollIntoView

  • scrollIntoView(pos: object, margin: number): void
  • Parameters

    • pos: object
    • margin: number

    Returns void

setCursorPosition

  • setCursorPosition(position: IPosition, options?: object): void
  • Set the primary position of the cursor.

    Notes

    This will remove any secondary cursors.

    Parameters

    • position: IPosition
    • Optional options: object

    Returns void

setOption

  • setOption<K>(option: K, value: IConfig[K]): void
  • Set a config option for the editor.

    Type parameters

    • K: keyof IConfig

    Parameters

    • option: K
    • value: IConfig[K]

    Returns void

setSelection

  • setSelection(selection: IRange): void
  • Set the primary selection. This will remove any secondary cursors.

    Parameters

    • selection: IRange

    Returns void

setSelections

  • setSelections(selections: IRange[]): void
  • Sets the selections for all the cursors, should not be empty. Cursors will be removed or added, as necessary. Passing an empty array resets a cursor position to the start of a document.

    Parameters

    • selections: IRange[]

    Returns void

setSize

  • setSize(dimension: IDimension | null): void
  • Set the size of the editor in pixels.

    Parameters

    • dimension: IDimension | null

    Returns void

undo

  • undo(): void
  • Undo one edit (if any undo events are stored).

    Returns void

Static addCommand

  • addCommand(name: string, command: function): void
  • Add a command to CodeMirror.

    Parameters

    • name: string

      The name of the command to add.

    • command: function

      The command function.

        • (cm: Editor): void
        • Parameters

          • cm: Editor

          Returns void

    Returns void

Object literals

Static defaultConfig

defaultConfig: object

The default configuration options for an editor.

coverGutterNextToScrollbar

coverGutterNextToScrollbar: false = false

dragDrop

dragDrop: true = true

electricChars

electricChars: true = true

extraKeys

extraKeys: null = null

fixedGutter

fixedGutter: true = true

foldGutter

foldGutter: false = false

gutters

gutters: undefined[] = []

keyMap

keyMap: string = "default"

lineSeparator

lineSeparator: null = null

lineWiseCopyCut

lineWiseCopyCut: true = true

mode

mode: string = "null"

rulers

rulers: undefined[] = []

scrollPastEnd

scrollPastEnd: false = false

scrollbarStyle

scrollbarStyle: string = "native"

selectionPointer

selectionPointer: false = false

showCursorWhenSelecting

showCursorWhenSelecting: false = false

smartIndent

smartIndent: true = true

styleActiveLine

styleActiveLine: false = false

styleSelectedText

styleSelectedText: true = true

theme

theme: string = "jupyter"

Generated using TypeDoc