import Cocoa
protocol ConfTextColorTheme {
+ var defaultColor: NSColor { get }
+
func color(for: highlight_type) -> NSColor
}
struct ConfTextAquaColorTheme: ConfTextColorTheme {
+ var defaultColor: NSColor {
+ return NSColor(hex: "#000000") // Plain text in Xcode
+ }
+
func color(for highlightType: highlight_type) -> NSColor {
switch highlightType.rawValue {
case HighlightSection.rawValue:
case HighlightError.rawValue:
return NSColor(hex: "#C41A16") // Strings in Xcode
default:
- return NSColor(hex: "#000000") // Plain text in Xcode
+ return defaultColor
}
}
}
struct ConfTextDarkAquaColorTheme: ConfTextColorTheme {
+ var defaultColor: NSColor {
+ return NSColor(hex: "#FFFFFF") // Plain text in Xcode
+ }
+
func color(for highlightType: highlight_type) -> NSColor {
switch highlightType.rawValue {
case HighlightSection.rawValue:
case HighlightError.rawValue:
return NSColor(hex: "#FF4C4C") // Strings in Xcode
default:
- return NSColor(hex: "#FFFFFF") // Plain text in Xcode
+ return defaultColor
}
}
}
hasError = false
privateKeyString = nil
+ let fullTextRange = NSRange(location: 0, length: (backingStore.string as NSString).length)
+
backingStore.beginEditing()
+ if let textColorTheme = textColorTheme {
+ let defaultAttributes: [NSAttributedString.Key: Any] = [
+ .foregroundColor: textColorTheme.defaultColor,
+ .font: defaultFont
+ ]
+ backingStore.setAttributes(defaultAttributes, range: fullTextRange)
+ }
var spans = highlight_config(backingStore.string.cString(using: String.Encoding.utf8))!
while spans.pointee.type != HighlightEnd {
backingStore.endEditing()
beginEditing()
- edited(.editedAttributes, range: NSRange(location: 0, length: (backingStore.string as NSString).length), changeInLength: 0)
+ edited(.editedAttributes, range: fullTextRange, changeInLength: 0)
endEditing()
}