Skip to content

Commit df6d765

Browse files
author
Mohanasundaram
committed
Change default find highlight color
Issue: #470 Find highlight color defaults to red color instead it should use system's default find highlight color(NSColor.findHighlightColor) Fix: * Theme has new static variable representing default find highlight color * Other find highlight colors are generated from the hue of default find highlight color * Find highlight color specified by xi-editor on theme_changed event is ignored
1 parent c9c27ea commit df6d765

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

Sources/XiEditor/Theme.swift

+16-4
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,24 @@ struct Theme {
5757
let shadow: NSColor?
5858
}
5959

60+
extension Theme {
61+
static var defaultFindHighlightColor: NSColor {
62+
if #available(OSX 10.13, *) {
63+
return NSColor.findHighlightColor
64+
}
65+
else {
66+
return NSColor(calibratedRed: 1.0, green: 1.0, blue: 0.0, alpha: 1.0)
67+
}
68+
}
69+
}
70+
6071
extension Theme {
6172
static func defaultTheme() -> Theme {
6273
return Theme(foreground: .black,
6374
background: .white,
6475
caret: .black,
6576
lineHighlight: nil,
66-
findHighlights: [NSColor(deviceWhite: 0.8, alpha: 0.4)],
77+
findHighlights: [Theme.defaultFindHighlightColor],
6778
findHighlightForeground: nil,
6879
gutter: NSColor(deviceWhite: 0.9, alpha: 1.0),
6980
gutterForeground: NSColor(deviceWhite: 0.5, alpha: 1.0),
@@ -82,7 +93,8 @@ extension Theme {
8293
let caret = NSColor(jsonRgbaColor: json["caret"] as? [String: Any] ?? [:])
8394
let line_highlight = NSColor(jsonRgbaColor: json["line_highlight"] as? [String: Any] ?? [:])
8495

85-
let find_highlight: NSColor? = NSColor(jsonRgbaColor: json["find_highlight"] as? [String: Any] ?? [:])
96+
// Use default find highlight color instead of theme's find_highlight value
97+
let find_highlight: NSColor? = Theme.defaultFindHighlightColor
8698
let find_highlight_foreground = NSColor(jsonRgbaColor: json["find_highlight_foreground"] as? [String: Any] ?? [:])
8799
let gutter = NSColor(jsonRgbaColor: json["gutter"] as? [String: Any] ?? [:])
88100
let gutter_foreground = NSColor(jsonRgbaColor: json["gutter_foreground"] as? [String: Any] ?? [:])
@@ -100,7 +112,7 @@ extension Theme {
100112
background: background ?? defaults.background,
101113
caret: caret ?? defaults.caret,
102114
lineHighlight: line_highlight ?? defaults.lineHighlight,
103-
findHighlights: Theme.generateHighlightColors(findHighlight: find_highlight ?? defaults.findHighlights?.first!),
115+
findHighlights: Theme.generateHighlightColors(findHighlight: find_highlight),
104116
findHighlightForeground: find_highlight_foreground ?? defaults.findHighlightForeground,
105117
gutter: gutter ?? (background ?? defaults.gutter),
106118
gutterForeground: gutter_foreground ?? defaults.gutterForeground,
@@ -123,7 +135,7 @@ extension Theme {
123135
// Leave room for default highlight and selection colors
124136
let customHighlights = Style.N_RESERVED_STYLES - 2
125137
return [defaultHighlight] + (0..<customHighlights).map({
126-
return NSColor(hue: CGFloat((1.0 / Double(customHighlights)) * Double($0)), saturation: 1, brightness: brightness, alpha: alpha)
138+
return NSColor(hue: CGFloat((1.0 / Double(customHighlights)) * Double($0)) + hue, saturation: 1, brightness: brightness, alpha: alpha)
127139
})
128140
})
129141
}

0 commit comments

Comments
 (0)