Skip to content

refactor(engine): extract TokenBreaking from TextFlowSupport#313

Merged
DemchaAV merged 2 commits into
developfrom
refactor/token-breaking-helper
Jul 6, 2026
Merged

refactor(engine): extract TokenBreaking from TextFlowSupport#313
DemchaAV merged 2 commits into
developfrom
refactor/token-breaking-helper

Conversation

@DemchaAV

@DemchaAV DemchaAV commented Jul 6, 2026

Copy link
Copy Markdown
Owner

Why

TextFlowSupport had grown to ~1.9k LOC, and the token-breaking family —
breakLongToken, softBreakSegments, splitLongToken, fitCharacters — is
pure string logic reachable only through breakLongToken from the three wrap
loops, yet was exercised only end-to-end via the paragraph render tests, never
directly.

What changed

  • Lift the four methods and the SOFT_BREAK_AFTER_CHARS constant verbatim into a
    new package-private TokenBreaking; TextFlowSupport now calls
    TokenBreaking.breakLongToken(...) at its three wrap sites. The methods are
    moved as-is, so behaviour is unchanged and the wrap file drops ~125 LOC.
  • TokenBreakingTest — direct coverage of soft-seam segmentation, greedy
    packing, 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 20
InlineHighlightRenderTest cases stay green unchanged — proof the move is
behaviour-identical — plus 11 new TokenBreakingTest cases.

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.

DemchaAV added 2 commits July 6, 2026 08:39
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.
@DemchaAV DemchaAV merged commit 65d97ad into develop Jul 6, 2026
11 checks passed
@DemchaAV DemchaAV deleted the refactor/token-breaking-helper branch July 6, 2026 08:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant