Ace API Reference
    Preparing search index...

    Class EditSession

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

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

    Hierarchy

    • EventEmitter<Ace.EditSessionEvents>
    • OptionsProvider<Ace.EditSessionOptions>
    • Folding
    • BracketMatch
    • TextMarkers
      • EditSession
    Index

    Constructors

    Properties

    Accessors

    Methods

    addDynamicMarker addEventListener addFold addFolds addGutterCustomWidget addGutterDecoration addMarker addTextMarker adjustWrapLimit clearAnnotations clearBreakpoint clearBreakpoints destroy documentToScreenColumn documentToScreenPosition documentToScreenRow duplicateLines endOperation expandFold expandFolds foldAll foldAllComments foldToLevel getAllFolds getAnnotations getAWordRange getBreakpoints getCommentFoldRange getDisplayLine getDocument getDocumentLastRowColumn getDocumentLastRowColumnPosition getFoldAt getFoldDisplayLine getFoldedRowCount getFoldLine getFoldsInRange getFoldsInRangeList getFoldStringAt getLength getLine getLines getLineWidgetMaxWidth getMarkers getMode getNavigateWithinSoftTabs getNewLineMode getNextFoldLine getOption getOptions getOverwrite getParentFoldRangeData getPrecedingCharacter getRowFoldEnd getRowFoldStart getRowLength getRowLineCount getRowSplitData getRowWrapIndent getScreenLastRowColumn getScreenLength getScreenTabSize getScreenWidth getScrollLeft getScrollTop getSelection getSelectionMarkers getState getTabSize getTabString getTextMarkers getTextRange getTokenAt getTokens getUndoManager getUseSoftTabs getUseWorker getUseWrapMode getWordRange getWrapLimit getWrapLimitRange highlight highlightLines indentRows insert isRowFolded isTabStop markUndoGroup moveLinesDown moveLinesUp moveText off on once onFoldWidgetClick onSelectionChange outdentRows redoChanges remove removeAllListeners removeDefaultHandler removeEventListener removeFold removeFolds removeFullLines removeGutterCustomWidget removeGutterDecoration removeListener removeMarker removeTextMarker replace resetCaches screenToDocumentColumn screenToDocumentPosition screenToDocumentRow setAnnotations setBreakpoint setBreakpoints setDefaultHandler setDocument setFoldStyle setMode setNavigateWithinSoftTabs setNewLineMode setOption setOptions setOverwrite setScrollLeft setScrollTop setTabSize setUndoManager setUndoSelect setUseSoftTabs setUseWorker setUseWrapMode setValue setWrapLimit setWrapLimitRange startOperation toggleFold toggleFoldWidget toggleOverwrite toJSON tokenizerUpdateFoldWidgets undoChanges unfold updateFoldWidgets fromJSON

    Constructors

    Properties

    bgTokenizer: BackgroundTokenizer
    curOp: Operation
    destroyed: boolean
    doc: Document
    findMatchingBracket: (position: Ace.Point, chr?: string) => Ace.Point
    foldWidgets: any[]
    getBracketRange: (pos: Ace.Point) => Range
    getFoldWidget: any
    getFoldWidgetRange: any
    getMatchingBracketRanges: (pos: Ace.Point, isBackwards?: boolean) => Range[]

    Returns:

    • null if there is no any bracket at pos;
    • two Ranges if there is opening and closing brackets;
    • one Range if there is only one bracket
    getMatchingTags: (
        pos: Ace.Point,
    ) => {
        closeTag: Range;
        closeTagName: Range;
        openTag: Range;
        openTagName: Range;
    }

    Returns [[Range]]'s for matching tags and tag names, if there are any

    getValue: () => string

    Returns the current [[Document Document]] as a string.

    getValue

    EditSession.toString

    gutterRenderer?: any
    id: string
    isFullWidth: (c: any) => boolean
    lineWidgets: Ace.LineWidget[]
    lineWidgetsWidth?: number
    lineWidgetWidth: number
    mergeUndoDeltas: boolean
    multiSelect?: any
    nonTokenRe: RegExp
    prevOp: {}
    screenWidth: any
    selection: Selection
    selectionMarkerCount?: number
    tokenRe: RegExp

    Accessors

    • get widgetManager(): LineWidgets

      Get "widgetManager" from EditSession

      Returns LineWidgets

    • set widgetManager(value: LineWidgets): void

      Set "widgetManager" in EditSession

      Parameters

      • value: LineWidgets

      Returns void

    Methods

    • Adds a new fold. The new created Fold object or an existing fold object in case the passed in range fits an existing fold exactly.

      Parameters

      • placeholder: string | Fold
      • Optionalrange: Range

      Returns Fold

    • Parameters

      • folds: Fold[]

      Returns void

    • Experimental

      Replaces the fold widget if present with the custom icon from a specific row in the gutter

      Parameters

      • row: number

        The row number where the widget will be displayed

      • attributes: { callbacks: any; className: string; label: string; title: string }

        Configuration attributes for the widget

        • callbacks: any

          Event callback functions for the widget e.g onClick;

        • className: string

          CSS class name for styling the widget

        • label: string

          Text label to display in the widget

        • title: string

          Tooltip text for the widget

      Returns 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

    • 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

      • clazz: string

        Set the CSS class for the marker

      • Optionaltype: "line" | "text" | "fullLine" | "screenLine" | MarkerRenderer

        Identify the renderer type of the marker. If string provided, corresponding built-in renderer is used. Supported string types are "fullLine", "screenLine", "text" or "line". If a Function is provided, that Function is used as renderer.

      • OptionalinFront: boolean

        Set to true to establish a front marker

      Returns number

      The new marker id

    • This should generally only be called by the renderer when a resize is detected.

      Parameters

      • desiredLimit: number

        The new wrap limit

      • Optional$printMargin: any

      Returns boolean

    • Clears all the annotations for this session. This function also triggers the 'changeAnnotation' event.

      Returns 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

    • Removes all breakpoints on the rows. This function also emits the 'changeBreakpoint' event.

      Returns void

    • For the given document row and column, returns the screen column.

      Parameters

      • row: number | Ace.Point
      • OptionaldocColumn: number

      Returns number

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

      Parameters

      • docRow: number | Ace.Point

        The document row to check

      • OptionaldocColumn: number

        The document column to check

      Returns Ace.Point

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

    • For the given document row and column, returns the screen row.

      Parameters

      • docRow: number | Ace.Point
      • OptionaldocColumn: number

      Returns number

    • Duplicates all the text between firstRow and lastRow.

      Parameters

      • firstRow: number

        The starting row to duplicate

      • lastRow: number

        The final row to duplicate

      Returns number

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

    • End current Ace operation. Emits "beforeEndOperation" event just before clearing everything, where the current operation can be accessed through curOp property.

      Parameters

      • Optionale: any

      Returns void

    • Parameters

      • fold: Fold

      Returns void

    • Parameters

      • folds: Fold[]

      Returns void

    • Parameters

      • OptionalstartRow: number
      • OptionalendRow: number
      • Optionaldepth: number
      • Optionaltest: Function

      Returns void

    • Parameters

      • level: number

      Returns void

    • Returns all folds in the document

      Returns Fold[]

    • 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

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

      Returns string[]

    • Parameters

      • row: number
      • column: number
      • Optionaldir: number

      Returns Range

    • Parameters

      • row: number
      • endColumn: number
      • startRow: number
      • startColumn: number

      Returns string

    • For the given document row and column, this returns the column position of the last screen row.

      Parameters

      • docRow: number
      • docColumn: number

      Returns number

    • For the given document row and column, this returns the document position of the last row.

      Parameters

      • docRow: number
      • docColumn: number

      Returns Ace.Point

    • Looks up a fold at a given row/column. Possible values for side: -1: ignore a fold if fold.start = row/column +1: ignore a fold if fold.end = row/column

      Parameters

      • row: number
      • column: number
      • Optionalside: number

      Returns Fold

    • Parameters

      • foldLine: FoldLine
      • OptionalendRow: number
      • OptionalendColumn: number
      • OptionalstartRow: number
      • OptionalstartColumn: number

      Returns string

    • Parameters

      • first: number
      • last: number

      Returns number

    • Parameters

      • docRow: number
      • OptionalstartFoldLine: FoldLine

      Returns FoldLine

    • Returns all folds in the given range. Note, that this will return folds

      Parameters

      Returns Fold[]

    • Returns the string between folds at the given position. E.g. foob|arwolrd -> "bar" foobarwol|rd -> "world" foobar<fo|ld>wolrd ->

      where | means the position of row/column

      The trim option determs if the return string should be trimed according to the "side" passed with the trim value:

      E.g. foob|arwolrd -trim=-1> "b" foobarwol|rd -trim=+1> "rld" fo|obarwolrd -trim=00> "foo"

      Parameters

      • row: number
      • column: number
      • Optionaltrim: number
      • OptionalfoldLine: FoldLine

      Returns 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

    • 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[]

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

      Parameters

      • OptionalinFront: boolean

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

      Returns { [id: number]: MarkerLike }

    • Returns true if keyboard navigation moves the cursor within soft tabs, false if it moves the cursor over soft tabs.

      Returns boolean

    • Returns the fold which starts after or contains docRow

      Parameters

      • docRow: number
      • OptionalstartFoldLine: FoldLine

      Returns FoldLine

    • Parameters

      • row: number
      • OptionalignoreCurrent: boolean

      Returns { firstRange?: Range; range?: Range }

    • Returns string

      the last character preceding the cursor in the editor

    • Parameters

      • docRow: number
      • OptionalstartFoldRow: FoldLine

      Returns number

    • Parameters

      • docRow: number
      • OptionalstartFoldRow: FoldLine

      Returns number

    • Returns number of screenrows in a wrapped line.

      Parameters

      • row: number

        The row number to check

      Returns number

    • For the given row, this returns the split data.

      Parameters

      • row: number

      Returns string

    • Returns the position (on screen) for the last character in the provided screen row.

      Parameters

      • screenRow: number

        The screen row to check

      Returns number

    • The distance to the next tab stop at the specified screen column.

      Parameters

      • screenColumn: number

        The screen column to check

      Returns 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

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

      Returns number

    • {:BackgroundTokenizer.getState}

      Parameters

      • row: number

        The row to start at

      Returns string | string[]

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

      Returns string

    • 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

    • 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[]

    • Returns true if soft tabs are being used, false otherwise.

      Returns boolean

    • Returns true if wrap mode is being used; false otherwise.

      Returns boolean

    • 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

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

    • experimental

      Parameters

      • startRow: number
      • endRow: number
      • clazz: string
      • OptionalinFront: boolean

      Returns Range

    • 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 [[EditSession.getTabString getTabString()]].

      Parameters

      • startRow: number

        Starting row

      • endRow: number

        Ending row

      • indentString: string

        The indent token

      Returns void

    • Inserts a block of text and the indicated position.

      Parameters

      • position: Ace.Point

        The position {row, column} to start inserting at

      • text: string

        A chunk of text to insert

      Returns Ace.Point

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

    • Checks if a given documentRow is folded. This is true if there are some folded parts such that some parts of the line is still visible.

      Parameters

      • docRow: number
      • OptionalstartFoldRow: FoldLine

      Returns boolean

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

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

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

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

    • 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: Ace.Point

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

      • Optionalcopy: boolean

      Returns Range

      The new range where the text was moved to.

    • Parameters

      • row: number
      • e: any

      Returns void

    • Outdents all the rows defined by the start and end properties of range.

      Parameters

      • range: Range

        A range of rows

      Returns void

    • Re-implements a previously undone change to your document.

      Parameters

      • deltas: Ace.Delta[]

        An array of previous changes

      • OptionaldontSelect: boolean

      Returns void

    • Removes the range from the document.

      Parameters

      • range: Ace.IRange

        A specified Range to remove

      Returns Ace.Point

      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.

    • Parameters

      • Optionalname: string

      Returns void

    • Parameters

      • name: string
      • callback: Function

      Returns void

    • Parameters

      • fold: Fold

      Returns void

    • Parameters

      • folds: Fold[]

      Returns void

    • Removes a range of full lines. This method also triggers the 'change' event.

      Parameters

      • firstRow: number

        The first row to be removed

      • lastRow: number

        The last row to be removed

      Returns string[]

      Returns all the removed lines.

    • Experimental

      Replaces the custom icon with the fold widget if present from a specific row in the gutter

      Parameters

      • row: number

        The row number for which to hide the custom icon

      Returns void

    • Removes className from the row.

      Parameters

      • row: number

        The row number

      • className: string

        The class to add

      Returns 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

    • Replaces a range in the document with the new text.

      Parameters

      • range: Ace.IRange

        A specified Range to replace

      • text: string

        The new text to use as a replacement

      Returns Ace.Point

      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.

    • Parameters

      • screenRow: number
      • screenColumn: number

      Returns number

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

      Parameters

      • screenRow: number

        The screen row to check

      • screenColumn: number

        The screen column to check

      • OptionaloffsetX: number

        screen character x-offset [optional]

      Returns Ace.Point

      The object returned has two properties: row and column.

    • Parameters

      • screenRow: number
      • screenColumn: number

      Returns number

    • Sets annotations for the EditSession. This functions emits the 'changeAnnotation' event.

      Parameters

      Returns 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

    • 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

    • Parameters

      • name: string
      • callback: Function

      Returns void

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

      Parameters

      • doc: Document

        The new Document to use

      Returns void

    • Parameters

      • style: string

      Returns void

    • Sets a new text mode for the EditSession. This method also emits the 'changeMode' event. If a [[BackgroundTokenizer BackgroundTokenizer]] is set, the 'tokenizerUpdate' event is also emitted.

      Parameters

      • mode: string | Ace.SyntaxMode

        Set a new text mode

      • Optionalcb: () => void

        optional callback

      Returns 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

    • Parameters

      • optList: Partial<T>

      Returns 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

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

    • This function sets the scroll top value. It also emits the 'changeScrollTop' event.

      Parameters

      • scrollTop: number

        The new scroll top value

      Returns 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

    • 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

    • 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

        Value indicating whether or not to use soft tabs

      Returns void

    • Identifies if you want to use a worker for the EditSession.

      Parameters

      • useWorker: boolean

        Set to true to use a worker

      Returns 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

    • Sets the session text.

      Parameters

      • text: string

        The new text to place

      Returns 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

    • Sets the boundaries of wrap. Either value can be null to have an unconstrained wrap, or, they can be the same number to pin the limit. If the wrap limits for min or max are different, this method also emits the 'changeWrapMode' event.

      Parameters

      • min: number

        The minimum wrap value (the left side wrap)

      • max: number

        The maximum wrap value (the right side wrap)

      Returns void

    • Start an Ace operation, which will then batch all the subsequent changes (to either content or selection) under a single atomic operation.

      Parameters

      • OptionalcommandEvent: { args?: any; command?: { name?: string } }

        Optional name for the operation

      Returns void

    • Parameters

      • OptionaltryToUnfold: boolean

      Returns void

    • Parameters

      • OptionaltoggleParent: boolean

      Returns void

    • Sets the value of overwrite to the opposite of whatever it currently is.

      Returns void

    • Parameters

      • e: any

      Returns void

    • Reverts previous changes to your document.

      Parameters

      • deltas: Ace.Delta[]

        An array of previous changes

      • OptionaldontSelect: boolean

        If true, doesn't select the range of where the change occured

      Returns void