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

#470 Change default find highlight color #481

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
20 changes: 16 additions & 4 deletions Sources/XiEditor/Theme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,24 @@ struct Theme {
let shadow: NSColor?
}

extension Theme {
static var defaultFindHighlightColor: NSColor {
if #available(OSX 10.13, *) {
return NSColor.findHighlightColor
}
else {
return NSColor(calibratedRed: 1.0, green: 1.0, blue: 0.0, alpha: 1.0)
}
}
}

extension Theme {
static func defaultTheme() -> Theme {
return Theme(foreground: .black,
background: .white,
caret: .black,
lineHighlight: nil,
findHighlights: [NSColor(deviceWhite: 0.8, alpha: 0.4)],
findHighlights: [Theme.defaultFindHighlightColor],
findHighlightForeground: nil,
gutter: NSColor(deviceWhite: 0.9, alpha: 1.0),
gutterForeground: NSColor(deviceWhite: 0.5, alpha: 1.0),
Expand All @@ -82,7 +93,8 @@ extension Theme {
let caret = NSColor(jsonRgbaColor: json["caret"] as? [String: Any] ?? [:])
let line_highlight = NSColor(jsonRgbaColor: json["line_highlight"] as? [String: Any] ?? [:])

let find_highlight: NSColor? = NSColor(jsonRgbaColor: json["find_highlight"] as? [String: Any] ?? [:])
// Use default find highlight color instead of theme's find_highlight value
let find_highlight: NSColor? = Theme.defaultFindHighlightColor
Copy link
Member

Choose a reason for hiding this comment

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

I think if the theme specifies a color for find highlights, then it's ok to use that color instead of forcing the default yellow.

Copy link
Author

@mohanio mohanio Oct 21, 2019

Choose a reason for hiding this comment

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

Sure, I'm also bit not clear on expected behavior. I will wait for @cmyr's clarification #470 (comment)

let find_highlight_foreground = NSColor(jsonRgbaColor: json["find_highlight_foreground"] as? [String: Any] ?? [:])
let gutter = NSColor(jsonRgbaColor: json["gutter"] as? [String: Any] ?? [:])
let gutter_foreground = NSColor(jsonRgbaColor: json["gutter_foreground"] as? [String: Any] ?? [:])
Expand All @@ -100,7 +112,7 @@ extension Theme {
background: background ?? defaults.background,
caret: caret ?? defaults.caret,
lineHighlight: line_highlight ?? defaults.lineHighlight,
findHighlights: Theme.generateHighlightColors(findHighlight: find_highlight ?? defaults.findHighlights?.first!),
findHighlights: Theme.generateHighlightColors(findHighlight: find_highlight),
findHighlightForeground: find_highlight_foreground ?? defaults.findHighlightForeground,
gutter: gutter ?? (background ?? defaults.gutter),
gutterForeground: gutter_foreground ?? defaults.gutterForeground,
Expand All @@ -123,7 +135,7 @@ extension Theme {
// Leave room for default highlight and selection colors
let customHighlights = Style.N_RESERVED_STYLES - 2
return [defaultHighlight] + (0..<customHighlights).map({
return NSColor(hue: CGFloat((1.0 / Double(customHighlights)) * Double($0)), saturation: 1, brightness: brightness, alpha: alpha)
return NSColor(hue: CGFloat((1.0 / Double(customHighlights)) * Double($0)) + hue, saturation: 1, brightness: brightness, alpha: alpha)
})
})
}
Expand Down