Skip to content

Simplify rich-inline: unify stepRichInlineLine/Stats and remove containsCJKText wrapper #136

@shaun0927

Description

@shaun0927

Summary

Two small simplification opportunities in the v0.0.5 code, both pure refactors with no behavior change.

1. stepRichInlineLine and stepRichInlineLineStats share ~180 lines of near-identical logic

rich-inline.ts:211–387 and rich-inline.ts:389–519 implement the same line-stepping loop. The only difference is whether a collectFragment callback fires. Since stepRichInlineLine already accepts an optional collectFragment parameter, the stats variant could be replaced with stepRichInlineLine(flow, maxWidth, cursor, undefined).

Evidence of drift risk: PR #132 had to apply the same overflow guard to both functions in parallel — the exact duplication pattern that makes one-sided patches easy to miss.

I verified the two functions produce identical lineCount and maxLineWidth across multiple item/width combinations (simple text, CJK multi-item, atomic chips with extraWidth, mixed items), so unification would not change behavior.

2. containsCJKText() is a single-call-site passthrough to isCJK()

// analysis.ts:161–163
function containsCJKText(text: string): boolean {
  return isCJK(text)
}

One call site at line 1214. Similar to the isCJK dedup and no-op removal in PR #118.

Motivation

Both align with the repo's holistic-pass simplification principle. Neither changes behavior — the first reduces the surface for future one-sided patches in rich-inline, and the second removes a trivial indirection.

Happy to submit a PR if these look reasonable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions