feat(editor): land reading toggle — render, interact, typography slots (S1.2 #71)
Map #20 execution child, built per decisions #68/#69/#70: - ReadingPresenter: block-aware renderer (ADR-0010 stance) — blank-line split, one block per chunk; lists (bullets + ordered + nesting + auto-renumber via per-level counters — one rendering path), headings by level (h1 = slot size, h2 = 0.77x, ### = body+1, #### floors at bold body), HR via the editing syntaxOnly predicate, fenced code, blockquotes (QuoteTextBlock hairline), tables (NSTextTable 1px border, delimiter-row alignment), images (hover payload), links styled + retained. Footnotes stay fallback. Source ranges ride every block (click→edit map). - ReadingSurface: read-only selectable NSTextView canvas (#68: a presentation of the same TextKit2 document). Tap with no selection after mouseDown returns = edit intent at the clicked block (the tracking-loop fix); ⌘-click opens links; scroll tracking feeds the flip-back caret; image hover NSPopover loads off-main. - ProseTypography (#70): three role slots — Body / Headings / Code — each {face, size}, UserDefaults six values, member-based font resolution (family+weight lookup misresolves Concourse Book→Thin), silent system fallback; both prose surfaces read them; editing presenter's headings + dimmed syntax rewired through the slots. - PostEditorView: Read⇄Edit toolbar button (far left) + View menu "Toggle Reading Mode" + ⌘R; reading state transient per open; drafts included (draft mirror); flip-back caret hint applied once per token. - SettingsPaneView: Typography section — three slot rows (family picker incl. current face not in the installed list + size field). - kitchen-sink.md (+png): corpus piece exercising constructs absent from the eight posts, per #69. Verified: 94 unit tests (renderer classification, renumbering, source ranges, fallbacks) + UI smoke; PERF-3k renders 128 blocks in ~17 ms; live-app probe — Read renders kitchen-sink markers-hidden, renumbered, byte-stable file after full round-trip; click-to-edit flips at the clicked paragraph; typography ladder pixel-verified (20/15 ink px).
This commit is contained in:
1 parent
f2953ee07e
commit
4c91733e78
12 files changed
+1393
-33
No files matched your search
@@ -3,18 +3,48 @@
|
||||
// Museion
|
||||
//
|
||||
// #17 (S1.1): Settings — the Museion Home path, repoint-only (ADR-0004).
|
||||
// #71 (map #20 / #70): the Typography section — three role slots (Body /
|
||||
// Headings / Code), each {face, size}: a Picker over every installed font
|
||||
// family (defaults are being auditioned; shrinks to a curated shortlist
|
||||
// once they settle) + a size field. UserDefaults persistence; re-picking a
|
||||
// face is reset. Chrome stays system.
|
||||
//
|
||||
|
||||
import AppKit
|
||||
import SwiftUI
|
||||
|
||||
/// Settings pane. #17 scope: the Home control only — further settings arrive
|
||||
/// with their tickets. Choosing a folder repoints Museion at that root;
|
||||
/// content is never moved.
|
||||
/// Settings pane. Home control per #17; typography slots per #70.
|
||||
struct SettingsPaneView: View {
|
||||
@Binding var home: URL
|
||||
|
||||
/// Full family list once per pane lifetime (#70: full list while
|
||||
/// auditioning; the picker's current selection must be listed even when
|
||||
/// NSFontManager omits it — Iowan Old Style is such a case).
|
||||
private var families: [String] {
|
||||
let current = [
|
||||
UserDefaults.standard.string(forKey: "proseBodyFace"),
|
||||
UserDefaults.standard.string(forKey: "proseHeadingsFace"),
|
||||
UserDefaults.standard.string(forKey: "proseCodeFace"),
|
||||
].compactMap(\.self)
|
||||
let all = NSFontManager.shared.availableFontFamilies
|
||||
return Array((current + all).uniqued())
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
ScrollView {
|
||||
VStack(alignment: .leading, spacing: 24) {
|
||||
contentSection
|
||||
typographySection
|
||||
}
|
||||
.padding(24)
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)
|
||||
}
|
||||
.background(DesignTokens.background)
|
||||
}
|
||||
|
||||
// MARK: Home (#17)
|
||||
|
||||
private var contentSection: some View {
|
||||
VStack(alignment: .leading, spacing: 12) {
|
||||
Text("Content")
|
||||
.font(.system(size: 13, weight: .semibold))
|
||||
@@ -33,9 +63,32 @@ struct SettingsPaneView: View {
|
||||
.font(.callout)
|
||||
.foregroundStyle(DesignTokens.muted)
|
||||
}
|
||||
.padding(24)
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)
|
||||
.background(DesignTokens.background)
|
||||
}
|
||||
|
||||
// MARK: Typography (#70)
|
||||
|
||||
private var typographySection: some View {
|
||||
VStack(alignment: .leading, spacing: 12) {
|
||||
Text("Typography")
|
||||
.font(.system(size: 13, weight: .semibold))
|
||||
Text(
|
||||
"The three prose roles. Both the editor and reading mode use them; a missing face falls back to the system font.",
|
||||
)
|
||||
.font(.callout)
|
||||
.foregroundStyle(DesignTokens.muted)
|
||||
SlotRow(
|
||||
label: "Body", faceKey: "proseBodyFace", sizeKey: "proseBodySize",
|
||||
families: families,
|
||||
)
|
||||
SlotRow(
|
||||
label: "Headings", faceKey: "proseHeadingsFace", sizeKey: "proseHeadingsSize",
|
||||
families: families,
|
||||
)
|
||||
SlotRow(
|
||||
label: "Code", faceKey: "proseCodeFace", sizeKey: "proseCodeSize",
|
||||
families: families,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private func chooseHome() {
|
||||
@@ -49,3 +102,54 @@ struct SettingsPaneView: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// One role slot: face picker (full family list) + size stepper.
|
||||
private struct SlotRow: View {
|
||||
let label: String
|
||||
let faceKey: String
|
||||
let sizeKey: String
|
||||
let families: [String]
|
||||
|
||||
var body: some View {
|
||||
HStack(spacing: 10) {
|
||||
Text(label)
|
||||
.font(.system(size: 12, weight: .semibold))
|
||||
.frame(width: 76, alignment: .leading)
|
||||
Picker("", selection: faceBinding) {
|
||||
ForEach(families, id: \.self) { family in
|
||||
Text(family).tag(family)
|
||||
}
|
||||
}
|
||||
.labelsHidden()
|
||||
.frame(maxWidth: 320)
|
||||
TextField("", value: sizeBinding, format: .number)
|
||||
.textFieldStyle(.roundedBorder)
|
||||
.frame(width: 56)
|
||||
Text("pt")
|
||||
.font(.system(size: 11, design: DesignTokens.mono))
|
||||
.foregroundStyle(DesignTokens.muted)
|
||||
}
|
||||
}
|
||||
|
||||
private var faceBinding: Binding<String> {
|
||||
Binding(
|
||||
get: { UserDefaults.standard.string(forKey: faceKey) ?? "" },
|
||||
set: { UserDefaults.standard.set($0, forKey: faceKey) },
|
||||
)
|
||||
}
|
||||
|
||||
private var sizeBinding: Binding<Double> {
|
||||
Binding(
|
||||
get: { UserDefaults.standard.double(forKey: sizeKey) },
|
||||
set: { UserDefaults.standard.set(max(6, min(72, $0)), forKey: sizeKey) },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private extension Array {
|
||||
/// Order-preserving dedupe (face lists merge current + installed).
|
||||
func uniqued() -> [Element] where Element: Hashable {
|
||||
var seen = Set<Element>()
|
||||
return filter { seen.insert($0).inserted }
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user