Options
All
  • Public
  • Public/Protected
  • All
Menu

Class EditSession

Stores all the data about Editor state providing easy way to change editors state.

EditSession can be attached to only one Document. Same Document can be attached to several EditSessions.

Hierarchy

  • EditSession

Implements

Index

Constructors

constructor

Events

on

  • on(name: "changeWrapLimit"): void
  • on(name: "changeWrapMode"): void
  • on(name: "changeMode"): void
  • on(name: "changeAnnotation"): void
  • on(name: "changeBackMarker"): void
  • on(name: "changeFrontMarker"): void
  • on(name: "changeBreakpoint"): void
  • on(name: "changeOverwrite"): void
  • on(name: "changeTabSize"): void
  • on(name: "changeFold", callback: (obj: { action: string; data: Fold }) => void): Function
  • on(name: "changeScrollLeft", callback: (scrollLeft: number) => void): Function
  • on(name: "changeScrollTop", callback: (scrollTop: number) => void): Function
  • on(name: "tokenizerUpdate", callback: (obj: { data: { first: number; last: number } }) => void): Function
  • on(name: "change", callback: () => void): Function
  • Emitted when the wrapping limit changes.

    Parameters

    • name: "changeWrapLimit"

    Returns void

  • Emitted when the wrap mode changes.

    Parameters

    • name: "changeWrapMode"

    Returns void

  • Emitted when the current mode changes.

    Parameters

    • name: "changeMode"

    Returns void

  • Emitted when an annotation changes, like through EditSession.setAnnotations.

    Parameters

    • name: "changeAnnotation"

    Returns void

  • Emitted when a back marker changes.

    Parameters

    • name: "changeBackMarker"

    Returns void

  • Emitted when a front marker changes.

    Parameters

    • name: "changeFrontMarker"

    Returns void

  • Emitted when the gutter changes, either by setting or removing breakpoints, or when the gutter decorations change.

    Parameters

    • name: "changeBreakpoint"

    Returns void

  • Emitted when the ability to overwrite text changes, via EditSession.setOverwrite.

    Parameters

    • name: "changeOverwrite"

    Returns void

  • Emitted when the tab size changes, via EditSession.setTabSize.

    Parameters

    • name: "changeTabSize"

    Returns void

  • Emitted when a code fold is added or removed.

    Parameters

    • name: "changeFold"
    • callback: (obj: { action: string; data: Fold }) => void
        • (obj: { action: string; data: Fold }): void
        • Parameters

          • obj: { action: string; data: Fold }
            • action: string
            • data: Fold

          Returns void

    Returns Function

  • Emitted when the scroll left changes.

    Parameters

    • name: "changeScrollLeft"
    • callback: (scrollLeft: number) => void
        • (scrollLeft: number): void
        • Parameters

          • scrollLeft: number

          Returns void

    Returns Function

  • Emitted when the scroll top changes.

    Parameters

    • name: "changeScrollTop"
    • callback: (scrollTop: number) => void
        • (scrollTop: number): void
        • Parameters

          • scrollTop: number

          Returns void

    Returns Function

  • Emitted when a background tokenizer asynchronously processes new rows.

    Parameters

    • name: "tokenizerUpdate"
    • callback: (obj: { data: { first: number; last: number } }) => void
        • (obj: { data: { first: number; last: number } }): void
        • Parameters

          • obj: { data: { first: number; last: number } }
            • data: { first: number; last: number }
              • first: number
              • last: number

          Returns void

    Returns Function

  • Emitted when the document changes.

    Parameters

    • name: "change"
    • callback: () => void
        • (): void
        • Returns void

    Returns Function

Properties

Readonly doc

selection

selection: Selection

Methods

addDynamicMarker

  • Adds a dynamic marker to the session.

    Parameters

    • marker: MarkerLike

      object with update method

    • inFront: boolean

      Set to true to establish a front marker

    Returns MarkerLike

    The added marker

addGutterDecoration

  • addGutterDecoration(row: number, className: string): void
  • Adds className to the row, to be used for CSS stylings and whatnot.

    Parameters

    • row: number

      The row number

    • className: string

      The class to add

    Returns void

addMarker

  • addMarker(range: Range, className: string, type: "text" | MarkerRenderer | "fullLine" | "screenLine", inFront?: boolean): number
  • Adds a new marker to the given Range. If inFront is true, a front marker is defined, and the 'changeFrontMarker' event fires; otherwise, the 'changeBackMarker' event fires.

    Parameters

    • range: Range

      Define the range of the marker

    • className: string
    • type: "text" | MarkerRenderer | "fullLine" | "screenLine"

      Identify the type of the marker

    • Optional inFront: boolean

      Set to true to establish a front marker

    Returns number

    The new marker id

Private adjustWrapLimit

  • adjustWrapLimit(desiredLimit: number): boolean
  • This should generally only be called by the renderer when a resize is detected.

    Parameters

    • desiredLimit: number

      The new wrap limit

    Returns boolean

clearAnnotations

  • clearAnnotations(): void
  • Clears all the annotations for this session. This function also triggers the 'changeAnnotation' event.

    Returns void

clearBreakpoint

  • clearBreakpoint(row: number): void
  • Removes a breakpoint on the row number given by row. This function also emits the 'changeBreakpoint' event.

    Parameters

    • row: number

      A row index

    Returns void

clearBreakpoints

  • clearBreakpoints(): void
  • Removes all breakpoints on the rows. This function also emits the 'changeBreakpoint' event.

    Returns void

documentToScreenColumn

  • documentToScreenColumn(row: number, docColumn: number): number
  • For the given document row and column, returns the screen column.

    Parameters

    • row: number
    • docColumn: number

    Returns number

documentToScreenPosition

  • documentToScreenPosition(docRow: number, docColumn: number): Position
  • documentToScreenPosition(position: Position): Position
  • Converts document coordinates to screen coordinates. {:conversionConsiderations}

    related

    EditSession.screenToDocumentPosition

    Parameters

    • docRow: number

      The document row to check

    • docColumn: number

      The document column to check

    Returns Position

    The object returned by this method has two properties: row and column.

  • Converts document coordinates to screen coordinates. {:conversionConsiderations}

    related

    EditSession.screenToDocumentPosition

    Parameters

    Returns Position

    The object returned by this method has two properties: row and column.

documentToScreenRow

  • documentToScreenRow(docRow: number, docColumn: number): number
  • For the given document row and column, returns the screen row.

    Parameters

    • docRow: number
    • docColumn: number

    Returns number

duplicateLines

  • duplicateLines(firstRow: number, lastRow: number): void
  • Duplicates all the text between firstRow and lastRow.

    Parameters

    • firstRow: number

      The starting row to duplicate

    • lastRow: number

      The final row to duplicate

    Returns void

    Returns the number of new rows added; in other words, lastRow - firstRow + 1.

getAWordRange

  • getAWordRange(row: number, column: number): Range
  • Gets the range of a word, including its right whitespace.

    Parameters

    • row: number

      The row number to start from

    • column: number

      The column number to start from

    Returns Range

getAnnotations

getBreakpoints

  • getBreakpoints(): string[]
  • Returns an array of strings, indicating the breakpoint class (if any) applied to each row.

    Returns string[]

getDocument

getDocumentLastRowColumn

  • getDocumentLastRowColumn(docRow: number, docColumn: number): number
  • For the given document row and column, this returns the column position of the last screen row.

    Parameters

    • docRow: number
    • docColumn: number

    Returns number

getDocumentLastRowColumnPosition

  • getDocumentLastRowColumnPosition(docRow: Number, docColumn: Number): any
  • For the given document row and column, this returns the document position of the last row.

    Parameters

    • docRow: Number
    • docColumn: Number

    Returns any

getLength

  • getLength(): number

getLine

  • getLine(row: number): string
  • Returns a verbatim copy of the given line as it is in the document

    Parameters

    • row: number

      The row to retrieve from

    Returns string

getLines

  • getLines(firstRow: number, lastRow: number): string[]
  • Returns an array of strings of the rows between firstRow and lastRow. This function is inclusive of lastRow.

    Parameters

    • firstRow: number

      The first row index to retrieve

    • lastRow: number

      The final row index to retrieve

    Returns string[]

getMarkers

  • Returns an object containing all of the markers, either front or back.

    Parameters

    • Optional inFront: boolean

      If true, indicates you only want front markers; false indicates only back markers

    Returns MarkerLike[]

getMode

