Creates a new Document
. If text
is included, the Document
contains those strings; otherwise, it's empty.
text The starting text
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:
"insert"
range
: the Range of the change within the document
lines
: the lines being added
"remove"
range
: the Range of the change within the document
lines
: the lines being removed
Applies delta
to the document.
A delta object (can include "insert" and "remove" actions)
Applies all changes in deltas
to the document.
An array of delta objects (can include "insert" and "remove" actions)
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 all the text within range
as an array of lines.
The range to work with.
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
]{: #Document.getNewLineMode}
Returns all the text within range
as a single string.
The range to work with.
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
A {row, column}
object of the index
position
Inserts a block of text
at the indicated position
.
The position to start inserting at; it's an object that looks like { row: row, column: column}
A chunk of text to insert
The position ({row, column}) of the last line of text
. If the length of text
is 0, this function simply returns position
.
Inserts a block of text
at the indicated position
.
The position to start inserting at; it's an object that looks like { row: row, column: column}
A chunk of text to insert
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.
The index of the row to insert at
An array of strings
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}
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:
This does NOT handle newline characters (single-line text only).
This is faster than the insert
method for single-line text insertions.
The position to insert at; it's an object that looks like { row: row, column: column}
A chunk of text
Returns an object containing the final row and column, like this:
{row: endRow, column: 0}
Deprecated methods retained for backwards compatibility.
Inserts the elements in lines
into the document, starting at the position index given by row
. This method also triggers the "change"
event.
An array of strings
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 {row, column}
to convert
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
.
A specified Range to replace
The new text to use as a replacement
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.
A delta object (can include "insert" and "remove" actions)
Reverts all changes in deltas
from the document.
An array of delta objects (can include "insert" and "remove" actions)
[Sets the new line mode.]{: #Document.setNewLineMode.desc}
{: #Document.setNewLineMode.param}
Replaces all the lines in the current Document
with the value of text
.
The text to use
Generated using TypeDoc
Contains the text of the document. Document can be attached to several
EditSession
s. At its core,Document
s are just an array of strings, with each row in the document matching up to the array index.