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.

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

  • Private

    Parameters

    • position: Point

    Returns Point

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

    Method

    $split

  • Parameters

    • delta: Delta
    • MAX: number

    Returns void

  • Applies delta to the document.

    Parameters

    • delta: Delta

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

    • Optional doNotValidate: boolean

    Returns void

  • Applies all changes in deltas to the document.

    Parameters

    • deltas: Delta[]

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

    Returns void

  • Parameters

    • row: number
    • column: number

    Returns Point

  • 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

    • range: IRange

      The range to work with.

    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 the type of newlines being used; either windows, unix, or auto]{: #Document.getNewLineMode}

    Returns NewLineMode

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

    Parameters

    • range: IRange

      The range to work with.

    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

    • Optional startRow: number

      The row from which to start the conversion

    Returns Point

    A {row, column} object of the index position

  • Inserts a block of text at the indicated position.

    Parameters

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

    Returns the position of the end of the inserted text

  • Parameters

    • row: any
    • lines: any

    Returns void

    Deprecated

  • 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: Point
    • lines: string[]

      An array of strings

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

    • position: any

    Returns Point

    Deprecated

  • Returns true if text is a newline character (either \r\n, \r, or \n).

    Parameters

    • text: string

      The text to check

    Returns boolean

  • Parameters

    • row: number
    • column: number

    Returns Point

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

      The {row, column} to convert

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

      A specified Range to remove

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

    Deprecated

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

      A specified Range to replace

    • text: string

      The new text to use as a replacement

    Returns 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: Delta

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

    Returns void

  • Reverts all changes in deltas from the document.

    Parameters

    • deltas: Delta[]

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

    Returns void

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

    Parameters

    • newLineMode: NewLineMode

      [The newline mode to use; can be either windows, unix, or auto]{: #Document.setNewLineMode.param}

    Returns void

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

    Parameters

    • text: string

      The text to use

    Returns void

Generated using TypeDoc