Repository navigation
#1057 Show full line numbers in long diffs - #1074
Conversation
The lazy unified diff gives every row one measured height. A line number wider than the 24 dp/pt column then wrapped (Android) or was truncated (iOS) and the shared height cut it: line 7818 showed as "78" on Android, and every number from 100 up showed as "1…" on iOS. The columns now widen by one digit width per digit past two, from the largest line number in the document, and never wrap. Diffs under 100 lines look as before. Co-Authored-By: Claude Opus 5.5 <[email protected]>
| ) { | ||
| // Two digits fit the base width; each further digit widens the column, so a number never wraps | ||
| // into the second line that the one shared row height would clip. | ||
| val gutterWidth = openCodeTextScaled(24.dp + LINE_NUMBER_DIGIT_WIDTH * maxOf(0, gutterDigits - 2)) |
There was a problem hiding this comment.
medium: Gutter width follows the app text-size setting but not the phone font scale, so numbers still clip
gutterWidth is built from dp constants (24.dp plus LINE_NUMBER_DIGIT_WIDTH = 9.dp per extra digit) passed through openCodeTextScaled, which only multiplies LocalOpenCodeTextScale (the app's Appearance multiplier, see AppearanceTextSize.multiplier). The code text itself is 14.sp laid out through Density.fontScale, and inside a text region that is base.fontScale * multiplier (ScaledTextDensity.fontScale). So when the phone's own font-size setting differs from 1.0, the glyphs grow while the added per-digit width stays fixed. Line 9 of the PR comment says each further digit adds one digit width so a number never wraps/clips; that invariant does not hold for the system font scale. The constant should come from the resolved font metrics (e.g. TextMeasurer.measure("0", CodeTextStyle) as OpenCodeCodeFile.kt does) or be scaled with LocalDensity.current.fontScale as well. (The same mismatch already affects the base 24.dp, but the new per-digit term inherits it, so the numbers this PR is meant to protect still clip.)
Failure scenario: Android with Settings > Display > Font size = Largest (fontScale ≈ 1.3), app text size at default. A diff reaching line 7818 (4 digits): a 14 sp monospace digit is ≈ 8.4 dp × 1.3 ≈ 10.9 dp, so "7818" needs ≈ 44 dp, but the gutter is 24 + 9 × (4 − 2) = 42 dp (openCodeTextScaled is a no-op at the default app size). Text has softWrap = false/maxLines = 1, so the trailing digit is clipped and the gutter shows "781" — the same class of regression the PR claims to fix. At the accessibility font size (fontScale 2.0) even a 2-digit number (≈ 33.6 dp) exceeds the unscaled 24 dp base.
Found by 3 of 3 passes.


Summary
#1061 made the unified diff lay its rows out lazily, with one measured height for every row. The line-number columns kept their fixed 24 dp/pt width, so a number that did not fit was wrapped (Android) or truncated (iOS) and then cut by the shared row height: line 7818 showed as "78" on Android, and every number from 100 up showed as "1…" on iOS. This regression is on
main.The columns are now sized from the largest line number in the document: two digits fit the base width, and each further digit adds one digit width. Numbers never wrap. Diffs under 100 lines look exactly as before.
Refs #1057.
Checks
UnifiedDiffDocumentTest(one new case for the digit count). The full:app:testDebugUnitTestpassed on the commit this was written on.ChangesTests, run on a simulator.Evidence
Screenshots for both platforms are in the first comment.
Risks / Follow-ups
🤖 Generated with Claude Code
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.