TurboWarp / scratch-vm

Scratch VM with a JIT compiler and more features
https://turbowarp.org/
Mozilla Public License 2.0
75 stars 72 forks source link

Emojis won't render/work from lists using "letter of" block #128

Closed Scratchfangs closed 9 months ago

Scratchfangs commented 1 year ago

Expected Behavior

image

Actual Behavior

image

Steps to Reproduce

image

Operating System and Browser

Edge 112.0.1722.48, Windows 11

GarboMuffin commented 1 year ago

this is also a Scratch issue and a JavaScript issue in general

Johan-Mi commented 9 months ago

This happens because string indexing in Scratch uses UTF-16 code units (16 bits each) instead of Unicode code points (what's typically considered a "character"). Using code points would fix this specific case but would make string indexing $O(n)$ since code points aren't all the same length. The even more correct solution would be to use grapheme clusters, which among other things count letters with diacritics as one character and support composed emoji like skin tones and country flags. This would also be $O(n)$.

GarboMuffin commented 9 months ago

Yeah, we can't change this without breaking Scratch compatibility, and it would be slow

Seems like something that would work well in an extension