Repository navigation
fix: keep selection highlight uniform across colored and uncolored workspaces (#3308) #3310
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| import AppKit | ||
| import SwiftUI | ||
| import XCTest | ||
|
|
||
| #if canImport(cmux_DEV) | ||
|
|
@@ -61,3 +63,132 @@ final class SidebarWidthPolicyTests: XCTestCase { | |
| XCTAssertFalse(range.contains(686.1)) | ||
| } | ||
| } | ||
|
|
||
| final class SidebarWorkspaceSelectionColorTests: XCTestCase { | ||
| func testSelectedColoredWorkspaceUsesStandardSelectionBackgroundInLightAndDark() { | ||
| for colorScheme in [ColorScheme.light, .dark] { | ||
| let coloredSelected = sidebarWorkspaceRowBackgroundStyle( | ||
| activeTabIndicatorStyle: .solidFill, | ||
| isActive: true, | ||
| isMultiSelected: false, | ||
| customColorHex: "#E85D75", | ||
| colorScheme: colorScheme, | ||
| sidebarSelectionColorHex: nil | ||
| ) | ||
| let standardSelected = sidebarWorkspaceRowBackgroundStyle( | ||
| activeTabIndicatorStyle: .solidFill, | ||
| isActive: true, | ||
| isMultiSelected: false, | ||
| customColorHex: nil, | ||
| colorScheme: colorScheme, | ||
| sidebarSelectionColorHex: nil | ||
| ) | ||
|
|
||
| XCTAssertEqual(coloredSelected.opacity, standardSelected.opacity, accuracy: 0.001) | ||
| XCTAssertEqual(coloredSelected.opacity, 1, accuracy: 0.001) | ||
| assertColor(coloredSelected.color, equals: standardSelected.color) | ||
|
|
||
| let unselectedColored = sidebarWorkspaceRowBackgroundStyle( | ||
| activeTabIndicatorStyle: .solidFill, | ||
| isActive: false, | ||
| isMultiSelected: false, | ||
| customColorHex: "#E85D75", | ||
| colorScheme: colorScheme, | ||
| sidebarSelectionColorHex: nil | ||
| ) | ||
| XCTAssertEqual(unselectedColored.opacity, 0.7, accuracy: 0.001) | ||
| XCTAssertFalse( | ||
| colorsAreEqual(coloredSelected.color, unselectedColored.color), | ||
| "Selected row should use the standard selection background, not the workspace tab color" | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| func testSelectedColoredWorkspaceUsesConfiguredSelectionBackground() { | ||
| let selectionHex = "#123456" | ||
| let coloredSelected = sidebarWorkspaceRowBackgroundStyle( | ||
| activeTabIndicatorStyle: .solidFill, | ||
| isActive: true, | ||
| isMultiSelected: false, | ||
| customColorHex: "#E85D75", | ||
| colorScheme: .light, | ||
| sidebarSelectionColorHex: selectionHex | ||
| ) | ||
| let standardSelected = sidebarWorkspaceRowBackgroundStyle( | ||
| activeTabIndicatorStyle: .solidFill, | ||
| isActive: true, | ||
| isMultiSelected: false, | ||
| customColorHex: nil, | ||
| colorScheme: .light, | ||
| sidebarSelectionColorHex: selectionHex | ||
| ) | ||
|
|
||
| XCTAssertEqual(coloredSelected.opacity, 1, accuracy: 0.001) | ||
| assertColor(coloredSelected.color, equals: standardSelected.color) | ||
| assertColor(coloredSelected.color, equals: NSColor(hex: selectionHex)) | ||
| } | ||
|
Comment on lines
+107
to
+129
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| private func assertColor( | ||
| _ actual: NSColor?, | ||
| equals expected: NSColor?, | ||
| file: StaticString = #filePath, | ||
| line: UInt = #line | ||
| ) { | ||
| guard let actual, let expected else { | ||
| XCTAssertNotNil(actual, file: file, line: line) | ||
| XCTAssertNotNil(expected, file: file, line: line) | ||
| return | ||
| } | ||
|
|
||
| XCTAssertTrue( | ||
| colorsAreEqual(actual, expected), | ||
| "Expected \(colorDescription(actual)) to equal \(colorDescription(expected))", | ||
| file: file, | ||
| line: line | ||
| ) | ||
| } | ||
|
|
||
| private func colorsAreEqual(_ lhs: NSColor?, _ rhs: NSColor?) -> Bool { | ||
| guard let lhs, let rhs else { | ||
| return lhs == nil && rhs == nil | ||
| } | ||
| guard let lhsRGB = lhs.usingColorSpace(.sRGB), | ||
| let rhsRGB = rhs.usingColorSpace(.sRGB) else { | ||
| return false | ||
| } | ||
|
|
||
| var lhsRed: CGFloat = 0 | ||
| var lhsGreen: CGFloat = 0 | ||
| var lhsBlue: CGFloat = 0 | ||
| var lhsAlpha: CGFloat = 0 | ||
| var rhsRed: CGFloat = 0 | ||
| var rhsGreen: CGFloat = 0 | ||
| var rhsBlue: CGFloat = 0 | ||
| var rhsAlpha: CGFloat = 0 | ||
| lhsRGB.getRed(&lhsRed, green: &lhsGreen, blue: &lhsBlue, alpha: &lhsAlpha) | ||
| rhsRGB.getRed(&rhsRed, green: &rhsGreen, blue: &rhsBlue, alpha: &rhsAlpha) | ||
|
|
||
| return abs(lhsRed - rhsRed) <= 0.001 && | ||
| abs(lhsGreen - rhsGreen) <= 0.001 && | ||
| abs(lhsBlue - rhsBlue) <= 0.001 && | ||
| abs(lhsAlpha - rhsAlpha) <= 0.001 | ||
| } | ||
|
|
||
| private func colorDescription(_ color: NSColor) -> String { | ||
| guard let rgb = color.usingColorSpace(.sRGB) else { | ||
| return color.description | ||
| } | ||
| var red: CGFloat = 0 | ||
| var green: CGFloat = 0 | ||
| var blue: CGFloat = 0 | ||
| var alpha: CGFloat = 0 | ||
| rgb.getRed(&red, green: &green, blue: &blue, alpha: &alpha) | ||
| return String( | ||
| format: "rgba(%.3f, %.3f, %.3f, %.3f)", | ||
| red, | ||
| green, | ||
| blue, | ||
| alpha | ||
| ) | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SidebarWorkspaceSelectionColorTestsis added toSidebarWidthPolicyTests.swift, a file that tests resize-range arithmetic and clamping logic. The existing parallel coverage lives inWorkspaceUnitTests.swiftalongsideSidebarSelectedWorkspaceColorTests. Moving the new class there (or into a newSidebarSelectionColorTests.swift) would keep test organisation consistent and make it easier to find all selection-colour tests in one place.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!