DS Server

CommentCollection Object

Object|Introduced in 30.0

Description

Contains all comments in the main text or another part of a document. All comments are associated with a certain piece of text of the document. The collection consists of CommentedText objects, describing the position and length of the commented text and the comment string itself. A collection object can be obtained with the FormattedText.comments property.

Syntax

CommentCollection

Examples

The following example demonstrates CommentCollection in a practical document-editing workflow. It contains all comments in the main text or another part of a document. All comments are associated with a certain piece of text of the document. The collection consists of CommentedText objects, describing the position and length of the commented text and the comment string itself. A collection object can be obtained with the FormattedText.comments property.

function onTxError(error) {
    console.error("TX Text Control error:", error.msg);
    error.handled = true;
}

TXTextControl.textParts.getMainText(function(mainText) {
    const comments = mainText.comments;
    comments.getItem(
        function(comment) {
            if (!comment) {
                console.warn("No commented text was returned.");
                return;
            }
            
            console.log("get item result:", comment);
        },
        onTxError
    );
}, onTxError);

Members

Methods

MethodDescription
addCreates a comment with the specified comment string. The current text selection defines the commented text.
addAtPositionCreates a comment with the specified comment string, start position and length.
addReplyCreates a reply to an existing comment using the specified comment string.
elementAtReturns the element at a specified index in the collection. (Inherited from Collection.)
forEachExecutes a callback function for each element. (Inherited from Collection.)
getCountGets the number of elements contained in the collection. (Inherited from Collection.)
getItemGets the Comment containing the current text input position from the collection.
getNextItemGets the next comment in the text flow.
getPreviousItemGets the previous comment in the text flow.
removeRemoves a comment from the collection.