Parsing BBCode and setting "currentSelection" issues

[SIZE=1]First I’d like to make it clear that I haven’t started developing anything yet. This is just a “potential roadblock” that I’m tossing around in my mind. This is not time-critical, and knowing me, I may not even get around to finishing it anyway. Still, it’s a problem that must be solved.[/SIZE]

Let’s say you have a class which converts BBCode to AS3-friendly html and displays that formatted text in an AS3 TextField.

If the user selects a region of the formatted text (which gives a “selectionBeginIndex” and “selectionEndIndex”), how would one efficiently “map” that selection back to the BBCode? Since any BBCode within the text may offset the selection indexes.