The name of the GetCurrentPositionInSpan
method is misleading, as it actually returns the index in the current SpanLayoutBox.
Following is the code of the method which gets the index of a DocumentPosition in the current span:
positionCounter = 0;
var currentSpanBox = position.GetCurrentSpanBox();
(spanLayoutBox == currentSpanBox)
positionCounter += position.GetCurrentPositionInSpan();
positionCounter += spanLayoutBox.Text.Length;
Could you also share more details about your scenario? We may be able to suggest better approach, as the mapping between position index and position in text is not always straight-forward - for example if there are images, tables, annotations (comments, bookmarks, etc.) or similar elements.
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.