fix: fold text that has no spaces instead of cutting it off at the pane - #24
Merged
Conversation
Word wrapping breaks only at spaces and hyphens, so a Japanese sentence, or a long URL, stayed on one line and the pane cut it off. Every place that folds text now hard-wraps what word wrapping could not: source view, line numbers, the search jump's row count, and glamour's output, where a folded paragraph keeps its margin on the rows it continues on. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KUYF9hXeZFML1s8r3i2RVX
The first fix folded a spaceless run only once word wrapping had given up on it, so a Japanese sentence that followed a space was moved to the next row whole, leaving the row before it nearly empty, and a closing mark could start a row. Folding is now done by mado itself: rows break at spaces where one will do, between any two East Asian characters, and inside a word only when the word alone is wider than the row; 。」 and the like stay with the character before them, and 「( with the one after. Glamour renders without word wrap (which also stops it padding rows) and its output is folded the same way. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KUYF9hXeZFML1s8r3i2RVX
…ws, keep styled words whole Checked folding against headings, quotes, nested and ordered lists, inline styling, links, tables, code blocks, emoji, full- and half-width forms, Hangul and Chinese, spaceless URLs and the kinsoku marks. Three things were still cut off or split badly: a tab counted as one column though the terminal draws it to the next multiple of eight; the spaces glamour pads table cells with pushed a row past the pane; and an escape sequence inside a highlighted word was a place to break. Tabs are now expanded before folding, trailing spaces are kept only where they fit, and a sequence inside a word stays in the word. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KUYF9hXeZFML1s8r3i2RVX
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
A Japanese paragraph, or any run of text without spaces such as a long URL, was cut off at the right edge of the pane instead of being folded, and once folded, a run that followed a space was moved to the next row whole, leaving a nearly empty row before it. Word wrapping (reflow/wordwrap, used by glamour and by mado itself) breaks only at spaces and hyphens.
internal/ui/wrap.go: mado folds text itself.wrapTextbreaks a row at a space where one will do, between any two East Asian characters (Japanese has no spaces to offer), and inside a word only when the word alone is wider than the row. Wide characters count as two columns, escape sequences take none and stay whole, and closing marks such as。」stay with the character before them while「(stay with the one after (行頭・行末禁則, minimal).hardWrapLinesfolds glamour's already laid-out output the same way, keeping a paragraph's margin on the rows it continues on; glamour now renders with word wrap off (WithWordWrap(0)), which also stops it padding rows to the width.github.com/mattn/go-runewidth, already in the module graph;reflowis no longer used directly.Test plan
gofmt -l .,go vet ./...,TMPDIR=/tmp go test -race ./...clean。or、; line numbers number a folded line once; the search jump's row matches where the line is rendered;hardWrapLineskeeps every line once and keeps an indent set behind escape sequences; mermaid diagrams still fit at the exact width and fall back one column narrower🤖 Generated with Claude Code
https://claude.ai/code/session_01KUYF9hXeZFML1s8r3i2RVX