Suppose my HTML looks something like this
<div>
<p> start<span>span</span>end </p>
</div>
I need to be be able to get the offsets when a selection is made, without ignoring the span tags.
e.g.
suppose to user selected
t<span>span</span>e
I want the to get 4 as starting offset and 24 as the ending offset.
The selection object obtained via window.getSelection() returns 1,8, which is rather useless to me.
I obviously need to handle all cases where the user selects only the inner span, or part of the span etc.
Thanks
I’ve ended up solving it thusly:
basically, I’ve added a SPAN at the beginning of the range selection, then collapsed the range and added a SPAN at the end of it.
Then I simply searched for the index of the first span I’ve added, and the index of the second span I’ve added to find the offsets.