Repository navigation
fix: don't start a wrapped row with the space between words - #42
Merged
Merged
Conversation
With Word and WordOrGlyph wrapping, whitespace that did not fit at the end of a row started the next one, so that row began with a space, or held only spaces. This happened after a word that filled a row, after a word longer than the row, and after the last piece of a word split by glyph. Now whitespace that would start a wrapped row hangs at the end of the previous row instead, when that row holds a word. Rows of leading indentation wrap as before. A hanging space can sit past the right edge, so in every wrap mode a cursor past the edge of a wrapped row is now drawn on the last column. This also keeps the cursor visible at the end of a row that fills the whole width, and on the part of a long word that Word wrapping leaves past the edge, where it was not drawn before.
Merged
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.
Hi! I use ratatui-textarea with word wrapping in a notes editor and noticed that wrapped rows sometimes start with a space. When the space after a word doesn't fit at the end of a row, it moves to the start of the next one, so that row looks indented by one cell, or holds only the space. Now that space stays at the end of the row it follows.
Supersedes #41, which moved the last word down instead and left some of these cases open.
More from the agent:
cargo run --example wrapin an 80-column terminal, which starts with empty textareas, and typeword word word word word word word abc next. In the "Word Wrap" box,abcends exactly at the right edge, so the second row should benext. Onmainit isnext.ratatui0.30.1 (ratatui-core0.1.1) as locked here, default features (crossterm).wrap_word_chunkscloses a row when a chunk doesn't fit, and the next row starts with that chunk. When the chunk is whitespace, the row starts with it. The same happens after a word longer than the row (Word) and after the last piece of a word split by glyph (WordOrGlyph), which is theomegarow recorded inword_and_word_or_glyph_differ_for_long_words.wrap_word_chunks, the first whitespace char that would start a wrapped row is added to the end of the previous row instead, when that row doesn't already end with whitespace. Any further whitespace starts the next row, as onmain, so spaces typed before a wrapped word still push it once the row above is full. Rows of leading indentation, such as one tab per row, wrap as before.line_spans_segmentdraws a cursor past the edge of a wrapped row on the last char that fits (drawn_cursor_offset, which reuseschar_offset_for_screen_col).screen_map_load's wrap width calculation moved unchanged intowrap_widthso both can use it. This applies to every wrap mode,Glyphincluded, so it also shows the cursor in two places wheremaindoesn't draw it: at the end of a row that fills the whole width (helloat width 5), and on the part of a long word thatWordleaves past the edge (helloworldat width 4).word_and_word_or_glyph_differ_for_long_wordsnow expectsomegawithout the leading space. Two unit tests insrc/wrap.rscheck that leading indentation wraps as onmainand that spaces after the first one start the next row, and one test intests/textarea.rschecks that the cursor on a hanging space is drawn on the last column. All but the indentation test fail onmainand pass here. On Linux, the commands inCONTRIBUTING.mdpass, and so do thelintjob inci.ymland theunit-testcommands, run withcargo testinstead ofcargo llvm-cov. I didn't run macOS, Windows or the nightlycargo-docjob."helloe\u{301}\t"at width 7 withWordand the cursor at the end. Onmainthat tab starts the next row and the cursor is drawn there. Skipping zero-width chars would need a new helper next tochar_offset_for_screen_col; I left it out to keep the change small.screen_cursor()still returns the cursor's own column, which can be past the right edge (column 7 at width 7), while the cursor is drawn on the last column.WordOrGlyph, the last piece of a split word still ends its row, as onmain:iousandomegatake two rows althoughious omegafits in 10 columns. (WIP) fix: keep the space between words off the start of a wrapped row #41 joined them; I left that out to keep this change to the space.