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.
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 onemaxWidth-sized chunk when a word exceedsmaxWidthand stores the remainder incurrentLine— 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 tolinesas 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.OnCalculateRequiredDimensionsthen reportsmaxWidth = 7, inconsistent with the requested content width, andOnRenderwrites a 7-character string into a 3-column area, overflowing into adjacent UI. The existing testWordWrapSplitsTextAcrossLinesdoesn'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 intomaxWidth-sized chunks and appending each as its own line before continuing to the next word.Acceptance criteria
WrapTexton a word whose length is more than 2xmaxWidthproduces only lines that are each<= maxWidthcharacters long.