Skip to content

TextElement.WrapText doesn't fully break words longer than 2x the wrap width, overflowing the render area #114

Description

@matt-edmondson

What's wrong

TextElement.WrapText (TUI.Core/Elements/Primitives/TextElement.cs:161-202), in its "word longer than max width" branch (lines 187-192), slices off exactly one maxWidth-sized chunk when a word exceeds maxWidth and stores the remainder in currentLine — but that remainder is never re-sliced. It's only re-examined against the next word, and if it still doesn't fit, it's appended to lines as a single oversized line.

Failure scenario

WrapText("abcdefghij", 3) (a single 10-character word, width 3) returns ["abc", "defghij"] — the second line is 7 characters in a supposedly 3-character-wide box. OnCalculateRequiredDimensions then reports maxWidth = 7, inconsistent with the requested content width, and OnRender writes a 7-character string into a 3-column area, overflowing into adjacent UI. The existing test WordWrapSplitsTextAcrossLines doesn't catch this because it only uses words shorter than 2x the width.

Suggested fix

Loop while the leftover fragment is still longer than maxWidth, slicing it into maxWidth-sized chunks and appending each as its own line before continuing to the next word.

Acceptance criteria

WrapText on a word whose length is more than 2x maxWidth produces only lines that are each <= maxWidth characters long.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions