zircon icon indicating copy to clipboard operation
zircon copied to clipboard

ParagraphBuilder truncates all text after the first newline

Open nanodeath opened this issue 4 years ago • 1 comments

Describe the bug When adding a paragraph using TextBoxBuilder.addParagraph, it uses a ParagraphBuilder internally. That ParagraphBuilder discards everything after the first newline, which is surprising behavior.

To Reproduce

Code something like this:

Components.textBox(20)
    .addParagraph("foo\nbar")
    .build()

Expected behavior

This is actually an interesting question. I think my preference is that single newlines be replaced with whitespace, and multiple consecutive newlines be replaced with n-1 newlines.

For instance, if I say

.addParagraph("""
    okay this is a really long paragraph where
    I need multiple lines and stuff just to capture
    the spectacle the player sees
    """.trimIndent()

I don't necessarily want my in-editor linebreaks to be reflected exactly in game; just wordwrap it into whatever container it's in.

But if I say

.addParagraph("""
    In the beginning, life was good.

    But at some point, it stopped being good.
""".trimIndent())

I wouldn't expect this to be collapsed into a single sentence. Really I should use multiple addParagraph calls, but maybe it's being loaded from an external translations file or something. I'd be fine with In the beginning, life was good.\nBut at some point, it stopped being good.. If I really want to preserve the linebreak in the source code, I can add another newline.

I'm open to other opinions here, this seems admittedly subjective.

Screenshots

image

Additional context String.withNewLinesStripped is at the heart of this. It doesn't actually strip newlines; it deletes everything after the first newline.

nanodeath avatar Mar 12 '21 03:03 nanodeath

I'm also inclined to pick this one up once we decide what the desired behavior is.

nanodeath avatar Mar 12 '21 03:03 nanodeath