fix(tui): wrap text at word boundaries instead of mid-character - #96
Merged
Conversation
wrap_formatted_runs in src/widgets/document.rs wrapped at the grapheme level with no word-boundary awareness, so a word that didn't fit at the end of a line got split mid-word. Buffers graphemes into a word/word_width accumulator and only flushes it to the current line if it fits, otherwise starts a new line - the same pattern already used by the ANSI export's wrap_formatted_runs_with_width in src/ansi.rs. Search-match highlighting and the LayoutCache interaction are unaffected: styles are still computed per grapheme, and the function's signature and caching contract are unchanged.
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.
Summary
wrap_formatted_runs(src/widgets/document.rs:86) wrapped at the grapheme level with no word-boundary awareness, so a word that didn't fit at the end of a line got split mid-word — inconsistent with the ANSI export path (wrap_formatted_runs_with_widthinsrc/ansi.rs:438), which already does proper word-boundary wrapping.word/word_widthaccumulator to the grapheme loop, buffering graphemes until a space/newline boundary and only flushing to the current line if the word fits — the same pattern the ANSI wrapper already uses.Stylecomputation is untouched (still computed per grapheme, including for the word buffer and the space between words), and the function's signature/LayoutCacheinteraction is unchanged.\nfromw:br), and the zero-width edge case.Closes #83.
Test plan
cargo fmt --all -- --checkcargo clippy --all-targets -- -D warningscargo test(91 lib tests + integration tests, all passing, including 4 new tests)