Skip to content

Commit 93277c2

Browse files
committed
Fix code rendering in light mode in chat panel
1 parent e29c1a7 commit 93277c2

2 files changed

Lines changed: 21 additions & 7 deletions

File tree

Core/Sources/SuggestionWidget/SuggestionPanelContent/ChatPanel.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,8 @@ struct ChatCodeSyntaxHighlighter: CodeSyntaxHighlighter {
374374
let content = highlightedCodeBlock(
375375
code: content,
376376
language: language ?? "",
377-
brightMode: brightMode
377+
brightMode: brightMode,
378+
fontSize: 12
378379
)
379380
return Text(AttributedString(content))
380381
}

Core/Sources/SuggestionWidget/SyntaxHighlighting.swift

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@ import AppKit
22
import Foundation
33
import Highlightr
44
import Splash
5-
import XPCShared
65
import SwiftUI
6+
import XPCShared
77

8-
func highlightedCodeBlock(code: String, language: String, brightMode: Bool) -> NSAttributedString {
8+
func highlightedCodeBlock(
9+
code: String,
10+
language: String,
11+
brightMode: Bool,
12+
fontSize: Double
13+
) -> NSAttributedString {
914
switch language {
1015
case "swift":
1116
let plainTextColor = brightMode
@@ -42,7 +47,7 @@ func highlightedCodeBlock(code: String, language: String, brightMode: Bool) -> N
4247
)
4348
let formatted = NSMutableAttributedString(attributedString: highlighter.highlight(code))
4449
formatted.addAttributes(
45-
[.font: NSFont.monospacedSystemFont(ofSize: 13, weight: .regular)],
50+
[.font: NSFont.monospacedSystemFont(ofSize: fontSize, weight: .regular)],
4651
range: NSRange(location: 0, length: formatted.length)
4752
)
4853
return formatted
@@ -54,14 +59,17 @@ func highlightedCodeBlock(code: String, language: String, brightMode: Bool) -> N
5459
func unhighlightedCode() -> NSAttributedString {
5560
return NSAttributedString(
5661
string: code,
57-
attributes: [.foregroundColor: NSColor.white]
62+
attributes: [
63+
.foregroundColor: brightMode ? NSColor.black : NSColor.white,
64+
.font: NSFont.monospacedSystemFont(ofSize: fontSize, weight: .regular),
65+
]
5866
)
5967
}
6068
guard let highlighter = Highlightr() else {
6169
return unhighlightedCode()
6270
}
6371
highlighter.setTheme(to: brightMode ? "xcode" : "atom-one-dark")
64-
highlighter.theme.setCodeFont(.monospacedSystemFont(ofSize: 13, weight: .regular))
72+
highlighter.theme.setCodeFont(.monospacedSystemFont(ofSize: fontSize, weight: .regular))
6573
guard let formatted = highlighter.highlight(code, as: language) else {
6674
return unhighlightedCode()
6775
}
@@ -73,7 +81,12 @@ func highlightedCodeBlock(code: String, language: String, brightMode: Bool) -> N
7381
}
7482

7583
func highlighted(code: String, language: String, brightMode: Bool) -> [NSAttributedString] {
76-
let formatted = highlightedCodeBlock(code: code, language: language, brightMode: brightMode)
84+
let formatted = highlightedCodeBlock(
85+
code: code,
86+
language: language,
87+
brightMode: brightMode,
88+
fontSize: 13
89+
)
7790
let middleDotColor = brightMode
7891
? NSColor.black.withAlphaComponent(0.1)
7992
: NSColor.white.withAlphaComponent(0.1)

0 commit comments

Comments
 (0)