Bookmark not returning exact range taht i have added

Do you want to: Suggest a feature / Report a bug / Ask a how-to question
For feature suggestions, describe the result you would like to achieve in detail:
For bug reports, provide the steps to reproduce and if possible a minimal demo of the problem:
Document Server version:
Additional information:
Any relevant details about the situation. You can also attach images and videofile to the post (or to place them to external storage)

I am using below code to fetch document pharagraph text , doing some validations, getting the range and adding as a bookmark. But when user goes to Menu->References->Bookmarks → Click on bookmark → GOto Button. Cursor is going to the location but also selecting some additional text which is ahead or later. How to fix this range issue.

window.Asc.plugin.callCommand(function () {
let objTtile18Style = {
  "StyleName": "Tile18",
  "FontName": "Arial",
};
		
var oTextPr; var oParaPr;
var oDocument = Api.GetDocument();                                    
//header Test
var totallength = 0;
console.log("Number of elements oDocument : " + oDocument.GetElementsCount());
for(let i=0;i<oDocument.GetElementsCount();i++)
{
	var ephara=oDocument.GetElement(i);
	var paratext=ephara.GetText();
	var oContentLength = paratext.length;
	 try{
            oFontName = paratext.GetFontNames();
        } catch(error) { 
        }
        var firstFontName = oFontName ? oFontName[0] : null;

        // Compare the style with the defined style
        if (oStyleName !== objTtile18Style.StyleName || firstFontName !== objTtile18Style.FontName) {
            if (oStyleName !== objTtile18Style.StyleName) {
 
            }
            if (firstFontName !== objTtile18Style.FontName) {
               
               // console.log("The first font name '" + firstFontName + "' does not match with the defined font '" + objTtile18Style.FontName + "'. //Content: \"" + oContent + "\"");
                console.log("Content starts at position: " + totallength);
                console.log("Content ends at position: " + (totallength + oContentLength - 1));
				var rangestart= totallength;
				var rangeends = totallength + oContentLength - 1;
				
					var oRange = oDocument.GetRange(rangestart, rangeends);
					var tt= paratext.toString();
					var nContentControlType = 1;
	                oRange.AddBookmark("Error at :" +paratext);
				
	console.log("element :" +i  + "oDocument get element:" + paratext);
}
		}totallength += oContentLength;
}

Hello @sanjeevareddy.nagire

As I can see you are using quite a math expression to calculate the range. Please try troubleshooting it with GetBookmarkRange method. For instance, check which value your oRange variable have before adding a bookmark and which value is returned afterwards. It would help understanding whether both ranges coincide or not.


However, in general I’d recommend contacting our sales department via sales@onlyoffice.com to discuss possibilities of detailed code analysis as it may require quite more attention.