Skip to content

fix: clamp tab title font size - #94

Open
austinywang wants to merge 1 commit into
mainfrom
fix-tab-title-font-size-clamp
Open

austinywang wants to merge 1 commit into
mainfrom
fix-tab-title-font-size-clamp

Conversation

@austinywang

@austinywang austinywang commented Apr 13, 2026 •

Copy link
Copy Markdown

Summary

  • clamp tab title font size to a minimum readable size for tab items
  • apply the same clamp to drag previews so the dragged label matches the live tab
  • add unit coverage for the clamping helper

Testing

  • Not run locally (per repo policy)

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.

  • Bug Fixes
    • Apply clamped title size in TabItemView and TabDragPreview
    • Base accessory font size on the clamped title size
    • Add unit tests for the clamping helper

Written for commit 5d6b10b. Summary will update on new commits.

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Tab titles now enforce a minimum readable font size, preventing text from becoming too small in tab views.
  • Tests

    • Added test coverage to verify font size clamping behavior.

@coderabbitai

coderabbitai Bot commented Apr 13, 2026 •

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

This pull request introduces font size clamping for tab titles across multiple components. A new static method clampedTitleFontSize enforces a minimum readable size of 8 points, which is then integrated into TabItemView and TabDragPreview to ensure consistent, readable tab title rendering.

Changes

Cohort / File(s) Summary
Font Size Clamping Implementation
Sources/Bonsplit/Internal/Views/TabItemView.swift, Sources/Bonsplit/Internal/Views/TabDragPreview.swift
Added TabItemStyling.clampedTitleFontSize() static method to enforce minimum 8pt font size. Both components now use the clamped value via a computed titleFontSize property instead of raw appearance values.
Unit Test
Tests/BonsplitTests/BonsplitTests.swift
Added test testClampedTitleFontSizeUsesMinimumReadableSize verifying that font sizes below 8pt are clamped to 8pt, while sizes at or above remain unchanged.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Possibly related PRs

Poem

🐰 A hop through typography,
Where readability hops free,
Eight points minimum, we proclaim,
No squinting in the viewing game!
Clamped and clamped with bunny care, 🐇✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: clamp tab title font size' directly and clearly summarizes the main change: implementing font size clamping for tab titles.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-tab-title-font-size-clamp

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@greptile-apps

greptile-apps Bot commented Apr 13, 2026

Copy link
Copy Markdown

Greptile Summary

This PR adds a minimum font size clamp (max(8, size)) for tab title labels in both TabItemView and TabDragPreview, delegating the logic to a new shared helper TabItemStyling.clampedTitleFontSize. The accessoryFontSize computed property is updated to derive from the clamped title size rather than the raw appearance value, and three unit tests cover the boundary conditions.

Confidence Score: 5/5

Safe to merge — change is narrow, well-tested, and introduces no behavioral regressions.

All three call sites are updated consistently, the accessoryFontSize refactor is mathematically equivalent to the prior expression for all input values, and the new helper is covered by unit tests at and around the clamp boundary.

No files require special attention.

Important Files Changed

Filename Overview
Sources/Bonsplit/Internal/Views/TabItemView.swift Adds clampedTitleFontSize static helper to TabItemStyling and a private titleFontSize computed property in TabItemView; updates accessoryFontSize to derive from the clamped value — mathematically equivalent to the old expression.
Sources/Bonsplit/Internal/Views/TabDragPreview.swift Adds titleFontSize computed property that delegates to the new shared helper, keeping the drag preview visually consistent with the live tab.
Tests/BonsplitTests/BonsplitTests.swift Adds testClampedTitleFontSizeUsesMinimumReadableSize covering below-minimum, at-minimum, and above-minimum inputs.

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"]
Loading

Reviews (1): Last reviewed commit: "fix: clamp tab title font size" | Re-trigger Greptile

@coderabbitai coderabbitai 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.

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 (expected 8 if 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 through max().

🤖 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

📥 Commits

Reviewing files that changed from the base of the PR and between 2979ef6 and 5d6b10b.

📒 Files selected for processing (3)
  • Sources/Bonsplit/Internal/Views/TabDragPreview.swift
  • Sources/Bonsplit/Internal/Views/TabItemView.swift
  • Tests/BonsplitTests/BonsplitTests.swift

Comment on lines +23 to +25
static func clampedTitleFontSize(_ size: CGFloat) -> CGFloat {
max(8, size)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 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.

Suggested change
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.

@cubic-dev-ai cubic-dev-ai 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.

No issues found across 3 files

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