gluonhq / rich-text-area

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Text with emojis and Document issues

jperedadnr opened this issue · comments

When a given text has emoji unicode characters, its length for serialisation via Document depends on the total number of characters of the emoji, while its internal representation uses 1 character only.

For this text: "Text \ud83d\ude03!\nmore text.", pieceTable has:

 PieceTable{
 O="Text <e>!<n>more text.",
 A="",
 L=18, pieces ->
 - Piece{type=O, [0, 5], TDec{...}, "Text "}
 - Piece{type=O, [5, 1], TDec{...}, "<e>"}
 - Piece{type=O, [6, 12], TDec{...}, "!<n>more text."},
 OU -> [TU{'Text '}, EU{1F603}, TU{'!<n>more text.'}],
 AU -> []
}

this works: new DecorationModel(0, 19, preset, parPreset)) (note L=19, vs 18 in pieceTable).
And new DecorationModel(0, 18, preset, parPreset)) works but doesn't render the last character (".").

However, with two decorations (with the external lengths):

List.of(new DecorationModel(0, 9, preset, parPreset), new DecorationModel(9, 10, preset, parPreset));

fails:

Caused by: java.lang.StringIndexOutOfBoundsException: begin 9, end 19, length 18
        at java.base/java.lang.String.checkBoundsBeginEnd(String.java:4601)
        at java.base/java.lang.String.substring(String.java:2704)
        at com.gluonhq.richtextarea.model.Piece.getInternalText(Piece.java:79)
        at com.gluonhq.richtextarea.model.PieceCharacterIterator.lambda$reset$3(PieceTable.java:464)
        at com.gluonhq.richtextarea.model.PieceTable.walkPieces(PieceTable.java:394)
        at com.gluonhq.richtextarea.model.PieceCharacterIterator.reset(PieceTable.java:463)
        at com.gluonhq.richtextarea.model.PieceCharacterIterator.<init>(PieceTable.java:452)
        at com.gluonhq.richtextarea.model.PieceTable.<init>(PieceTable.java:95)
        at com.gluonhq.richtextarea.RichTextAreaSkin.setup(RichTextAreaSkin.java:611)
        at com.gluonhq.richtextarea.RichTextAreaSkin.<init>(RichTextAreaSkin.java:554)