fix(editor): audit fixes — fence staleness, font caching, lint shrink (#77)
- HIGH: fence delimiter edits now restyle the whole document (delimiter count fingerprint in the coordinator; count moved = full re-attribute, caret preserved) — typing/deleting a ``` flipped every line until the match before - derived fonts + measureWidth cached as nonisolated(unsafe) static let (were NSFontManager.convert per line per pass) - h2/h3/h4 line height calibrated from their own face's metrics - 7+ hashes fall to body (CommonMark cap); tab-indented heading marker dims the hash, not the tab - intraword _ spans unclaim on reject so the fallback char-dim takes them - shrink: fenceState reuses contentLines+classify (isDelim deleted), marker regexes as literals (helper + 2 lint disables deleted), charBefore/After via NSString, dead colors + forwarders deleted - vacuous retrofit test replaced with a real one + fenceDelimCount test
This commit is contained in:
1 parent
fefdd9a6fa
commit
1f7557a2ed
4 files changed
+102
-99
No files matched your search
@@ -25,55 +25,43 @@ nonisolated enum ProseTypography {
|
||||
|
||||
/// Body = Valkyrie OT B (the screen cut; CoreText unifies the OT family
|
||||
/// as "Valkyrie OT" — only B members installed, no A/B ambiguity).
|
||||
static var bodyFont: NSFont {
|
||||
NSFont(name: "ValkyrieOTBRegular", size: bodySize) ?? NSFont.systemFont(ofSize: bodySize)
|
||||
}
|
||||
/// ponytail: nonisolated(unsafe) — NSFont isn't Sendable; the cached
|
||||
/// instances are never mutated after creation.
|
||||
nonisolated(unsafe) static let bodyFont: NSFont = .init(name: "ValkyrieOTBRegular", size: bodySize) ?? NSFont.systemFont(ofSize: bodySize)
|
||||
|
||||
/// Headings = Concourse OT (the designer's own pairing with Valkyrie);
|
||||
/// Semibold carries heading weight better than Book on screen.
|
||||
static var headingFont: NSFont {
|
||||
NSFont(name: "ConcourseOT6Semibold", size: heading1Size) ?? NSFont.systemFont(ofSize: heading1Size, weight: .semibold)
|
||||
}
|
||||
nonisolated(unsafe) static let headingFont: NSFont = .init(name: "ConcourseOT6Semibold", size: heading1Size) ?? NSFont.systemFont(ofSize: heading1Size, weight: .semibold)
|
||||
|
||||
/// h2 = the headings face at CSS's 0.85× ladder step (#77).
|
||||
static var heading2Font: NSFont {
|
||||
NSFont(name: "ConcourseOT6Semibold", size: heading2Size) ?? NSFont.systemFont(ofSize: heading2Size, weight: .semibold)
|
||||
}
|
||||
nonisolated(unsafe) static let heading2Font: NSFont = .init(name: "ConcourseOT6Semibold", size: heading2Size) ?? NSFont.systemFont(ofSize: heading2Size, weight: .semibold)
|
||||
|
||||
/// h3 = body face, sized up, weight 600 (CSS h3: body-face w600). The B
|
||||
/// cut has no 600 member — the bold trait (700, real or synthesized) is
|
||||
/// the nearest expressible. ponytail: trait-convert; a true semibold face
|
||||
/// would drop in here if ever installed.
|
||||
static var heading3Font: NSFont {
|
||||
NSFontManager.shared.convert(
|
||||
NSFontManager.shared.convert(bodyFont, toSize: heading3Size),
|
||||
toHaveTrait: .boldFontMask,
|
||||
)
|
||||
}
|
||||
nonisolated(unsafe) static let heading3Font: NSFont = NSFontManager.shared.convert(
|
||||
NSFontManager.shared.convert(bodyFont, toSize: heading3Size),
|
||||
toHaveTrait: .boldFontMask,
|
||||
)
|
||||
|
||||
/// h4+ floors at bold body (CSS h4–h6).
|
||||
static var headingBoldFont: NSFont {
|
||||
NSFontManager.shared.convert(bodyFont, toHaveTrait: .boldFontMask)
|
||||
}
|
||||
nonisolated(unsafe) static let headingBoldFont: NSFont = NSFontManager.shared.convert(bodyFont, toHaveTrait: .boldFontMask)
|
||||
|
||||
/// Code slot (inline code, fenced blocks, editing syntax dim).
|
||||
static var codeFont: NSFont {
|
||||
NSFont(name: "UbuntuMonoNFM", size: codeSize) ?? NSFont.monospacedSystemFont(ofSize: codeSize, weight: .regular)
|
||||
}
|
||||
nonisolated(unsafe) static let codeFont: NSFont = .init(name: "UbuntuMonoNFM", size: codeSize) ?? NSFont.monospacedSystemFont(ofSize: codeSize, weight: .regular)
|
||||
|
||||
/// Blank source lines at 9pt (#77 half-height separators).
|
||||
static var blankFont: NSFont {
|
||||
NSFontManager.shared.convert(bodyFont, toSize: blankSize)
|
||||
}
|
||||
nonisolated(unsafe) static let blankFont: NSFont = NSFontManager.shared.convert(bodyFont, toSize: blankSize)
|
||||
|
||||
/// Editor measure (#77): reading.css `--measure: 66ch` — the advance of
|
||||
/// "0" × 66 in the body face (px→pt 1:1), + the text container's 24pt
|
||||
/// lineFragmentPadding on both sides (the CSS body's 24px side padding).
|
||||
static var measureWidth: CGFloat {
|
||||
static let measureWidth: CGFloat = {
|
||||
let zero = NSAttributedString(string: "0", attributes: [.font: bodyFont])
|
||||
let ch = zero.size().width
|
||||
return (ch * 66).rounded() + 48
|
||||
}
|
||||
}()
|
||||
|
||||
/// Line-height parity with reading.css (#77): CSS `line-height: n` means
|
||||
/// n × font-size pixels; TextKit's lineHeightMultiple multiplies the
|
||||
@@ -85,13 +73,9 @@ nonisolated enum ProseTypography {
|
||||
return (font.pointSize * cssLineHeight) / natural
|
||||
}
|
||||
|
||||
static var italicBodyFont: NSFont {
|
||||
NSFontManager.shared.convert(bodyFont, toHaveTrait: .italicFontMask)
|
||||
}
|
||||
nonisolated(unsafe) static let italicBodyFont: NSFont = NSFontManager.shared.convert(bodyFont, toHaveTrait: .italicFontMask)
|
||||
|
||||
static var boldBodyFont: NSFont {
|
||||
NSFontManager.shared.convert(bodyFont, toHaveTrait: .boldFontMask)
|
||||
}
|
||||
nonisolated(unsafe) static let boldBodyFont: NSFont = NSFontManager.shared.convert(bodyFont, toHaveTrait: .boldFontMask)
|
||||
|
||||
// MARK: Attribute stacks (editing surface)
|
||||
|
||||
@@ -104,10 +88,6 @@ nonisolated enum ProseTypography {
|
||||
NSColor(white: 0.55, alpha: 1)
|
||||
}
|
||||
|
||||
static var quoteRuleColor: NSColor {
|
||||
NSColor(white: 0.78, alpha: 1)
|
||||
}
|
||||
|
||||
/// Secondary ink — reading.css --secondary #48484d (quotes, #77).
|
||||
static var secondaryColor: NSColor {
|
||||
NSColor(red: 0x48 / 255, green: 0x48 / 255, blue: 0x4D / 255, alpha: 1)
|
||||
@@ -123,11 +103,6 @@ nonisolated enum ProseTypography {
|
||||
NSColor(red: 0xF5 / 255, green: 0xF5 / 255, blue: 0xF7 / 255, alpha: 1)
|
||||
}
|
||||
|
||||
/// Table borders + editing-surface hairline (≈ DesignTokens.border).
|
||||
static var tableBorderColor: NSColor {
|
||||
NSColor(red: 0xE8 / 255, green: 0xE5 / 255, blue: 0xDF / 255, alpha: 1)
|
||||
}
|
||||
|
||||
static var bodyAttributes: [NSAttributedString.Key: Any] {
|
||||
[
|
||||
.font: bodyFont,
|
||||
|
||||
Reference in new issue
Block a user