Repository navigation
Fix #60: wrap long URLs, paths and identifiers - #113
Merged
Merged
Conversation
A long URL or identifier had no break opportunity, so it ran past the right margin, and in a table it overlapped the next column. - breakable inserts zero-width spaces, which canvas treats as invisible optional breaks (working since the fork fix, tdewolff/canvas#397): after / ? & # (not inside ://), at camelCase boundaries, and every 20 characters of an unbroken run. In table cells, whose widths are only known at layout, every token of 12+ (code, links) or 24+ (prose) characters gets them, and cellWidths treats them as word boundaries so columns can shrink. Elsewhere only a token wider than 70% of the measure does. Break points cost Knuth-Plass work on every layout pass, and adding them to every moderately long URL nearly doubled render time; with the gate, the 2000-paragraph benchmark is back to baseline (1.8-2.0s against 1.7-1.9s on main). - Paragraph and table-row splits used to rebuild text from the laid-out spans and add a space at every line end, which would put a stray space into a URL at a zero-width-space break. lineCuts now aligns the lines with the original runs, and splitAt cuts the runs there, keeping faces, links, zero-width spaces and soft hyphens; a soft hyphen that ends the head becomes a visible '-'. joinLines remains only as a fallback. Tests: TestBreakable (the rules, visible text unchanged, the short-token threshold), TestLongTokensStayInMeasure (no overflow in a paragraph or in a three-column table) and TestSplitPreservesText (the original is exactly head + separator + tail at every possible split). Removing the break points fails the overflow test 4 times, and forcing the old rebuild path fails the split test.
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.
Fixes #60. It needed the canvas fix from #112 (tdewolff/canvas#397), now in place.
Break points:
breakableinserts U+200B, which canvas treats as an invisible optional break:/ ? & #, but not inside://Where they go
cellWidthstreats U+200B as a word boundary, so columns can shrink instead of overlapping.main).Exact splits: splitting a paragraph or table row used to rebuild text from the laid-out spans and add
" "at each line end, which would put a stray space into a URL at a U+200B break. Now:lineCutsaligns the laid-out lines with the original runs, skipping unused U+200B and U+00AD inside a line and matching a line-end-to its soft hyphen.splitAtcuts the original runs there, so faces, links, U+200B and U+00AD are kept exactly. A soft hyphen ending the head becomes a visible-.joinLinesremains as a fallback, used when the lines can't be aligned.Extracted text has no stray spaces at break points.
Tests
TestBreakable: the insertion rules, visible text unchanged, the short-token threshold.TestLongTokensStayInMeasure: noOverflowsXin a paragraph with a long URL and identifier, or in any cell of a three-column table of long paths and URLs.TestSplitPreservesText: at every possible split, the original equals head + separator + tail.Removing the break points fails the overflow test 4 times; forcing the old rebuild path fails the split test. The existing paragraph, footnote and table-split tests pass on the new path. I also checked the render visually: the URL and identifier wrap in the paragraph, and the three columns share the width.