返回介绍

Document

发布于 2019-12-03 22:48:17 字数 28357 浏览 1128 评论 0 收藏 0

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

new Document(String | Array text)

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

textString | ArrayRequired. The starting text

Events

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

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:

eObjectRequired. 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.applyDeltas(Object deltas)

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

deltasObjectRequired.

Document.createAnchor(Number row, Number column)

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

rowNumberRequired. The row number to use
columnNumberRequired. The column number to use

Document.getAllLines()

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

Document.getLength()

Returns the number of rows in the document.

Document.getLine(Number row)

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

rowNumberRequired. The row index to retrieve

Document.getLines(Number firstRow, Number lastRow)

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

firstRowNumberRequired. The first row index to retrieve
lastRowNumberRequired. The final row index to retrieve

Document.getNewLineCharacter()

返回值: String

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

Document.getNewLineMode()

返回值: String

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

Document.getTextRange(Range range)

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

rangeRangeRequired. The range to work with

Document.getValue()

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

Document.indexToPosition(Number index, Number startRow)

返回值: Object

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.

indexNumberRequired. An index to convert
startRowNumberRequired. =0 The row from which to start the conversion

Document.insert(Object position, String text)

返回值: Object

Inserts a block of text and the indicated position.

positionObjectRequired. The position to start inserting at
textStringRequired. A chunk of text to insert

Document.insertInLine(Object position, String text)

返回值: Object

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

positionObjectRequired. The position to insert at
textStringRequired. A chunk of text

DocuZment.insertLines(Number row, Array lines)

返回值: Object

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

rowNumberRequired. The index of the row to insert at
linesArrayRequired. An array of strings

Document.insertNewLine(Object position)

返回值: Object

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

positionObjectRequired. The position to insert at

Document.isNewLine(String text)

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

textStringRequired. The text to check

Document.positionToIndex(Object pos, Number startRow)

返回值: Number

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.

posObjectRequired. The {row, column} to convert
startRowNumberRequired. =0 The row from which to start the conversion

Document.remove(Range range)

返回值: Object

Removes the range from the document.

rangeRangeRequired. A specified Range to remove

Document.removeInLine(Number row, Number startColumn, Number endColumn)

返回值: Object

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

rowNumberRequired. The row to remove from
startColumnNumberRequired. The column to start removing at
endColumnNumberRequired. The column to stop removing at

Document.removeLines(Number firstRow, Number lastRow)

返回值: String

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

firstRowNumberRequired. The first row to be removed
lastRowNumberRequired. The last row to be removed

Document.removeNewLine(Number row)

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

rowNumberRequired. The row to check

Document.replace(Range range, String text)

返回值: Object

Replaces a range in the document with the new text.

rangeRangeRequired. A specified Range to replace
textStringRequired. The new text to use as a replacement

Document.revertDeltas(Object deltas)

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

deltasObjectRequired.

Document.setNewLineMode(String newLineMode)

Sets the new line mode.

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

Document.setValue(String text)

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

textStringRequired. The text to use

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文