Creates a new Document. If text is included, the Document contains those strings; otherwise, it's empty.
text The starting text
Creates a new Anchor to define a floating point in the document.
The row number to use
The column number to use
Returns all lines in the document as string array.
Returns the number of rows in the document.
Returns a verbatim copy of the given line as it is in the document
The row index to retrieve
Returns an array of strings of the rows between firstRow and lastRow. This function is inclusive of lastRow.
The first row index to retrieve
The final row index to retrieve
Returns the newline character that's being used, depending on the value of newLineMode.
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
Returns all the lines in the document as a single string, joined by the new line character.
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.
An index to convert
OptionalstartRow: numberThe row from which to start the conversion
A {row, column} object of the index 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.
The index of the row to insert at
An array of strings
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:
insert method for single-line text insertions.Returns the position of the end of the inserted text
Inserts the elements in lines into the document, starting at the position index given by row. This method also triggers the "change" event.
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).
The text to check
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.
The index position in the document
Removes a range of full lines. This method also triggers the "change" event.
The first row to be removed
The last row to be removed
Returns all the removed lines.
Removes the specified columns from the row. This method also triggers a "change" event.
The row to remove from
The column to start removing at
The column to stop removing at
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 the new line between row and the row immediately following it. This method also triggers the "change" event.
The row to check
Replaces a range in the document with the new text.
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.
[Sets the new line mode.]{: #Document.setNewLineMode.desc}
[The newline mode to use; can be either windows, unix, or auto]
Replaces all the lines in the current Document with the value of text.
The text to use
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.