Contains the text of the document. Document can be attached to several EditSessions. 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.

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

Arguments

textString | Array

Required. The starting text

Events

    • Document.on("change", function(Object e))

    Fires whenever the document changes.

    Fires whenever the document changes.

    Several methods trigger different "change" events. Below is a list of each action type, followed by each property that's also available:

    Arguments

    eObject

    Required. Contains at least one property called "action". "action" indicates the action that triggered the change. Each action also has a set of additional properties.

    Methods

      • Document.$clipPosition(position)
      • Internal
      • Document.$detectNewLine(text)
        • Void
      • Internal

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

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

    Arguments

    textString

    Required. The text to work with

    Returns

    Array of Strings

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

      • Document.applyDeltas(deltas)
        • Void

      Applies all the changes previously accumulated. These can be either 'includeText', 'insertLines', 'removeText', and 'removeLines'.

      Applies all the changes previously accumulated. These can be either 'includeText', 'insertLines', 'removeText', and 'removeLines'.

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

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

      Arguments

      rowNumber

      Required. The row number to use

      columnNumber

      Required. The column number to use

        • Document.getAllLines()

        Returns all lines in the document as string array. Warning: The caller should not modify this array!

        Returns all lines in the document as string array. Warning: The caller should not modify this array!

        Returns the number of rows in the document.

        Returns the number of rows in the document.

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

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

        Arguments

        rowNumber

        Required. The row index to retrieve

        Returns an array of strings of the rows between firstRow and lastRow. This function is inclusive of lastRow.

        Returns an array of strings of the rows between firstRow and lastRow. This function is inclusive of lastRow.

        Arguments

        firstRowNumber

        Required. The first row index to retrieve

        lastRowNumber

        Required. The final row index to retrieve

          • Document.getNewLineCharacter()

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

          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.

            • Document.getNewLineMode()

            Returns the type of newlines being used; either windows, unix, or auto

            Returns the type of newlines being used; either windows, unix, or auto

            Given a range within the document, this function returns all the text within that range as a single string.

            Given a range within the document, this function returns all the text within that range as a single string.

            Arguments

            rangeRange

            Required. The range to work with

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

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

            Arguments

            positionNumber

            Required. The position to start inserting at

            textString

            Required. A chunk of text to insert

            Returns

            Number

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

            • Inserts a block of text and the indicated position.

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

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

            Arguments

            positionNumber

            Required. The position to insert at

            textString

            Required. A chunk of text

            Returns

            Object

            Returns an object containing the final row and column, like this:

            • {row: endRow, column: 0}
            Number

            If text is empty, this function returns the value of position

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

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

            Arguments

            rowNumber

            Required. The index of the row to insert at

            linesArray

            Required. An array of strings

            Returns

            Object

            Returns an object containing 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}

            Inserts a new line into the document at the current row's position. This method also triggers the 'change' event.

            Inserts a new line into the document at the current row's position. This method also triggers the 'change' event.

            Arguments

            positionString

            Required. The position to insert at

            Returns

            Object

            Returns an object containing the final row and column, like this:

            • {row: endRow, column: 0}

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

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

            Arguments

            textString

            Required. The text to check

            Removes the range from the document.

            Removes the range from the document.

            Arguments

            rangeRange

            Required. A specified Range to remove

            Returns

            Object

            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 the specified columns from the row. This method also triggers the 'change' event.

            Removes the specified columns from the row. This method also triggers the 'change' event.

            Arguments

            rowNumber

            Required. The row to remove from

            startColumnNumber

            Required. The column to start removing at

            endColumnNumber

            Required. The column to stop removing at

            Returns

            Object

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

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

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

            Arguments

            firstRowNumber

            Required. The first row to be removed

            lastRowNumber

            Required. The last row to be removed

            Returns

            Array of Strings

            Returns all the removed lines.

              • Document.removeNewLine(Number row)
                • Void

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

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

              Arguments

              rowNumber

              Required. The row to check

              Replaces a range in the document with the new text.

              Replaces a range in the document with the new text.

              Arguments

              rangeRange

              Required. A specified Range to replace

              textString

              Required. The new text to use as a replacement

              Returns

              Object

              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.

                • Document.revertDeltas(deltas)
                  • Void

                Reverts any changes previously applied. These can be either 'includeText', 'insertLines', 'removeText', and 'removeLines'.

                Reverts any changes previously applied. These can be either 'includeText', 'insertLines', 'removeText', and 'removeLines'.

                  • Document.setNewLineMode(String newLineMode)
                    • Void

                  Sets the new line mode.

                  Sets the new line mode.

                  Arguments

                  newLineModeString

                  Required. The newline mode to use; can be either windows, unix, or auto

                    • Document.setValue(String text)
                      • Void

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

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

                    Arguments

                    textString

                    Required. The text to use