Skip to content
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

Update xcode color mapping #4

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions Sources/ThemePark/XcodeTheme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public struct XcodeTheme: Codable, Hashable, Sendable {
public let selection: String
public let markupTextNormalColor: String
public let markupTextNormalFont: String
public let insertionPoint: String
public let insertionPoint: String?
public let invisibles: String
public let syntaxColors: [String: String]
public let syntaxFonts: [String: String]
Expand Down Expand Up @@ -159,10 +159,14 @@ extension XcodeTheme: Styling {

return Style(color: color, font: font)
case .editor(.cursor):
let color = PlatformColor(componentsString: insertionPoint) ?? fallbackForegroundColor
let font = PlatformFont(componentsString: insertionPoint) ?? fallbackFont

return Style(color: color, font: font)
if let insertionPoint {
let color = PlatformColor(componentsString: insertionPoint) ?? fallbackForegroundColor
let font = PlatformFont(componentsString: insertionPoint) ?? fallbackFont

return Style(color: color, font: font)
} else {
return Style(color: fallbackForegroundColor, font: fallbackFont)
}
case .editor(.accessoryForeground):
return syntaxStyle(for: "xcode.syntax.plain")
case .editor(.accessoryBackground):
Expand All @@ -175,20 +179,24 @@ extension XcodeTheme: Styling {
return syntaxStyle(for: "xcode.syntax.url")
case .syntax(.literal(.string(_))):
return syntaxStyle(for: "xcode.syntax.string")
case .syntax(.literal(.number(_))):
return syntaxStyle(for: "xcode.syntax.number")
case .syntax(.keyword(_)):
return syntaxStyle(for: "xcode.syntax.keyword")
case .syntax(.text(_)), .gutter(.label):
return syntaxStyle(for: "xcode.syntax.plain")
case .syntax(.identifier(.property)):
return syntaxStyle(for: "xcode.syntax.identifier.variable")
case .syntax(.identifier(.variable)):
return syntaxStyle(for: "xcode.syntax.identifier.variable")
case .syntax(.literal(.number(_))):
return syntaxStyle(for: "xcode.syntax.number")
case .syntax(.identifier(.type)):
return syntaxStyle(for: "xcode.syntax.identifier.type")
case .syntax(.definition(.method)), .syntax(.definition(.function)), .syntax(.definition(.constructor)), .syntax(.definition(.property)):
case .syntax(.definition(.method)), .syntax(.definition(.function)):
return syntaxStyle(for: "xcode.syntax.identifier.function")
case .syntax(.definition(.constructor)), .syntax(.definition(.property)):
return syntaxStyle(for: "xcode.syntax.declaration.other")
case .syntax(.definition(.macro)):
return syntaxStyle(for: "xcode.syntax.identifier..macro")
return syntaxStyle(for: "xcode.syntax.identifier.macro")
case .syntax(.invisible):
let color = PlatformColor(componentsString: invisibles) ?? fallbackForegroundColor
let font = PlatformFont(componentsString: invisibles) ?? fallbackFont
Expand Down
4 changes: 2 additions & 2 deletions Tests/ThemeParkTests/XcodeThemeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ final class XcodeThemeTests: XCTestCase {

// color equality here is actually quite tricky
XCTAssertEqual(
theme.style(for: .editor(.background)),
Style(color: PlatformColor(hex: "#ffffff")!)
theme.style(for: .editor(.background)).color.toHex(),
Style(color: PlatformColor(hex: "#ffffff")!).color.toHex()
)
XCTAssertEqual(
theme.style(for: .syntax(.text(nil))).color.toHex(),
Expand Down
Loading