Separate code font size

This commit is contained in:
Ian Gulliver
2026-10-21 10:15:26 -07:00
parent 1ab0ebad9f
commit b5f23e20c2
4 changed files with 35 additions and 18 deletions
+12 -7
View File
@@ -11,24 +11,29 @@ final class FontSize {
static let range = 9...20
private(set) var body = PrefsRecord.defaultFontSize
private(set) var code = PrefsRecord.defaultFontSize
private init() {
load()
}
func load() {
body = record()?.fontSize ?? PrefsRecord.defaultFontSize
let r = record()
body = r?.fontSize ?? PrefsRecord.defaultFontSize
code = r?.codeFontSize ?? PrefsRecord.defaultFontSize
}
func set(_ size: Int) {
func set(body: Int, code: Int) {
if let r = record() {
r.fontSize = size
r.fontSize = body
r.codeFontSize = code
r.saved = Date()
} else {
persistence.insert(PrefsRecord(fontSize: size))
persistence.insert(PrefsRecord(fontSize: body, codeFontSize: code))
}
saveRecords()
body = size
self.body = body
self.code = code
}
private func record() -> PrefsRecord? {
@@ -52,10 +57,10 @@ enum Fonts {
private static let fonts = Mutex<[String: CTFont]>([:])
// Call sites give sizes relative to a 13pt body; the user's font size shifts them all.
// Call sites give sizes relative to a 13pt body; the user's text or code size shifts them.
@MainActor
private static func cached(_ size: CGFloat, _ weight: CGFloat, _ italic: Bool, _ mono: Bool) -> CTFont {
let size = size + CGFloat(FontSize.shared.body - 13)
let size = size + CGFloat((mono ? FontSize.shared.code : FontSize.shared.body) - 13)
let key = "\(size) \(weight) \(italic) \(mono)"
return fonts.withLock { fonts in
if let f = fonts[key] {