Skip to content

fix(tui): wrap text at word boundaries instead of mid-character - #96

Merged
bgreenwell merged 1 commit into
develfrom
fix/tui-word-wrap
Jul 15, 2026
Merged

fix(tui): wrap text at word boundaries instead of mid-character#96
bgreenwell merged 1 commit into
develfrom
fix/tui-word-wrap

Conversation

@bgreenwell

Copy link
Copy Markdown
Owner

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_width in src/ansi.rs:438), which already does proper word-boundary wrapping.
  • Adds a word/word_width accumulator 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.
  • Per-grapheme search-highlight Style computation is untouched (still computed per grapheme, including for the word buffer and the space between words), and the function's signature/LayoutCache interaction is unchanged.
  • Adds unit tests covering: word-boundary wrapping, the exact repro from the issue (word-splitting no longer happens and the original text round-trips through wrapping), embedded hard breaks (\n from w:br), and the zero-width edge case.

Closes #83.

Test plan

  • cargo fmt --all -- --check
  • cargo clippy --all-targets -- -D warnings
  • cargo test (91 lib tests + integration tests, all passing, including 4 new tests)

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.
@bgreenwell
bgreenwell merged commit 9128f0f into devel Jul 15, 2026
9 checks passed
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.

TUI text wrapping splits words mid-character (unlike ANSI export)

1 participant