From 677dc8c07397304547a51890760e4d6006ba5fdf Mon Sep 17 00:00:00 2001 From: Alexander Kucera Date: Tue, 6 Oct 2026 14:14:17 +0200 Subject: [PATCH] =?UTF-8?q?fix(editor):=20source-editor=20spacing=20?= =?UTF-8?q?=E2=80=94=20blank=20lines=20are=20the=20separator=20(#71=20foll?= =?UTF-8?q?ow-up=208)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- Museion/PostEditorView.swift | 10 ++++++++++ Museion/ProsePresenter.swift | 13 ++++++------- Museion/ProseTypography.swift | 6 ++++++ 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/Museion/PostEditorView.swift b/Museion/PostEditorView.swift index a87cb00..952d89e 100644 --- a/Museion/PostEditorView.swift +++ b/Museion/PostEditorView.swift @@ -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 diff --git a/Museion/ProsePresenter.swift b/Museion/ProsePresenter.swift index 6ad9838..4738ed2 100644 --- a/Museion/ProsePresenter.swift +++ b/Museion/ProsePresenter.swift @@ -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 } diff --git a/Museion/ProseTypography.swift b/Museion/ProseTypography.swift index 5538b2e..99a62c8 100644 --- a/Museion/ProseTypography.swift +++ b/Museion/ProseTypography.swift @@ -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