Skip to content

fix: keep indentation and spacing when TextElement wraps words - #182

Merged
matt-edmondson merged 2 commits into
mainfrom
fix/150-wordwrap-keeps-whitespace
Sep 30, 2026
Merged

matt-edmondson merged 2 commits into
mainfrom
fix/150-wordwrap-keeps-whitespace

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #150

What changed

TextElement.WrapText split each paragraph with Split(' ', RemoveEmptyEntries) and joined the words with single spaces. Turning on WordWrap therefore collapsed every run of spaces and removed leading indentation, even when the paragraph already fit and nothing had to wrap. Measurement used the same lines, so the measured width shrank as well.

Changes:

Tests

  • WordWrapLeavesALineThatFitsUnchanged: the repro from the issue. " indented two" in a 40-wide element renders unchanged, and the measured width is 17.
  • WordWrapKeepsSpacesExceptAtBreakPoints: " key: aa bb cc" at width 10 wraps to [" key: aa", "bb cc"].

Both tests fail with the fix reverted and pass with it. The full TUI.Test suite passes, 219/219, including the existing wrapping, wide-text and blank-paragraph tests.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Jn27sjy5Z1Sbi1aZaAJDgj


Generated by Claude Code

WrapText split on spaces with RemoveEmptyEntries and rejoined with single
spaces, so turning WordWrap on collapsed runs of spaces and dropped leading
indentation even on lines that already fit. A paragraph that fits now comes
back unchanged, and one that wraps keeps its spaces except at break points.

Fixes #150

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Jn27sjy5Z1Sbi1aZaAJDgj
Brings WrapText back under Sonar's cognitive-complexity limit (S3776).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Jn27sjy5Z1Sbi1aZaAJDgj
@sonarqubecloud

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit 0e82b96 into main Sep 30, 2026
14 checks passed
@matt-edmondson
matt-edmondson deleted the fix/150-wordwrap-keeps-whitespace branch September 30, 2026 04:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enabling WordWrap on TextElement collapses runs of spaces and strips leading indentation, even on lines that already fit

2 participants