getNavigateWithinSoftTabs

  • getNavigateWithinSoftTabs(): boolean
  • Returns true if keyboard navigation moves the cursor within soft tabs, false if it moves the cursor over soft tabs.

    Returns boolean

getNewLineMode

getOverwrite

  • getOverwrite(): boolean

getRowLength

  • getRowLength(row: Number): Number
  • Returns number of screenrows in a wrapped line.

    Parameters

    • row: Number

      The row number to check

    Returns Number

getRowSplitData

  • getRowSplitData(row: number): string
  • For the given row, this returns the split data.

    Parameters

    • row: number

    Returns string

getScreenLastRowColumn

  • getScreenLastRowColumn(screenRow: number): number
  • Returns the position (on screen) for the last character in the provided screen row.

    related

    EditSession.documentToScreenColumn

    Parameters

    • screenRow: number

      The screen row to check

    Returns number

getScreenLength

  • getScreenLength(): number

getScreenTabSize

  • getScreenTabSize(screenColumn: number): number
  • The distance to the next tab stop at the specified screen column.

    Parameters

    • screenColumn: number

      The screen column to check

    Returns number

getScreenWidth

  • getScreenWidth(): number

getScrollLeft

  • getScrollLeft(): number
  • [Returns the value of the distance between the left of the editor and the leftmost part of the visible content.]{: #EditSession.getScrollLeft}

    Returns number

getScrollTop

  • getScrollTop(): number
  • [Returns the value of the distance between the top of the editor and the topmost part of the visible content.]{: #EditSession.getScrollTop}

    Returns number

getSelection

getState

  • getState(row: number): string
  • {:BackgroundTokenizer.getState}

    related

    BackgroundTokenizer.getState

    Parameters

    • row: number

      The row to start at

    Returns string

getTabSize

  • getTabSize(): number

getTabString

  • getTabString(): string
  • Returns the current value for tabs. If the user is using soft tabs, this will be a series of spaces (defined by getTabSize()); otherwise it's simply '\t'.

    Returns string

getTextRange

  • getTextRange(range: Range): string

getTokenAt

  • getTokenAt(row: number, column: number): Token
  • Returns an object indicating the token at the current row. The object has two properties: index and start.

    Parameters

    • row: number

      The row number to retrieve from

    • column: number

      The column number to retrieve from

    Returns Token

getTokens

  • getTokens(row: number): Token[]
  • Starts tokenizing at the row indicated. Returns a list of objects of the tokenized rows.

    Parameters

    • row: number

      The row to start at

    Returns Token[]

getUndoManager

getUseSoftTabs

  • getUseSoftTabs(): boolean

getUseWorker

  • getUseWorker(): boolean

getUseWrapMode

  • getUseWrapMode(): boolean

getValue

  • getValue(): string

getWordRange

  • getWordRange(row: number, column: number): Range
  • Given a starting row and column, this method returns the Range of the first word boundary it finds.

    Parameters

    • row: number

      The row to start at

    • column: number

      The column to start at

    Returns Range

getWrapLimit

  • getWrapLimit(): number

getWrapLimitRange

  • getWrapLimitRange(): { max: number; min: number }
  • Returns an object that defines the minimum and maximum of the wrap limit; it looks something like this:

    { min: wrapLimitRange_min, max: wrapLimitRange_max }

    Returns { max: number; min: number }

    • max: number
    • min: number

highlightLines

  • highlightLines(startRow: number, endRow: number, className: string, inFront?: boolean): Range
  • experimental

    Parameters

    • startRow: number
    • endRow: number
    • className: string
    • Optional inFront: boolean

    Returns Range

indentRows

  • indentRows(startRow: number, endRow: number, indentString: string): void
  • Indents all the rows, from startRow to endRow (inclusive), by prefixing each row with the token in indentString.

    If indentString contains the '\t' character, it's replaced by whatever is defined by getTabString().

    Parameters

    • startRow: number

      Starting row

    • endRow: number

      Ending row

    • indentString: string

      The indent token

    Returns void

insert

  • insert(position: Position, text: string): void
  • Inserts a block of text and the indicated position.

    Parameters

    • position: Position

      The position {row, column} to start inserting at

    • text: string

      A chunk of text to insert

    Returns void

    The position of the last line of text. If the length of text is 0, this function simply returns position.

isTabStop

  • isTabStop(position: Position): boolean
  • Returns true if the character at the position is a soft tab.

    Parameters

    • position: Position

      The position to check

    Returns boolean

markUndoGroup

  • markUndoGroup(): void

moveLinesDown

  • moveLinesDown(firstRow: number, lastRow: number): void
  • Shifts all the lines in the document down one, starting from firstRow and ending at lastRow.

    Parameters

    • firstRow: number

      The starting row to move down

    • lastRow: number

      The final row to move down

    Returns void

    If firstRow is less-than or equal to 0, this function returns 0. Otherwise, on success, it returns -1.

moveLinesUp

  • moveLinesUp(firstRow: number, lastRow: number): void
  • Shifts all the lines in the document up one, starting from firstRow and ending at lastRow.

    Parameters

    • firstRow: number

      The starting row to move up

    • lastRow: number

      The final row to move up

    Returns void

    If firstRow is less-than or equal to 0, this function returns 0. Otherwise, on success, it returns -1.

moveText

  • moveText(fromRange: Range, toPosition: Position, copy?: boolean): void
  • Moves a range of text from the given range to the given position. toPosition is an object that looks like this:

    
    { row: newRowLocation, column: newColumnLocation }
    
    

    Parameters

    • fromRange: Range

      The range of text you want moved within the document

    • toPosition: Position

      The location (row and column) where you want to move the text to

    • Optional copy: boolean

    Returns void

    The new range where the text was moved to.

onReloadTokenizer

  • onReloadTokenizer(e: any): void

outdentRows

  • outdentRows(range: Range): void
  • Outdents all the rows defined by the start and end properties of range.

    Parameters

    • range: Range

      A range of rows

    Returns void

redoChanges

  • redoChanges(deltas: Delta[], dontSelect?: boolean): void
  • Re-implements a previously undone change to your document.

    Parameters

    • deltas: Delta[]

      An array of previous changes

    • Optional dontSelect: boolean

    Returns void

remove

  • remove(range: Range): void
  • Removes the range from the document.

    related

    Document.remove

    Parameters

    • range: Range

      A specified Range to remove

    Returns void

    The new start property of the range, which contains startRow and startColumn. If range is empty, this function returns the unmodified value of range.start.

removeFullLines

  • removeFullLines(firstRow: number, lastRow: number): void
  • Removes a range of full lines. This method also triggers the 'change' event.

    related

    Document.removeFullLines

    Parameters

    • firstRow: number

      The first row to be removed

    • lastRow: number

      The last row to be removed

    Returns void

    Returns all the removed lines.

removeGutterDecoration

  • removeGutterDecoration(row: number, className: string): void
  • Removes className from the row.

    Parameters

    • row: number

      The row number

    • className: string

      The class to add

    Returns void

removeMarker

  • removeMarker(markerId: number): void
  • Removes the marker with the specified ID. If this marker was in front, the 'changeFrontMarker' event is emitted. If the marker was in the back, the 'changeBackMarker' event is emitted.

    Parameters

    • markerId: number

      A number representing a marker

    Returns void

replace

  • replace(range: Range, text: string): void
  • Replaces a range in the document with the new text.

    related

    Document.replace

    Parameters

    • range: Range

      A specified Range to replace

    • text: string

      The new text to use as a replacement

    Returns void

    An object containing the final row and column, like this:

    {row: endRow, column: 0}
    

    If the text and range are empty, this function returns an object containing the current range.start value. If the text is the exact same as what currently exists, this function returns an object containing the current range.end value.

screenToDocumentPosition

  • screenToDocumentPosition(screenRow: number, screenColumn: number, offsetX?: number): Position
  • Converts characters coordinates on the screen to characters coordinates within the document. [This takes into account code folding, word wrap, tab size, and any other visual modifications.]{: #conversionConsiderations}

    related

    EditSession.documentToScreenPosition

    Parameters

    • screenRow: number

      The screen row to check

    • screenColumn: number

      The screen column to check

    • Optional offsetX: number

      screen character x-offset [optional]

    Returns Position

    The object returned has two properties: row and column.

setAnnotations

  • Error:

    {

    row: 12,

    column: 2, //can be undefined

    text: "Missing argument",

    type: "error" // or "warning" or "info"

    }

    Parameters

    Returns void

setBreakpoint

  • setBreakpoint(row: number, className: string): void
  • Sets a breakpoint on the row number given by row. This function also emits the 'changeBreakpoint' event.

    Parameters

    • row: number

      A row index

    • className: string

      Class of the breakpoint

    Returns void

setBreakpoints

  • setBreakpoints(rows: number[]): void
  • Sets a breakpoint on every row number given by rows. This function also emites the 'changeBreakpoint' event.

    Parameters

    • rows: number[]

      An array of row indices

    Returns void

setDocument

  • Sets the EditSession to point to a new Document. If a BackgroundTokenizer exists, it also points to doc.

    Parameters

    Returns void

setNavigateWithinSoftTabs

  • setNavigateWithinSoftTabs(navigateWithinSoftTabs: boolean): void
  • Set whether keyboard navigation of soft tabs moves the cursor within the soft tab, rather than over

    Parameters

    • navigateWithinSoftTabs: boolean

      Value indicating whether or not to navigate within soft tabs

    Returns void

setNewLineMode

setOverwrite

  • setOverwrite(overwrite: boolean): void
  • Pass in true to enable overwrites in your session, or false to disable.

    If overwrites is enabled, any text you enter will type over any text after it. If the value of overwrite changes, this function also emits the changeOverwrite event.

    Parameters

    • overwrite: boolean

      Defines whether or not to set overwrites

    Returns void

setScrollLeft

  • setScrollLeft(scrollLeft: number): void
  • [Sets the value of the distance between the left of the editor and the leftmost part of the visible content.]{: #EditSession.setScrollLeft}

    Parameters

    • scrollLeft: number

    Returns void

setScrollTop

  • setScrollTop(scrollTop: number): void
  • This function sets the scroll top value. It also emits the 'changeScrollTop' event.

    Parameters

    • scrollTop: number

      The new scroll top value

    Returns void

setTabSize

  • setTabSize(tabSize: number): void
  • Set the number of spaces that define a soft tab; for example, passing in 4 transforms the soft tabs to be equivalent to four spaces. This function also emits the changeTabSize event.

    Parameters

    • tabSize: number

      The new tab size

    Returns void

setUndoManager

setUndoSelect

  • setUndoSelect(enable: boolean): void
  • Enables or disables highlighting of the range where an undo occurred.

    Parameters

    • enable: boolean

      If true, selects the range of the reinserted change

    Returns void

setUseSoftTabs

  • setUseSoftTabs(val: boolean): void
  • Pass true to enable the use of soft tabs. Soft tabs means you're using spaces instead of the tab character ('\t').

    Parameters

    • val: boolean

    Returns void

setUseWorker

  • setUseWorker(useWorker: boolean): void
  • Identifies if you want to use a worker for the EditSession.

    Parameters

    • useWorker: boolean

      Set to true to use a worker

    Returns void

setUseWrapMode

  • setUseWrapMode(useWrapMode: boolean): void
  • Sets whether or not line wrapping is enabled. If useWrapMode is different than the current value, the 'changeWrapMode' event is emitted.

    Parameters

    • useWrapMode: boolean

      Enable (or disable) wrap mode

    Returns void

setValue

  • setValue(text: string): void
  • Sets the session text.

    Parameters

    • text: string

      The new text to place

    Returns void

setWrapLimit

  • setWrapLimit(limit: number): void
  • Sets the line length for soft wrap in the editor. Lines will break

    at a minimum of the given length minus 20 chars and at a maximum

    of the given number of chars.

    Parameters

    • limit: number

      The maximum line length in chars, for soft wrapping lines.

    Returns void

setWrapLimitRange

  • setWrapLimitRange(min: number, max: number): void
  • Allow the wrap limit to move freely between min and max. Either

    Parameters

    • min: number
    • max: number

    Returns void

toString

  • toString(): String

toggleOverwrite

  • toggleOverwrite(): void
  • Sets the value of overwrite to the opposite of whatever it currently is.

    Returns void

undoChanges

  • undoChanges(deltas: Delta[], dontSelect?: boolean): void
  • Reverts previous changes to your document.

    Parameters

    • deltas: Delta[]

      An array of previous changes

    • Optional dontSelect: boolean

      {: #dontSelect}

    Returns void

Generated using TypeDoc