fix(editor): source-editor spacing — blank lines are the separator (#71 follow-up 8)

Two defects from the flow-knob commit: (1) edit mode got reading-mode's
paragraph spacing stacked on top of the visible blank source lines —
gaps tripled. Source editors render the blank line AS the separator;
paragraph spacing is now 0, only lineHeightMultiple rides the knobs.
(2) Knob changes never reached an open editor — updateNSView now
re-attributes the whole storage (selection preserved) when
ProseTypography.flowKey moves.
This commit is contained in:
AlexKucera committed 2026-10-06 14:14:17 +02:00
1 parent 6d7d1411a2
commit 677dc8c073
3 files changed
+22 -7

No files matched your search

+10
View File
@@ -297,6 +297,15 @@ struct ProseTextView: NSViewRepresentable {
func updateNSView(_ scroll: NSScrollView, context: Context) {
guard let tv = scroll.documentView as? NSTextView else { return }
// Typography/flow knob change: re-attribute everything, keep text
// and selection (settings live in another pane; the editor is idle).
if context.coordinator.appliedFlowKey != ProseTypography.flowKey {
context.coordinator.appliedFlowKey = ProseTypography.flowKey
let sel = tv.selectedRange()
let storage = tv.textStorage as! NSMutableAttributedString
storage.setAttributedString(ProsePresenter.attribute(tv.string))
tv.setSelectedRange(sel)
}
if let session {
context.coordinator.sessionRef = session
// Load only when the generation moved (open, Yes-reload) — never
@@ -348,6 +357,7 @@ struct ProseTextView: NSViewRepresentable {
var sessionRef: EditorSession?
var loadedGeneration = -1
var appliedCaretToken = -1
var appliedFlowKey = ""
init(representable: ProseTextView) {
onEdit = representable.onEdit
+6 -7
View File
@@ -40,15 +40,14 @@ nonisolated enum ProsePresenter {
/// Paragraph spacing per line kind, applied via NSParagraphStyle.
/// ponytail: quote rides body spacing — attributes(for:) styles quotes
/// as body anyway; dedicated quote spacing waits for #20's polish pass.
static func paragraph(_ kind: LineKind) -> NSParagraphStyle {
static func paragraph(_: LineKind) -> NSParagraphStyle {
let style = NSMutableParagraphStyle()
// Edit mode shows blank source lines — the blank line IS the
// separator. Only line height rides the flow knobs here; the
// paragraph/heading spacing knobs are reading-mode only.
style.lineHeightMultiple = ProseTypography.lineHeightMultiple
let line = ProseTypography.linePoints
switch kind {
case .heading1: style.paragraphSpacing = 2 * line; style.paragraphSpacingBefore = 26
case .heading2: style.paragraphSpacing = 2 * line; style.paragraphSpacingBefore = 1 * line
case .quote, .syntaxOnly, .body: style.paragraphSpacing = 1 * line
}
style.paragraphSpacing = 0
style.paragraphSpacingBefore = 0
return style
}
+6
View File
@@ -108,6 +108,12 @@ nonisolated enum ProseTypography {
clamped("proseHeadingSpacingLines", default: defaultHeadingSpacingLines, 0 ... 6)
}
/// Every value the prose surfaces render from, summed — a change key
/// for live re-attribution when settings move.
static var flowKey: String {
"\(bodyFont.fontName)@\(bodyFont.pointSize)|\(codeFont.fontName)@\(codeFont.pointSize)|\(headingFont.fontName)@\(headingFont.pointSize)|lh=\(lineHeightMultiple)|p=\(paragraphSpacingLines)|h=\(headingSpacingLines)"
}
/// One body line at the configured flow, in points.
static var linePoints: CGFloat {
let f = bodyFont