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.

Constructors

Properties

Accessors

Methods

$clipColumnToRow $clipPositionToDocument $clipRangeToDocument $clipRowToDocument $computeWidth $computeWrapSplits $constrainWrapLimit $detectNewLine $getDisplayTokens $getRowCacheIndex $getStringScreenWidth $getUndoSelection $initOperationListeners $moveLines $onChangeMode $resetRowCache $setFontMetrics $startWorker $stopWorker $updateInternalDataOnChange $updateRowLengthCache $updateWrapData addDynamicMarker addGutterCustomWidget addGutterDecoration addMarker adjustWrapLimit clearAnnotations clearBreakpoint clearBreakpoints destroy documentToScreenColumn documentToScreenPosition documentToScreenRow duplicateLines endOperation getAWordRange getAnnotations getBreakpoints getDocument getDocumentLastRowColumn getDocumentLastRowColumnPosition getLength getLine getLineWidgetMaxWidth getLines getMarkers getMode getNavigateWithinSoftTabs getNewLineMode getOverwrite getPrecedingCharacter getRowLength getRowLineCount getRowSplitData getRowWrapIndent getScreenLastRowColumn getScreenLength getScreenTabSize getScreenWidth getScrollLeft getScrollTop getSelection getState getTabSize getTabString getTextRange getTokenAt getTokens getUndoManager getUseSoftTabs getUseWorker getUseWrapMode getWordRange getWrapLimit getWrapLimitRange highlight highlightLines indentRows insert isTabStop markUndoGroup moveLinesDown moveLinesUp moveText onChange onChangeFold onReloadTokenizer onSelectionChange outdentRows redoChanges remove removeFullLines removeGutterCustomWidget removeGutterDecoration removeMarker replace resetCaches screenToDocumentColumn screenToDocumentPosition screenToDocumentRow setAnnotations setBreakpoint setBreakpoints setDocument setMode setNavigateWithinSoftTabs setNewLineMode setOverwrite setScrollLeft setScrollTop setTabSize setUndoManager setUndoSelect setUseSoftTabs setUseWorker setUseWrapMode setValue setWrapLimit setWrapLimitRange startOperation toJSON toString toggleOverwrite undoChanges fromJSON

