Offset cursor position by rich text tags

Hello. I have a text box that uses rich text tags and I want to get the user’s cursor position when they focus the text box.
Say the text box contains this:
This is what will show with the text box when it is not being edited:

However, with a text box, once you edit the text box the tags will show again, as this is how text boxes work.
Say you clicked between the H and the i, this will produce a cursor position of 2 as it is the second position of the text without tags, so when the tags are revealed the cursor will move just before the b in the bold tag. I want the cursor to be put where it was before, just after the H.

To put this visually: ("|" indicates the cursor)
Desired result:
Actual result: