Skip to content

#1057 Show full line numbers in long diffs - #1074

Merged
ivanfenenko merged 1 commit into
mainfrom
fix/1057-diff-line-number-gutter
Nov 16, 2026
Merged

ivanfenenko merged 1 commit into
mainfrom
fix/1057-diff-line-number-gutter

Conversation

@ivanfenenko

@ivanfenenko ivanfenenko commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

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

  • Android: UnifiedDiffDocumentTest (one new case for the digit count). The full :app:testDebugUnitTest passed on the commit this was written on.
  • iOS: one new case in ChangesTests, run on a simulator.
  • Checked in the real apps against a v2 harness server with generated files, on an Android emulator and an iOS simulator: a diff with line numbers above 6,000 (Android) and above 1,600 (iOS) shows every number in full.

Evidence

Screenshots for both platforms are in the first comment.

Risks / Follow-ups

  • The digit width is a constant for the 14 pt code font, scaled with the text size setting. Not checked at the largest text size.
  • Not checked: a diff with more than 99,999 lines.

🤖 Generated with Claude Code


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

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]>
@ivanfenenko

Copy link
Copy Markdown
Collaborator Author

Line numbers in a long diff, with this change. Generated files on a v2 harness server.

Android iOS
Android: long diff, four-digit line numbers shown in full iOS: long diff, four-digit line numbers shown in full

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review: 1 finding(s) that 2+ of 3 passes agreed on.

opencode pr-review · passes: muse-spark-1.3-contributor, glm-5.3-flash, deepseek-v4.1-flash · $0.063

) {
// 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))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Merged via the queue into main with commit 829f797 Nov 16, 2026
@ivanfenenko
ivanfenenko deleted the fix/1057-diff-line-number-gutter branch November 16, 2026 09:54
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