Skip to content

Commit d03ccdd

Browse files
committed
Fix comment colors
1 parent 6d75a07 commit d03ccdd

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

HackerNews/Extensions/Atributika.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@ extension TagTransformer {
1818
}
1919

2020
extension String {
21-
var styledAttributedString: NSAttributedString {
21+
func styledAttributedString(textColor: Color) -> NSAttributedString {
2222
let paragraphStyle = NSMutableParagraphStyle()
2323
paragraphStyle.paragraphSpacing = 8
2424
let systemFontSize = NSFont.systemFontSize(for: .regular)
2525
let all = Style
2626
.font(.systemFont(ofSize: systemFontSize))
27+
.foregroundColor(textColor)
2728
.paragraphStyle(paragraphStyle)
2829
let a = Style("a")
2930
let i = Style("i")

HackerNews/Page/CommentCellView.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,14 @@ class CommentCellView: NSTableCellView {
5656
}
5757
}
5858
authorLabel.stringValue = comment.author
59-
textLabel.attributedStringValue = comment.text.styledAttributedString
59+
let textColor: NSColor
60+
switch comment.color {
61+
case .c00: textColor = .labelColor
62+
case .c5a, .c73, .c82: textColor = .secondaryLabelColor
63+
case .c88, .c9c, .cae: textColor = .tertiaryLabelColor
64+
case .cbe, .cce, .cdd: textColor = .quaternaryLabelColor
65+
}
66+
textLabel.attributedStringValue = comment.text.styledAttributedString(textColor: textColor)
6067
creationLabel.stringValue = formatter.localizedString(for: comment.creation, relativeTo: Date())
6168
}
6269

HackerNews/Page/ItemViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class ItemViewController: NSViewController {
3030
urlButton.isHidden = false
3131
urlButton.title = host
3232
} else if let text = story.content.text {
33-
textLabel.attributedStringValue = text.styledAttributedString
33+
textLabel.attributedStringValue = text.styledAttributedString(textColor: .labelColor)
3434
textScrollView.isHidden = false
3535
urlButton.isHidden = true
3636
} else {

0 commit comments

Comments
 (0)