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