Repository navigation
fix: keep indentation and spacing when TextElement wraps words - #182
Merged
Merged
Conversation
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
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #150
What changed
TextElement.WrapTextsplit each paragraph withSplit(' ', RemoveEmptyEntries)and joined the words with single spaces. Turning onWordWraptherefore 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:
maxWidthcells is returned unchanged.SplitKeepingSpaceshelper tokenizes the text into alternating runs of spaces and non-spaces. Runs of spaces are kept between words and as first-line indentation. They are dropped only where a line breaks: at the end of a flushed line and at the start of a continuation line.Regextokenizer so the change doesn't add a new analyzer rule.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.Testsuite 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