Constructors

  • Sets up a new EditSession and associates it with the given Document and Mode.

    Parameters

    • Optional text: string | Document

      [If text is a Document, it associates the EditSession with it. Otherwise, a new Document is created, with the initial text]{: #textParam}

    • Optional mode: SyntaxMode

      [The initial language mode to use for the document]{: #modeParam}

    Returns EditSession

Properties

$annotations: Annotation[]
$autoNewLine: string
$backMarkers: {}

Type declaration

    $bidiHandler: BidiHandler
    $breakpoints: any[]
    $decorations: any[]
    $defaultUndoManager: {
        add: (() => void);
        addSelection: (() => void);
        addSession: (() => void);
        hasRedo: (() => void);
        hasUndo: (() => void);
        redo: (() => void);
        reset: (() => void);
        startNewGroup: (() => void);
        undo: (() => void);
    }

    Type declaration

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

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

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

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

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

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

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

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

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

    $docRowCache: number[]
    $editor: any
    $foldData: FoldLine[]
    $fromUndo: boolean
    $frontMarkers: {}

    Type declaration

      $gutterCustomWidgets: {}

      Type declaration

        $informUndoManager: {
            schedule: { (timeout?: number): void; delay(timeout?: number): void; schedule: ...; call(): void; cancel(): void; isPending(): any; };
            call(): void;
            cancel(): void;
            delay(timeout?): void;
            isPending(): any;
            (timeout?): void;
        }

        Type declaration

          • (timeout?): void
          • Parameters

            • Optional timeout: number

            Returns void

        • schedule: { (timeout?: number): void; delay(timeout?: number): void; schedule: ...; call(): void; cancel(): void; isPending(): any; }
        • call:function
        • cancel:function
        • delay:function
          • Parameters

            • Optional timeout: number

            Returns void

        • isPending:function
        $lastSel: Range | Range[]
        $markerId: number
        $mode: any
        $modeId: any
        $modes: {}

        Type declaration

          $modified: boolean
          $onChange: any
          $onSelectionChange: any
          $operationResetTimer: {
              schedule: { (timeout?: number): void; delay(timeout?: number): void; schedule: ...; call(): void; cancel(): void; isPending(): any; };
              call(): void;
              cancel(): void;
              delay(timeout?): void;
              isPending(): any;
              (timeout?): void;
          }

          Type declaration

            • (timeout?): void
            • Parameters

              • Optional timeout: number

              Returns void

          • schedule: { (timeout?: number): void; delay(timeout?: number): void; schedule: ...; call(): void; cancel(): void; isPending(): any; }
          • call:function
          • cancel:function
          • delay:function
            • Parameters

              • Optional timeout: number

              Returns void

          • isPending:function
          $overwrite: boolean
          $rowLengthCache: any[]
          $screenRowCache: number[]
          $scrollLeft: any
          $scrollTop: any
          $searchHighlight: MarkerLike
          $syncInformUndoManager: (() => void) | (() => void)

          Type declaration

            • (): void
            • Returns void

          Type declaration

            • (): void
            • Returns void

          $undoManager: UndoManager
          $undoSelect: boolean
          $updating: boolean
          $useWrapMode: any
          $worker: any
          $wrapData: any[]
          $wrapLimit: any
          $wrapLimitRange: any
          bgTokenizer: BackgroundTokenizer
          curOp: Operation
          destroyed: boolean
          doc: Document
          getValue: (() => string)

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

          Type declaration

            • (): string
            • Returns the current [[Document Document]] as a string.

              Returns string

              Method

              getValue

              Alias

              EditSession.toString

          Method

          getValue

          Returns

          Alias

          EditSession.toString

          id: string
          isFullWidth: ((c) => boolean)

          Type declaration

            • (c): boolean
            • Parameters

              • c: any

              Returns boolean

          lineWidgetWidth: number
          lineWidgets: LineWidget[]
          mergeUndoDeltas: boolean
          nonTokenRe: RegExp
          prevOp: {}

          Type declaration

            screenWidth: any
            selection: Selection
            tokenRe: RegExp
            $uid: number

            Accessors

            • get widgetManager(): LineWidgets
            • Get "widgetManager" from EditSession

              Returns LineWidgets

              object

            • set widgetManager(value): void
            • Set "widgetManager" in EditSession

              Parameters

              • value: LineWidgets

              Returns void

              void

            Methods

            • Parameters

              • row: number
              • column: number

              Returns number

            • Parameters

              • row: number
              • column: number

              Returns Point

            • Parameters

              • tokens: number[]
              • wrapLimit: number
              • tabSize: number

              Returns any[]

            • Parameters

              • wrapLimit: number
              • Optional min: number
              • Optional max: number

              Returns number

            • If text contains either the newline (\n) or carriage-return ('\r') characters, $autoNewLine stores that value.

              Parameters

              • text: string

                A block of text

              Returns void

            • Given a string, returns an array of the display characters, including tabs and spaces.

              Parameters

              • str: string

                The string to check

              • Optional offset: number

                The value to start at

              Returns number[]

            • Parameters

              • cacheArray: any
              • val: any

              Returns number

            • Calculates the width of the string str on the screen while assuming that the string starts at the first column on the screen.

              Parameters

              • str: string

                The string to calculate the screen width of

              • Optional maxScreenColumn: number
              • Optional screenColumn: number

              Returns number[]

              Returns an int[] array with two elements:
              The first position indicates the number of columns for str on screen.
              The second value contains the position of the document column that this function read until.

            • Parameters

              • deltas: Delta[]
              • Optional isUndo: boolean

              Returns Range

            • Parameters

              • firstRow: number
              • lastRow: number
              • Optional dir: any

              Returns number

            • Parameters

              • mode: any
              • Optional $isPlaceholder: any

              Returns void

            • Parameters

              • docRow: number

                The row to work with

              Returns void

            • Parameters

              • firstRow: number
              • lastRow: number

              Returns void

            • Parameters

              • firstRow: number
              • lastRow: number

              Returns void

            • Adds a dynamic marker to the session.

              Parameters

              • marker: MarkerLike

                object with update method

              • Optional inFront: boolean

                Set to true to establish a front marker

              Returns MarkerLike

              The added marker

            • 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

              • Optional type: "line" | "text" | MarkerRenderer | "fullLine" | "screenLine"

                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.

              • Optional inFront: 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 | Point
              • Optional docColumn: number

              Returns number

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

              Parameters

              • docRow: number | Point

                The document row to check

              • Optional docColumn: number

                The document column to check

              Returns Point

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

              Related

              EditSession.screenToDocumentPosition

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

              Parameters

              • docRow: number | Point
              • Optional docColumn: 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

              • Optional e: any

              Returns void

            • 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 the annotations for the EditSession.

              Returns Annotation[]

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

              Returns string[]

            • Returns the Document associated with this session.

              Returns Document

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

            • 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

              • Optional inFront: boolean

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

              Returns {
                  [id: number]: Ace.MarkerLike;
              }

              • [id: number]: Ace.MarkerLike
            • Returns the current text mode.

              Returns SyntaxMode

              The current text mode

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

              Returns boolean

            • Returns the current new line mode.

              Returns NewLineMode

              Related

              Document.getNewLineMode

            • Returns true if overwrites are enabled; false otherwise.

              Returns boolean

            • Returns string

              the last character preceding the cursor in the editor

            • 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

              Related

              EditSession.documentToScreenColumn

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

              Related

              BackgroundTokenizer.getState

            • 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

            • {:Document.getTextRange.desc}

              Parameters

              • Optional range: IRange

                The range to work with

              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 the value of wrap limit.

              Returns number

              The wrap limit.

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

              Parameters

              • startRow: number
              • endRow: number
              • clazz: string
              • Optional inFront: 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: Point

                The position {row, column} to start inserting at

              • text: string

                A chunk of text to insert

              Returns Point

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

            • Returns true if the character at the position is a soft tab.

              Parameters

              • position: Point

                The position to check

              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: Point

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

              • Optional copy: boolean

              Returns Range

              The new range where the text was moved to.

            • Internal

              Reloads all the tokens on the current session. This function calls [[BackgroundTokenizer.start BackgroundTokenizer.start ()]] to all the rows; it also emits the 'tokenizerUpdate' event.

              Parameters

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

                An array of previous changes

              • Optional dontSelect: boolean

                {:dontSelect}

              Returns void

            • Removes the range from the document.

              Parameters

              • range: IRange

                A specified Range to remove

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

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

              Related

              Document.removeFullLines

            • 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: IRange

                A specified Range to replace

              • text: string

                The new text to use as a replacement

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

              Related

              Document.replace

            • 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

              • Optional offsetX: number

                screen character x-offset [optional]

              Returns Point

              The object returned has two properties: row and column.

              Related

              EditSession.documentToScreenPosition

            • Parameters

              • screenRow: number
              • screenColumn: number

              Returns number

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

              Parameters

              • annotations: Annotation[]

                A list of annotations

              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

            • 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

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

                Set a new text mode

              • Optional cb: (() => void)

                optional callback

                  • (): void
                  • Returns void

              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

            • {:Document.setNewLineMode.desc}

              Parameters

              • newLineMode: NewLineMode

                {:Document.setNewLineMode.param}

              Returns void

              Related

              Document.setNewLineMode

            • 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

              • Optional commandEvent: {
                    args?: any;
                    command?: {
                        name?: string;
                    };
                }

                Optional name for the operation

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

              Returns void

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

              Returns string

              Method

              toString

              Alias

              EditSession.getValue

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

              Returns void

            • Reverts previous changes to your document.

              Parameters

              • deltas: Delta[]

                An array of previous changes

              • Optional dontSelect: boolean

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

              Returns void

            • Returns a new instance of EditSession with state from JSON.

              Parameters

              • session: any

                The EditSession state.

              Returns EditSession

              Method

              fromJSON

            Generated using TypeDoc