rexrainbow / phaser3-rex-notes

Notes of phaser3 engine
MIT License
1.18k stars 259 forks source link

Typewriting feature of textbox changes order of text bbcode tags #444

Open dtturcotte opened 3 weeks ago

dtturcotte commented 3 weeks ago

I am using bbcode text in the textbox. I noticed an issue with my text formatting, and when I looked into the text after the textbox completed typewriting, it had changed the order of bbcode tags:

"[area=Quiero]Quiero[/area] [shadow][area=un]un[/area] [area=plátano]plátano[/area][/shadow] [area=y]y[/area] [shadow][area=dos]dos[/area] [area=manzanas]manzanas[/area][/shadow].";

After typewriting:

"[area=Quiero]Quiero[/area] [shadow][area=un]un[/area] [area=plátano]plátano[/shadow][/area] [area=y]y[/area] [shadow][area=dos]dos[/area] [area=manzanas]manzanas [/shadow] [/area]".

Codepen

rexrainbow commented 3 weeks ago

You can ignore this reorder behavior, since the displaying result is correct.

dtturcotte commented 3 weeks ago

The issue is I use regex to make text manipulations based on expected order of the bbcode, e.g., splicing in new bbcode formats such as [u] [/u] for certain words. I don't believe that the typewriting functionality should provide unexpected artifacts like this, in my opinion.

I'm handling now by saving the input text prior to the start of the typewriter, then re-setting it to that saved text after typewriting is complete.

rexrainbow commented 2 weeks ago

After setting text, the content will be parsed to text segment object and its style state. Typing action gets some of text segments and rebuild these text segment objects to BBCode text string. The original order of open/close tags will be discard after parsing BBCode text string, for example [b][/b]AAA -> AAA , text segment AAA does not have b style in the end.

After some investigating, it needs store extra information to implement feature that rebuild BBCode text string with original order of tags. Therefore I won't add it currently.

Lucky you found a workaround solution.