feat(editor): configurable text flow — line height + spacing knobs (#71 follow-up 7)

Three UserDefaults-backed knobs in ProseTypography (line-height multiple,
space-after-¶ and space-after-heading in body lines, clamped), surfaced
in Settings → Text Flow. Also fixes two real bugs from the last commit:
paragraphSpacing was set to 1.25 POINTS (now lines × linePoints), and
reading-mode body paragraphs never received the rhythm at all (they rode
the editing surface's fixed 10pt) — both surfaces now share one rhythm.
This commit is contained in:
AlexKucera committed 2026-10-06 13:43:43 +02:00
1 parent 2d4e2563f7
commit 6d7d1411a2
4 files changed
+98 -5

No files matched your search

+37
View File
@@ -28,6 +28,11 @@ nonisolated enum ProseTypography {
static let defaultBodySize: Double = 17
static let defaultHeadingsSize: Double = 26
static let defaultCodeSize: Double = 13
/// Text flow (#71 polish): line-height multiple + paragraph/heading
/// spacing measured in body lines — different faces need different flow.
static let defaultLineHeight: Double = 1.25
static let defaultParagraphSpacingLines: Double = 1
static let defaultHeadingSpacingLines: Double = 2
/// Register the six defaults once at app start.
static func registerDefaults() {
@@ -38,6 +43,9 @@ nonisolated enum ProseTypography {
"proseHeadingsSize": defaultHeadingsSize,
"proseCodeFace": defaultCodeFace,
"proseCodeSize": defaultCodeSize,
"proseLineHeight": defaultLineHeight,
"proseParagraphSpacingLines": defaultParagraphSpacingLines,
"proseHeadingSpacingLines": defaultHeadingSpacingLines,
])
}
@@ -83,6 +91,35 @@ nonisolated enum ProseTypography {
bolded(bodyFont)
}
// MARK: Text flow (#71 polish)
/// Line-height multiple (clamped 1…2; 0/absent → default).
static var lineHeightMultiple: CGFloat {
clamped("proseLineHeight", default: defaultLineHeight, 1 ... 2)
}
/// Spacing after body paragraphs, in body lines.
static var paragraphSpacingLines: CGFloat {
clamped("proseParagraphSpacingLines", default: defaultParagraphSpacingLines, 0 ... 4)
}
/// Spacing after headings, in body lines.
static var headingSpacingLines: CGFloat {
clamped("proseHeadingSpacingLines", default: defaultHeadingSpacingLines, 0 ... 6)
}
/// One body line at the configured flow, in points.
static var linePoints: CGFloat {
let f = bodyFont
return (f.ascender - f.descender + f.leading) * lineHeightMultiple
}
private static func clamped(_ key: String, default def: Double, _ range: ClosedRange<Double>) -> CGFloat {
let stored = UserDefaults.standard.double(forKey: key)
let value = stored == 0 ? def : stored
return CGFloat(min(max(value, range.lowerBound), range.upperBound))
}
// MARK: Attribute stacks (reading + editing share them)
static var foregroundColor: NSColor {