Repository navigation
fix(textarea): keep a last word that exactly fills the line - #1070
Open
abdull-ah-med wants to merge 1 commit into
Open
abdull-ah-med wants to merge 1 commit into
abdull-ah-med wants to merge 1 commit into
Conversation
When the final word of a line made it exactly as wide as the textarea, wrap moved that word to the next row, so a line of spaced words could only hold width-1 characters while a single unbroken word could hold the full width. Keep the word on its row and move only the trailing cursor cell to the next row, matching the unbroken-word case. The word still reflows once it grows past the width. Fixes charmbracelet#333
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.
CONTRIBUTING.md.Fixes #333
What was wrong
With a width-10 textarea, typing
1234567890keeps all ten characters on the first row, but typing1 2 3 4 56(also ten cells) moves56to the next row as soon as the6is typed. So a line of spaced words could only holdwidth-1cells.The cause is the final check in
wrap():>= widthmoved the last word to a new row whenever it made the line exactly full. A single unbroken word that fills the width takes a different path. It stays on its row, and only the trailing cursor cell goes to the next row.What changed
wrap()now keeps a last word that fits exactly on its row and puts only the trailing cursor space on the next row. This matches the unbroken-word case. The word still reflows once it grows past the width (1 2 3 4 567→1 2 3 4/567).Before / after (width 10, no prompt or line numbers)
12345678901234567890/ ``1 2 3 4 561 2 3 4/561 2 3 4 56/ ``1 2 3 4 5671 2 3 4/567How it was tested
TestWrapLastWordFillsWidth(table test ofwrap, including a double-width rune) andTestTypingLastWordFillsWidthDoesNotReflow(typing throughUpdate, then one more character to confirm the reflow). Both fail onmainand pass with this change.LineInfo()row/column for the cursor at the end and at column 9 are now identical for1234567890and1 2 3 4 56.go test ./...,go vet ./...,gofmt -l ., andgolangci-lint runon the changed code all pass.I prepared this change with AI assistance, then reviewed and tested it myself.