Issue with ReplaceTextSmart in Text document API

Document Server version: 9.2.0

Hello team,

We recently started using the ReplaceTextSmart method from the Text Document API, but it does not seem to behave as expected when Track Changes is enabled.

Instead of replacing the word correctly, the method appears to merge characters.

Example:
If the text “Hello from” is replaced with “Hello on”, the expected result in Track Changes mode would be:

  • Hello from on

However, the actual result shows the characters being merged incorrectly

  • Hello from n

We are also seeing similar issues in multiple places, especially when replacing an entire paragraph. You can reproduce this in the playground using the attached .docx file.
Example Document Title.docx (69.5 KB)

Steps to reproduce

  1. Open the attached document in the OnlyOffice playground.
  2. Enable Track Changes.
  3. Select the paragraph.
  4. Run the following code:
var Editor = {
    callMethod: async function (name, args) {
        return new Promise(resolve => (function () {
            Asc.plugin.executeMethod(name, args || [], function (returnValue) {
                resolve(returnValue);
            });
        })());
    }
};

(async function () {
    let version = await Editor.callMethod("GetVersion");
    console.log("Version:", version);

    // Get the selected text first, using explicit separators that match ReplaceTextSmart
    const selectedText = await Editor.callMethod("GetSelectedText", [{
        Numbering: false,
        Math: false,
        TableCellSeparator: "\n",
        TableRowSeparator: "\r\n",
        ParaSeparator: "\r\n",
        TabSymbol: "\t",
        NewLineSeparator: "\r"
    }]);

    console.log("--- Selected Text ---");
    console.log(selectedText);
    console.log("Selected text length:", selectedText ? selectedText.length : 0);

    const arr = [
        `This Agreement shall commence on the Effective Date and continue a period of three (3) years obligations under this Agreement with respect to Confidential Information continue for three (3) years from the date of disclosure of the applicable Confidential Information Provided that the Parties enter into the agreement regarding the Purpose, the agreement shall prevail over this Confidential Information disclosed prior to expiration or termination of this Agreement shall continue to be governed by this Agreement until the end of the applicable Confidentiality Period. Upon request, Recipient shall promptly destroy or erase any Confidential Information it holds, except that the Recipient may retain Confidential Information that is: (i) securely stored in archival or computer back-up systems; or (ii) required to be retained to meet regulatory obligations or internal rules, provided, however, that any retained Confidential Information shall remain subject to the terms of this`
    ];

    const result = await Editor.callMethod("ReplaceTextSmart", [arr, "\t", "\r"]);
    console.log("ReplaceTextSmart result:", result);
})();

Notes

  • Track Changes must be enabled.
  • The target paragraph should be selected before running the script.

We would appreciate any guidance on:

  • Whether this is a known limitation of ReplaceTextSmart in Track Changes mode.
  • Any recommended workaround or alternative approach to apply changes properly.

Thank you.


Hello @editor_pro,

Thank you for reporting the issue. I see that you submitted the same request in our Helpdesk. Please avoid duplicating the requests.

Hello @editor_pro,

We have registered this issue as a bug. You will be notified when a new Document Server version containing the fix is released.