Emoji TextArea StyledText Bug?

Take a look at the video below. Is this a bug or am I misunderstanding how to use a TextArea's StyledText object? Whenever the button is clicked, I am toggling the colour of the TextArea's StyledText between start position 0 for a length of 4 characters using TextArea1.StyledText.TextColor(0, 4) = someColor.

As you can see in the video, if the text in the TextArea is "ABCD" then it works however if I delete the "A" and replace it with the grinning emoji (using the Touch Bar on my Mac) then only letters "BC" are toggled to red. I would expect "BCD" to go red. It looks like the StyledText object is treating the emoji as two characters.

I’ve uploaded the demo app as a binary Xojo project here (saved with Xojo 2019 r3.1).

Here’s a short screencast of the bug:

https://vimeo.com/415187928

It’s not a bug. You have to find out yourself how big a letter is, i.e. how many characters it consists of (String.Length). The text datatype handled this better, but String is and will always be the “future”. If Xojo should transfer some properties of the text data type to String in the coming releases, the handling could possibly become better. Until then you have to find a solution for this yourself, unfortunately.

Not that this is a solution, but this thread may help to understand a little more of how emojis are constructed, and how that fits in with the Xojo String and Text types.

https://forum.xojo.com/58137-string-encoding-multi-byte-letters

That’s really interesting. Does this in essence mean that StyledText is counting the length of styles using bytes rather than characters? It seems to be taking the character count as a parameter but internally using the number of bytes. If so, that smells like a bug (or at least incorrectly documented).

Right. I suppose this dates back to RealBasic times, when UTF-8 was still in the future.

Counting Unicode code points would be a more accurate description. Emojis are more complex as they are built from multiple Unicode code points.

see this feedback case for more info:
<https://xojo.com/issue/58933>