Skip to content

Use workspace tab color for selected sidebar rows - #2573

Closed
austinywang wants to merge 1 commit into
mainfrom
issue-2565-selected-workspace-tab-color
Closed

austinywang wants to merge 1 commit into
mainfrom
issue-2565-selected-workspace-tab-color

Conversation

@austinywang

@austinywang austinywang commented Apr 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • use a workspace's assigned tab color for the selected sidebar row when available
  • darken overly bright custom colors until the existing white selected-state text stays readable
  • keep the existing sidebar selection color and accent fallback when no workspace-specific color is set

Testing

  • not run locally per repo policy

Closes #2565


Summary by cubic

Use each workspace’s tab color as the selected sidebar row background, with automatic darkening to keep white text readable. Keeps existing selection color and accent fallback when no workspace color is set. Closes #2565.

  • New Features
    • Selected row uses the workspace tab color when available.
    • Automatically darkens bright colors to maintain 4.5:1 contrast with white text.
    • Respects light/dark mode via WorkspaceTabColorSettings.displayNSColor(...).
    • Falls back to sidebarSelectionColorHex, then the app accent color.

Written for commit 9e7d5f3. Summary will update on new commits.

Summary by CodeRabbit

  • Improvements

    • Enhanced sidebar color contrast by automatically adjusting background colors to meet WCAG accessibility standards, improving readability and usability.
  • New Features

    • Added support for custom per-workspace colors and customizable sidebar selection color overrides for personalized interface appearance.

@coderabbitai

coderabbitai Bot commented Apr 4, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 65088ae6-18db-42c9-987c-5157a75de431

📥 Commits

Reviewing files that changed from the base of the PR and between f484673 and 9e7d5f3.

📒 Files selected for processing (1)
  • Sources/ContentView.swift

📝 Walkthrough

Walkthrough

This PR adds color contrast utilities and updates the sidebar selected-workspace background resolution to use per-workspace custom colors with automatic contrast adjustments to ensure WCAG-compliant readability against white text.

Changes

Cohort / File(s) Summary
Color Contrast Utilities
Sources/ContentView.swift
Added WCAG-style relative luminance and contrast ratio calculation functions to support accessibility-compliant color contrast validation.
Sidebar Background Color Resolution
Sources/ContentView.swift
Extended sidebarSelectedWorkspaceBackgroundNSColor function signature to accept optional customHex (per-workspace custom color) and sidebarSelectionColorHex (user override) parameters. Implemented logic to iteratively darken custom colors (up to 12 iterations) until contrast ratio against white meets 4.5:1 threshold. Updated TabItemView.selectionBackgroundColor to pass tab.customColor and stored sidebarSelectionColorHex to the updated function.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Poem

🐰 A fuzzy calculation, contrast so bright,
Custom colors darkened to meet the light,
No more blue hopping when workspaces gleam,
Accessibility thrives in WCAG's dream! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 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 (4 passed)
Check name Status Explanation
Title check ✅ Passed The title directly matches the PR's primary objective: using workspace tab colors for selected sidebar rows.
Description check ✅ Passed The description covers the main objectives, testing approach, and auto-generated summary, though manual testing verification is missing per repo policy.
Linked Issues check ✅ Passed The code changes implement the core requirements from issue #2565: using workspace tab colors in selected sidebar states with automatic contrast adjustment.
Out of Scope Changes check ✅ Passed All changes are focused on implementing workspace tab color functionality for selected sidebar rows, directly addressing issue #2565 requirements.

✏️ 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 issue-2565-selected-workspace-tab-color

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 4, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR colours the active sidebar row with the workspace's assigned tab colour (instead of always using the accent or custom sidebar selection colour), applying an iterative WCAG-AA darkening loop so white text stays readable. The sidebarSelectedWorkspaceBackgroundNSColor function is extended with two defaulted parameters (customHex, sidebarSelectionColorHex) preserving all existing call-site behaviour, and the colour-dot/swatch paths already in TabItemView ensure tab.customColor changes propagate through the existing observation publishers.

Confidence Score: 5/5

Safe to merge; the only finding is a P2 precision nit on a WCAG linearization constant with no practical impact.

All three branches (workspace custom colour → contrast-adjusted, user sidebar colour → unchanged, accent fallback → unchanged) are correct. The Equatable/observation wiring is preserved. Only one P2 style suggestion (WCAG threshold 0.03928 → 0.04045) remains.

No files require special attention.

Important Files Changed

Filename Overview
Sources/ContentView.swift Adds workspace-specific tab color as the sidebar selection background, with a WCAG-based iterative darkening pass to ensure 4.5:1 contrast against white text; extends sidebarSelectedWorkspaceBackgroundNSColor with two defaulted parameters for backward compatibility.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[selectionBackgroundColor] --> B{tab.customColor set?}
    B -- yes --> C[sidebarSelectedWorkspaceCustomBackgroundNSColor]
    C --> D[WorkspaceTabColorSettings.displayNSColor]
    D -- nil --> E{sidebarSelectionColorHex set?}
    D -- color --> F[sidebarSelectedWorkspaceReadableBackgroundNSColor]
    F --> G{contrast ratio with white >= 4.5?}
    G -- yes --> H[return adjusted color]
    G -- no, iter < 12 --> I[blend 12% black]
    I --> G
    B -- no --> E
    E -- yes --> J[NSColor hex parse → return]
    E -- no --> K[cmuxAccentNSColor fallback]
Loading

Reviews (1): Last reviewed commit: "Use workspace tab color for selected sid..." | Re-trigger Greptile

Comment thread Sources/ContentView.swift
Comment on lines +90 to +96
return pow((component + 0.055) / 1.055, 2.4)
}

let linearRed = linearized(red)
let linearGreen = linearized(green)
let linearBlue = linearized(blue)
return (0.2126 * linearRed) + (0.7152 * linearGreen) + (0.0722 * linearBlue)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 WCAG linearization threshold is off by a rounding

The threshold 0.03928 comes from the original WCAG 2.0 draft. WCAG 2.1 corrected it to 0.04045. The difference is negligible in practice (only colours very close to R/G/B ≈ 10 are affected), but using the updated value keeps the implementation consistent with the current spec.

Suggested change
return pow((component + 0.055) / 1.055, 2.4)
}
let linearRed = linearized(red)
let linearGreen = linearized(green)
let linearBlue = linearized(blue)
return (0.2126 * linearRed) + (0.7152 * linearGreen) + (0.0722 * linearBlue)
func linearized(_ component: CGFloat) -> CGFloat {
if component <= 0.04045 {
return component / 12.92
}
return pow((component + 0.055) / 1.055, 2.4)
}

@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 1 file

@austinywang austinywang closed this Apr 4, 2026

This branch was successfully deployed

1 active deployment
Preview — 9e7d5f37 Deployed Apr 3, 2026 by vercel[bot]
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.

Selected workspace background should use assigned tab color

1 participant