refactor(engine): extract TokenBreaking from TextFlowSupport#313
Merged
Conversation
The token-breaking family — breakLongToken, softBreakSegments, splitLongToken and fitCharacters — was pure string logic reachable only through breakLongToken from the three wrap loops, yet covered only end-to-end via the paragraph render tests. Move it verbatim into a package-private TokenBreaking; TextFlowSupport now calls TokenBreaking.breakLongToken(...) at its three wrap sites. Behaviour is unchanged (methods lifted as-is) and the wrap file drops ~125 lines. Add TokenBreakingTest: direct coverage of seam segmentation, greedy packing, the char-level fallback and the min-one-char guarantee, driven by a deterministic fixed-width measurement double so the assertions do not depend on font metrics.
Guard softBreakSegments against null/empty (splitLongToken already did, and both are now package-visible directly-callable entry points), add the @author tag to match the sibling layout helpers, and cover the null/empty and fits-whole edges directly in TokenBreakingTest.
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.
Why
TextFlowSupporthad grown to ~1.9k LOC, and the token-breaking family —breakLongToken,softBreakSegments,splitLongToken,fitCharacters— ispure string logic reachable only through
breakLongTokenfrom the three wraploops, yet was exercised only end-to-end via the paragraph render tests, never
directly.
What changed
SOFT_BREAK_AFTER_CHARSconstant verbatim into anew package-private
TokenBreaking;TextFlowSupportnow callsTokenBreaking.breakLongToken(...)at its three wrap sites. The methods aremoved as-is, so behaviour is unchanged and the wrap file drops ~125 LOC.
TokenBreakingTest— direct coverage of soft-seam segmentation, greedypacking, the character-level fallback and the min-one-char guarantee, driven by
a deterministic fixed-width measurement double so the assertions do not depend
on real font metrics.
Verification
./mvnw -B -ntp verify -pl .→ BUILD SUCCESS, 1632 tests. The 20InlineHighlightRenderTestcases stay green unchanged — proof the move isbehaviour-identical — plus 11 new
TokenBreakingTestcases.Lane: shared-engine — pure internal refactor, no public API or behaviour
change (package-private helper).
Follows #307 (merged): a straight extraction of the token-breaking logic that PR
introduced, with no behaviour change.