Add diffHunkHeaders + diffLineNumberStyle for mobile/minimal renderers#10
Conversation
The library renders a side-by-side `old | new` gutter and an `@@ -a,b +c,d @@` separator above every hunk. Both are right for desktop unified-diff review and wrong for narrow viewports — on a phone every context line shows the same number twice (e.g. `19 19`, `20 20`) which reads as noise, and the hunk header eats screen space without adding signal beyond what the surrounding chrome (file name, stats badge) already conveys. This adds two opt-in knobs that leave today's behaviour unchanged: - `DiffConfiguration.LineNumberStyle = .hidden | .single | .dual`, default `.dual`. `.single` shows one column with the new line number for added/context and the old line number for removed — matching how `git diff --color` and most terminal renderers present a compact gutter. - `.diffLineNumberStyle(_:)` view modifier sets it explicitly. The legacy `.diffLineNumbers(_:Bool)` modifier and the legacy `showLineNumbers: Bool` init parameter still work: `true` → `.dual`, `false` → `.hidden`. - `showHunkHeaders: Bool`, default `true`, exposed via `.diffHunkHeaders(_:)`. Mirrors the existing `.diffFileHeaders(_:)` modifier. - New `.mobile` preset bundles `.single` + hidden hunk headers + compact font/spacing for a sensible mobile default. The existing modifiers (`.diffTheme`, `.diffFont`, `.diffLineSpacing`, `.diffWordWrap`) were each manually re-instantiating `DiffConfiguration` with the old field set — that would have silently reset the new fields whenever chained after `.diffLineNumberStyle` / `.diffHunkHeaders`. Switched them to the existing `.with*` builders so every field flows through unchanged. 10 new tests cover field inference (legacy → new), the new modifiers, the `.mobile` preset, and that chaining other modifiers preserves the new fields. 21/21 passing total (was 11). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (7)
📝 WalkthroughWalkthroughThis PR introduces a refined line-number rendering system and hunk header visibility control for diffs. It replaces the boolean ChangesLine number styles and hunk header visibility
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
DiffConfiguration.LineNumberStyle = .hidden | .single | .dual, default.dual(no behaviour change for existing callers)..diffLineNumberStyle(_:)view modifier for the new gutter modes..singleshows one column — new line number on+/context, old line number on-— matching howgit diff --colorand terminal renderers handle narrow space.showHunkHeaders: Bool(defaulttrue) +.diffHunkHeaders(_:)modifier mirroring the existing.diffFileHeaders(_:)toggle..mobilepreset bundles.single+ hidden hunk headers + compact spacing.Why
On a phone, the existing
.dualgutter renders every context line as19 19/20 20/ etc. — visually duplicated, hard to scan at small sizes. The hunk header@@ -17,10 +17,18 @@adds another line of low-signal text. Together they crowd out the actual code change. Pi-remote-control is shipping its first mobile diff review surface; this PR unblocks the right minimal-mobile rendering without forking.Usage
```swift
DiffRenderer(diffText: text)
.diffLineNumberStyle(.single)
.diffHunkHeaders(false)
.diffTheme(.dark)
// or
DiffRenderer(diffText: text)
.diffConfiguration(.mobile)
```
Implementation notes
showLineNumbers: Boolstays as a stored property and stays accepted by the legacy init / modifier. When the legacy flag isfalsewe map to.hidden; whentruewe map to.dual— so any existing call site stays pixel-identical.with*builders forward the new fields. The remaining "old"View.diffXxxmodifiers (.diffTheme,.diffFont,.diffLineSpacing,.diffWordWrap) were manually re-instantiatingDiffConfigurationand would have silently reset the new fields when chained after.diffLineNumberStyle/.diffHunkHeaders. Switched them to the existing.with*builders.Test plan
.mobilepreset).🤖 Generated with Claude Code
Summary by CodeRabbit
Release Notes
New Features
.diffLineNumberStyle(_:)modifier supporting hidden, single, and dual line-number display options..diffHunkHeaders(_:)modifier to toggle hunk-header visibility..mobilepreset configuration with optimized defaults for mobile viewing.Documentation
.diffLineNumbers(_:)as legacy; use.diffLineNumberStyle(_:)instead.