How to insert TMP Inputfield caret position inside a Rich Text tag?

I want to allow user to be able to bold text in the TMP inputfield. So I tried with the following code to position the caret inside the tag. But I noticed manipulating caretPosition will skip tags, how can I put the caret inside?

string tag = "<b></b>";
inputField.text = inputField.text.Insert(caretPosition, tag);
inputField.caretPosition += 3;

I learned from this thread about the inner cared, which is named stringPosition

2 Likes

Thank you very much! I spent like 2 hours for this, thank you !!