Repository navigation
fix: clamp tab title font size - #94
austinywang wants to merge 1 commit into
Conversation
📝 WalkthroughWalkthroughThis pull request introduces font size clamping for tab titles across multiple components. A new static method Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~5 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 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 |
Greptile SummaryThis PR adds a minimum font size clamp ( Confidence Score: 5/5Safe to merge — change is narrow, well-tested, and introduces no behavioral regressions. All three call sites are updated consistently, the No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["appearance.tabTitleFontSize (CGFloat)"] --> B["TabItemStyling.clampedTitleFontSize(size)"]
B --> C{"size < 8?"}
C -- "yes" --> D["return 8"]
C -- "no" --> E["return size"]
D & E --> F["titleFontSize"]
F --> G["Text(tab.title).font(.system(size: titleFontSize))"]
F --> H["accessoryFontSize = max(8, titleFontSize - 2)"]
F -.-> I["TabDragPreview.titleFontSize (same helper)"]
I --> J["Drag preview Text label"]
Reviews (1): Last reviewed commit: "fix: clamp tab title font size" | Re-trigger Greptile |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
Tests/BonsplitTests/BonsplitTests.swift (1)
570-574: Extend clamp tests with a non-finite input case.Good finite coverage. Add an assertion for
.infinity(expected8if helper is hardened) so this edge case stays protected.Proposed test addition
func testClampedTitleFontSizeUsesMinimumReadableSize() { XCTAssertEqual(TabItemStyling.clampedTitleFontSize(3), 8) XCTAssertEqual(TabItemStyling.clampedTitleFontSize(8), 8) XCTAssertEqual(TabItemStyling.clampedTitleFontSize(13), 13) + XCTAssertEqual(TabItemStyling.clampedTitleFontSize(.infinity), 8) }Based on learnings: In Swift, non-finite floating-point values (e.g.,
+infinity) can still pass throughmax().🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@Tests/BonsplitTests/BonsplitTests.swift` around lines 570 - 574, Add a test asserting that TabItemStyling.clampedTitleFontSize(.infinity) returns 8 to cover non-finite inputs; update the test method testClampedTitleFontSizeUsesMinimumReadableSize to include XCTAssertEqual(TabItemStyling.clampedTitleFontSize(.infinity), 8) so the helper is hardened against +infinity passing through max()/min() logic.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@Sources/Bonsplit/Internal/Views/TabItemView.swift`:
- Around line 23-25: clampedTitleFontSize currently returns max(8, size) which
allows +infinity through; update clampedTitleFontSize(_ size: CGFloat) to first
guard size.isFinite and return a safe fallback (e.g., 8) if not finite,
otherwise return max(8, size); reference clampedTitleFontSize and the sources
that call .font(.system(size:)) so the non-finite value cannot propagate from
BonsplitConfiguration.Appearance.tabTitleFontSize.
---
Nitpick comments:
In `@Tests/BonsplitTests/BonsplitTests.swift`:
- Around line 570-574: Add a test asserting that
TabItemStyling.clampedTitleFontSize(.infinity) returns 8 to cover non-finite
inputs; update the test method testClampedTitleFontSizeUsesMinimumReadableSize
to include XCTAssertEqual(TabItemStyling.clampedTitleFontSize(.infinity), 8) so
the helper is hardened against +infinity passing through max()/min() logic.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 72cd9d69-5435-4376-896b-986537f1c569
📒 Files selected for processing (3)
Sources/Bonsplit/Internal/Views/TabDragPreview.swiftSources/Bonsplit/Internal/Views/TabItemView.swiftTests/BonsplitTests/BonsplitTests.swift
| static func clampedTitleFontSize(_ size: CGFloat) -> CGFloat { | ||
| max(8, size) | ||
| } |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Verify where `tabTitleFontSize` is defined/used and whether finite checks already exist.
rg -n -C3 --type=swift '\btabTitleFontSize\b'
rg -n -C3 --type=swift '\bisFinite\b'Repository: manaflow-ai/bonsplit
Length of output: 4366
🏁 Script executed:
# Inspect the actual implementation at lines 23-25 and surrounding context
cat -n Sources/Bonsplit/Internal/Views/TabItemView.swift | sed -n '20,30p'Repository: manaflow-ai/bonsplit
Length of output: 413
🏁 Script executed:
# Check font construction at line 126
cat -n Sources/Bonsplit/Internal/Views/TabItemView.swift | sed -n '120,135p'Repository: manaflow-ai/bonsplit
Length of output: 802
🏁 Script executed:
# Check TabDragPreview.swift around line 21
cat -n Sources/Bonsplit/Internal/Views/TabDragPreview.swift | sed -n '1,30p'Repository: manaflow-ai/bonsplit
Length of output: 1403
🏁 Script executed:
# Check if tabTitleFontSize has any validation/constraints in BonsplitConfiguration
cat -n Sources/Bonsplit/Public/BonsplitConfiguration.swift | sed -n '150,250p'Repository: manaflow-ai/bonsplit
Length of output: 4053
Add a finite guard in clampedTitleFontSize to prevent non-finite font sizes.
The function max(8, size) at line 24 allows +infinity to pass through to .font(.system(size:)) at lines 126 and TabDragPreview.swift:21. Since BonsplitConfiguration.Appearance.tabTitleFontSize has no validation, a user could pass .infinity to the configuration. Add a finite check:
Proposed fix
static func clampedTitleFontSize(_ size: CGFloat) -> CGFloat {
- max(8, size)
+ guard size.isFinite else { return 8 }
+ return max(8, size)
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| static func clampedTitleFontSize(_ size: CGFloat) -> CGFloat { | |
| max(8, size) | |
| } | |
| static func clampedTitleFontSize(_ size: CGFloat) -> CGFloat { | |
| guard size.isFinite else { return 8 } | |
| return max(8, size) | |
| } |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@Sources/Bonsplit/Internal/Views/TabItemView.swift` around lines 23 - 25,
clampedTitleFontSize currently returns max(8, size) which allows +infinity
through; update clampedTitleFontSize(_ size: CGFloat) to first guard
size.isFinite and return a safe fallback (e.g., 8) if not finite, otherwise
return max(8, size); reference clampedTitleFontSize and the sources that call
.font(.system(size:)) so the non-finite value cannot propagate from
BonsplitConfiguration.Appearance.tabTitleFontSize.
Summary
Testing
Summary by cubic
Clamp tab title font size to a minimum of 8pt so small labels stay readable and match drag previews. Accessory text now scales from the clamped title size.
Written for commit 5d6b10b. Summary will update on new commits.
Summary by CodeRabbit
Release Notes
Bug Fixes
Tests