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:
AlexKucera committed 2026-10-08 14:11:47 +02:00
1 parent fefdd9a6fa
commit 1f7557a2ed
4 files changed
+102 -99

No files matched your search

+24 -6
View File
@@ -119,16 +119,34 @@ struct ProsePresenterTests {
}
@Test func `fences interior retrofit`() {
// reattribute over a paragraph inside an existing fence — state comes
// from the prefix scan, not the paragraph alone.
let full = "```\nfirst\n```\n\npara\n"
// Reattribute a paragraph INSIDE a fence at location > 0 — the
// fence state must come from the prefix scan, not the paragraph.
let full = "para before\n\n```\nfirst code\n```\n\nafter"
let out = NSMutableAttributedString(attributedString: ProsePresenter.attribute(full))
let ns = full as NSString
let para = ns.paragraphRange(for: NSRange(location: 0, length: 0)) // "```"
let firstRange = ns.range(of: "first code")
// clobber the line to body, then reattribute its paragraph
out.setAttributes(ProseTypography.bodyAttributes, range: firstRange)
let para = ns.paragraphRange(for: NSRange(location: firstRange.location, length: 0))
ProsePresenter.reattribute(out, paragraphRange: para)
let loc = ns.range(of: "first").location
let font = out.attribute(.font, at: loc, effectiveRange: nil) as? NSFont
let font = out.attribute(.font, at: firstRange.location, effectiveRange: nil) as? NSFont
#expect(font?.pointSize == 14)
// Outside the fence (prefix scan returns false): body styling.
let afterRange = ns.range(of: "after")
out.setAttributes([.font: ProseTypography.codeFont], range: afterRange)
let afterPara = ns.paragraphRange(for: NSRange(location: afterRange.location, length: 0))
ProsePresenter.reattribute(out, paragraphRange: afterPara)
let afterFont = out.attribute(.font, at: afterRange.location, effectiveRange: nil) as? NSFont
#expect(afterFont?.pointSize == 17)
}
@Test func `fence delim count tracks delimiters`() {
#expect(ProsePresenter.fenceDelimCount("plain") == 0)
#expect(ProsePresenter.fenceDelimCount("```\ncode\n```") == 2)
#expect(ProsePresenter.fenceDelimCount("~~~\ncode\n```") == 2)
#expect(ProsePresenter.fenceDelimCount("```js\nlet x = 1\n```") == 2)
#expect(ProsePresenter.fenceDelimCount("not ``` inline, a fence needs line start") == 0)
}
@Test func `underscore in word not italic`() {