Quick answer: Godot 4 RichTextLabel returning wrong character index when BBCode is enabled? get_character_at returns visual index, not source - parse BBCode separately for source-position queries.
Click on a word in BBCode-formatted text. Lookup returns the wrong character; chat highlighting points at unrelated text.
Use visible_characters
For cursor queries, work in visible space. BBCode tags don't count as visible characters; visible index is what get_character_at returns.
Or maintain a source map
Build a mapping from visible index to source index at parse time. Lookup is O(1); accurate for any query.
Disable BBCode for cursor-heavy UI
For text fields where the player clicks frequently, plain TextEdit avoids the BBCode index dance entirely.
“BBCode parsing creates two coordinate systems. Document the conversion.”
If you ship rich text input (chat, comments), test cursor position with mixed BBCode + emoji + multi-byte text. The bug class hides in the edges.