DS Server

Javascript: SectionCollection.addAtTextPosition Method

Method|Introduced in 28.0

Description

Adds a new section at the specified text input position. The new section ends at the end position of the section containing the input position. If a new section is inserted in a paragraph or table, the paragraph or table is split into two paragraphs or tables.

Syntax

<void> SectionCollection.addAtTextPosition(<SectionBreakKind> sectionBreakKind, <number> textPosition, [<RequestBooleanCallback> callback], [<ErrorCallback> errorCallback])

Parameters

ParameterDescription
sectionBreakKind

Specifies the kind of section's break.

textPosition

Specifies the text position at which the section is to be inserted.

callback

Optional. Receives whether the section could be added.

errorCallback

Optional. Is called when the operation failed with an error.

Examples

The following example demonstrates SectionCollection.addAtTextPosition in a practical document-editing workflow. It adds a new section at the specified text input position. The new section ends at the end position of the section containing the input position. If a new section is inserted in a paragraph or table, the paragraph or table is split into two paragraphs or tables.

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

TXTextControl.sections.addAtTextPosition(
    TXTextControl.SectionBreakKind.BeginAtNewLine,
    -1,
    function(result) {
        if (result) {
            console.log("add at text position is available.");
        } else {
            console.warn("add at text position is not available in the current document state.");
        }
    },
    onTxError
);