Text area having extremely odd behavior while using rich text?

Hello all,

I am trying to create a simple rich text editor for in game use and have run into some funny behavior.

When using the following GUI code, the cursor seems to have issue correctly navagating around the rich text formatting.

What I have noticed happening when I move the carrot with my arrow keys ( starting at the very first character ) is that it skips the first word, then moves onto the rich text and parses it letter by letter as expected. followed with halting at the third word for a few clicks then proceeding to parse the third word correctly.

Any ideas how to fix this issue?

void OnGUI() {
 
GUIStyle textStyle = new GUIStyle();
textStyle.normal.textColor = Color.white;
textStyle.wordWrap = true;
textStyle.richText = true;
 
GUI.TextArea(new Rect(20,20,200,50), "normal <color=green> green </color> normal", textStyle);
}

Because the different components rely on GUI Style, RichText works in a lot of places, but editing in real time is broken. The cursor position is based on where it is in the real text, with tags, not what is displayed.

(replacing

 with cursor) In the following text I'll show whats actually happening:

"a <b>bold[c]</b> word"  shows as "a **bold**[c] word" 

but if I press right it becomes this:

"a <b>bold<[c]/b> word"  shows as "[c]a **bold** word" 

Notice how the [c] is actually in the closing bold tag now?  Also, how it is displayed (sometimes) as if the cursor is at the beginning?  This issue is accentuated further if you were to press backspace, as it would delete the "<", disrupting the tags, and showing it in real text, not rich:

"a <b>bold[c]/b> word"  shows as "a <b>bold[c]/b> word" 


----------


**SOLUTION** (sort of): [39690-richtexteditorcs.txt|39690]

I've attached a script I've been working on, which checks if you are positioned in a tag, and if you are, it keeps moving the direction you were heading until the cursor position is correct.  It works for arrow keys pretty well, but selections between bold/unbold words only work in some conditions.  The code is still in Dagiw (Do Anything, Get It Working), so ugly.

If you improve on it, I'd really appreciate getting a copy of the enhancements.

 - Thanks!