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
fromon
However, the actual result shows the characters being merged incorrectly
- Hello
fromn
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
- Open the attached document in the OnlyOffice playground.
- Enable Track Changes.
- Select the paragraph.
- 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
ReplaceTextSmartin Track Changes mode. - Any recommended workaround or alternative approach to apply changes properly.
Thank you.