RichText property ignores the first space after <br/> or \n characters

Reproduction Steps

  • Download this file Reproduction For RichText.rbxl (153.2 KB)

  • Inspect the text of the TextLabel of SurfaceGui, whose parent’s name is PartForReproduction, located in Workspace.PartForReproduction.SurfaceGui

  • Look at the text on the part. Texts do not seem to align correctly comparing the ContextText property and the text on the surface of the part.

Expected Behavior
There ought not to be an indentation at the beginning of each sentence following the characters <br/> and \n.

Actual Behavior
Every time those characters are used, there’s an indent whose size is kept up in accordance with the actual text.

Workaround
Wrapping each <br/> line breaker (not \n anymore due to an exploit patch recently) with the font tag its size option set to 0 resolves the issue temporarily, proposed by @chess123mate in RichText property ignores the first space after <br/> or \n characters - #6 by chess123mate Yet it is irritating to implement it for every character.

Date First Experienced: 19:20:00 (UTC+3) 10-06-2021
Date Last Experienced: 02:18:00 (UTC+3) 08-25-2022

Issue Area: Engine
Issue Type: Display
Impact: Medium
Frequency: Constantly

3 Likes

Thanks for the report! We’ve filed a ticket to our internal database and we’ll follow up when we have an update for you.

2 Likes

Any update? Been dealing with this issue for many months now

(cc @pjhinthehouse, @EmesOfficial, @MaciejCreates, support bug topic)

This issue has been occuring for a very long time now. The following images demonstrate the issue. Beyond the first newline character (\n or <br/>), a space/whitespace appears as the first character for every succeeding line.

3 Likes

Was having this issue for a while, but just discovered a work-around!

label.Text = string.gsub(text, '\n', '<font size="0">\n</font>')

(If you’re using <br/> you should find/replace that instead of the newline character, of course.)

[EDIT: Note that if you have multiple newlines in a row, this will reduce their line height to 0!]

Thanks for finding a workaround. Just to clarify, \n and br/ both point to the same newline character, so they can be used interchangeably.

That’s only the case after you give it to a TextLabel with RichText on; as you prepare the text, keep in mind that Lua(u) treats them differently:

print("\n" == "br/") -- false       (but probably not what you meant)
print("\n" == "<br/>") -- false
print(("A\nB<br/>C"):gsub("\n", "!")) -- A!B<br/>C 1

If your string has both “\n” and “<br/>”, this works:

label.Text = string.gsub(string.gsub(text, "<br/>", "\n"), "\n", '<font size="0">\n</font>')

Only if it hasn’t already been formatted. If your string contains br/ (non formatted), then sure, you can substitute. Otherwise, if your newline characters were already contained in the string, it doesn’t matter whether you use \n or br/

@chess123mate @dukzae


2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.