Ace API Reference
    Preparing search index...

    Class Document

    Contains the text of the document. Document can be attached to several [[EditSession EditSession]]s. At its core, Documents are just an array of strings, with each row in the document matching up to the array index.

    Index

    Constructors

    • Creates a new Document. If text is included, the Document contains those strings; otherwise, it's empty.

      Parameters

      • textOrLines: string | string[]

        text The starting text

      Returns Document

    Properties

    $autoNewLine: string
    $lines: string[]
    $newLineMode: any

    Methods

    • Parameters

      • text: string

      Returns void

    • Splits a string of text on any newline (\n) or carriage-return (\r) characters.

      Parameters

      • text: string

        The text to work with

      Returns string[]

      A String array, with each index containing a piece of the original text string.

      $split

    • Applies delta to the document.

      Parameters

      • delta: Ace.Delta

        A delta object (can include "insert" and "remove" actions)

      • OptionaldoNotValidate: boolean

      Returns void

    • Applies all changes in deltas to the document.

      Parameters

      • deltas: Ace.Delta[]

        An array of delta objects (can include "insert" and "remove" actions)

      Returns void

    • Creates a new Anchor to define a floating point in the document.

      Parameters

      • row: number

        The row number to use

      • column: number

        The column number to use

      Returns Anchor

    • Returns all lines in the document as string array.

      Returns string[]

    • Returns the number of rows in the document.

      Returns number

    • Returns a verbatim copy of the given line as it is in the document

      Parameters

      • row: number

        The row index to retrieve

      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 all the text within range as an array of lines.

      Parameters

      Returns string[]

    • Returns the newline character that's being used, depending on the value of newLineMode.

      Returns string

      If newLineMode == windows, \r\n is returned.
      If newLineMode == unix, \n is returned.
      If newLineMode == auto, the value of autoNewLine is returned.

    • Returns all the text within range as a single string.

      Parameters

      Returns string

    • Returns all the lines in the document as a single string, joined by the new line character.

      Returns string

    • Converts an index position in a document to a {row, column} object.

      Index refers to the "absolute position" of a character in the document. For example:

      var x = 0; // 10 characters, plus one for newline
      var y = -1;

      Here, y is an index 15: 11 characters for the first row, and 5 characters until y in the second.

      Parameters

      • index: number

        An index to convert

      • OptionalstartRow: number

        The row from which to start the conversion

      Returns Ace.Point

      A {row, column} object of the index position

    • Inserts a block of text at the indicated position.

      Parameters

      • position: Ace.Point

        The position to start inserting at; it's an object that looks like { row: row, column: column}

      • text: string

        A chunk of text to insert

      Returns Ace.Point

      The position ({row, column}) of the last line of text. If the length of text is 0, this function simply returns position.

    • Inserts the elements in lines into the document as full lines (does not merge with existing line), starting at the row index given by row. This method also triggers the "change" event.

      Parameters

      • row: number

        The index of the row to insert at

      • lines: string[]

        An array of strings

      Returns void

    • Inserts text into the position at the current row. This method also triggers the "change" event.

      This differs from the insert method in two ways:

      1. This does NOT handle newline characters (single-line text only).
      2. This is faster than the insert method for single-line text insertions.

      Parameters

      • position: Ace.Point

        The position to insert at; it's an object that looks like { row: row, column: column}

      • text: string

        A chunk of text without new lines

      Returns Ace.Point

      Returns the position of the end of the inserted text

    • Parameters

      • row: any
      • lines: any

      Returns void

    • Inserts the elements in lines into the document, starting at the position index given by row. This method also triggers the "change" event.

      Parameters

      • position: Ace.Point
      • lines: string[]

        An array of strings

      Returns Ace.Point

      Contains the final row and column, like this:

      {row: endRow, column: 0}
      

      If lines is empty, this function returns an object containing the current row, and column, like this:

      {row: row, column: 0}
      
    • Returns true if text is a newline character (either \r\n, \r, or \n).

      Parameters

      • text: string

        The text to check

      Returns boolean

    • Converts the {row, column} position in a document to the character's index.

      Index refers to the "absolute position" of a character in the document. For example:

      var x = 0; // 10 characters, plus one for newline
      var y = -1;

      Here, y is an index 15: 11 characters for the first row, and 5 characters until y in the second.

      Parameters

      • pos: Ace.Point

        The {row, column} to convert

      • OptionalstartRow: number

        The row from which to start the conversion

      Returns number

      The index position in the document

    • Removes the range from the document.

      Parameters

      • range: Ace.IRange

        A specified Range to remove

      Returns Ace.Point

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

    • Removes the specified columns from the row. This method also triggers a "change" event.

      Parameters

      • row: number

        The row to remove from

      • startColumn: number

        The column to start removing at

      • endColumn: number

        The column to stop removing at

      Returns Ace.Point

      Returns an object containing startRow and startColumn, indicating the new row and column values.
      If startColumn is equal to endColumn, this function returns nothing.

    • Parameters

      • firstRow: any
      • lastRow: any

      Returns string[]

    • Removes the new line between row and the row immediately following it. This method also triggers the "change" event.

      Parameters

      • row: number

        The row to check

      Returns void

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

      Parameters

      • range: Ace.IRange | Range

        A specified Range to replace

      • text: string

        The new text to use as a replacement

      Returns Ace.Point

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

    • Reverts delta from the document.

      Parameters

      • delta: Ace.Delta

        A delta object (can include "insert" and "remove" actions)

      Returns void

    • Reverts all changes in deltas from the document.

      Parameters

      • deltas: Ace.Delta[]

        An array of delta objects (can include "insert" and "remove" actions)

      Returns void

    • [Sets the new line mode.]{: #Document.setNewLineMode.desc}

      Parameters

      • newLineMode: Ace.NewLineMode

        [The newline mode to use; can be either windows, unix, or auto]

      Returns void

    • Replaces all the lines in the current Document with the value of text.

      Parameters

      • text: string

        The text to use

      Returns void