# Emoji TextArea StyledText Bug?

**URL:** <https://forum.xojo.com/t/emoji-textarea-styledtext-bug/53669>\
**Category:** General\
**Created:** [May 5, 2020, 4:02pm UTC](https://forum.xojo.com/t/emoji-textarea-styledtext-bug/53669 "2020-05-05T16:02:34Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![GarryPettet](https://forum.xojo.com/user_avatar/forum.xojo.com/garrypettet/32/31_2.png) [@GarryPettet](https://forum.xojo.com/u/GarryPettet)\
**Post date:** [May 5, 2020, 4:02pm UTC](https://forum.xojo.com/t/emoji-textarea-styledtext-bug/53669/1 "2020-05-05T16:02:34Z")

</div>

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](https://cloud.pettet.xyz/index.php/s/wYqJ2j3WdRSxw22) (saved with Xojo 2019 r3.1).

Here’s a short screencast of the bug:

[https://vimeo.com/415187928](https://vimeo.com/415187928)

---

<div class="post-metadata">

**Author:** ![Martin\_T](https://forum.xojo.com/letter_avatar_proxy/v4/letter/m/a88e57/32.png) [@Martin\_T](https://forum.xojo.com/u/Martin_T)\
**Post date:** [May 5, 2020, 4:24pm UTC](https://forum.xojo.com/t/emoji-textarea-styledtext-bug/53669/2 "2020-05-05T16:24:18Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![anon93744516](https://forum.xojo.com/letter_avatar_proxy/v4/letter/a/5e9695/32.png) [@anon93744516](https://forum.xojo.com/u/anon93744516)\
**Post date:** [May 5, 2020, 4:41pm UTC](https://forum.xojo.com/t/emoji-textarea-styledtext-bug/53669/3 "2020-05-05T16:41:21Z")

</div>

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](https://forum.xojo.com/58137-string-encoding-multi-byte-letters)

---

<div class="post-metadata">

**Author:** ![GarryPettet](https://forum.xojo.com/user_avatar/forum.xojo.com/garrypettet/32/31_2.png) [@GarryPettet](https://forum.xojo.com/u/GarryPettet)\
**Post date:** [May 5, 2020, 5:48pm UTC](https://forum.xojo.com/t/emoji-textarea-styledtext-bug/53669/4 "2020-05-05T17:48:31Z")

</div>

> [@487415:@Martin Trippensee](#):
>
> 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.

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).

---

<div class="post-metadata">

**Author:** ![Martin\_T](https://forum.xojo.com/letter_avatar_proxy/v4/letter/m/a88e57/32.png) [@Martin\_T](https://forum.xojo.com/u/Martin_T)\
**Post date:** [May 5, 2020, 5:58pm UTC](https://forum.xojo.com/t/emoji-textarea-styledtext-bug/53669/5 "2020-05-05T17:58:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kevin\_g](https://forum.xojo.com/letter_avatar_proxy/v4/letter/k/65b543/32.png) [@kevin\_g](https://forum.xojo.com/u/kevin_g)\
**Post date:** [May 5, 2020, 6:24pm UTC](https://forum.xojo.com/t/emoji-textarea-styledtext-bug/53669/6 "2020-05-05T18:24:19Z")

</div>

> [@487426:@Garry Pettet](#):
>
> 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).

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](https://xojo.com/issue/58933)\>

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [April 29, 2021, 4:23pm UTC](https://forum.xojo.com/t/emoji-textarea-styledtext-bug/53669/7 "2021-04-29T16:23:42Z")

</div>


