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
@@ -317,6 +317,7 @@ struct ProseTextView: NSViewRepresentable {
|
||||
// pre-edit text — then session.edit on the stale view would
|
||||
// have flushed it over the user's real content (#71 fix).
|
||||
tv.textStorage?.setAttributedString(ProsePresenter.attribute(session.text))
|
||||
context.coordinator.fenceDelims = ProsePresenter.fenceDelimCount(session.text)
|
||||
// #66: restore cursor (clamped) + scroll.
|
||||
let length = (tv.string as NSString).length
|
||||
var cursor = session.restoreCursor ?? PostStore.CursorState()
|
||||
@@ -367,6 +368,10 @@ struct ProseTextView: NSViewRepresentable {
|
||||
var sessionRef: EditorSession?
|
||||
var loadedGeneration = -1
|
||||
var appliedCaretToken = -1
|
||||
/// #77: fence delimiter count — the cross-paragraph fence state
|
||||
/// fingerprint. A moved count means a ``` was typed/deleted and every
|
||||
/// line until the matching delimiter changed kind.
|
||||
var fenceDelims = 0
|
||||
|
||||
init(representable: ProseTextView) {
|
||||
onEdit = representable.onEdit
|
||||
@@ -375,9 +380,19 @@ struct ProseTextView: NSViewRepresentable {
|
||||
func textDidChange(_ notification: Notification) {
|
||||
guard let tv = notification.object as? NSTextView, let storage = tv.textStorage else { return }
|
||||
let sel = tv.selectedRange()
|
||||
// Re-attribute the paragraph(s) touching the selection — one pass.
|
||||
let paragraphRange = (storage.string as NSString).paragraphRange(for: sel)
|
||||
ProsePresenter.reattribute(storage as NSMutableAttributedString, paragraphRange: paragraphRange)
|
||||
let delims = ProsePresenter.fenceDelimCount(storage.string)
|
||||
if delims == fenceDelims {
|
||||
// Re-attribute the paragraph(s) touching the selection — one pass.
|
||||
let paragraphRange = (storage.string as NSString).paragraphRange(for: sel)
|
||||
ProsePresenter.reattribute(storage as NSMutableAttributedString, paragraphRange: paragraphRange)
|
||||
} else {
|
||||
// Delimiter typed/deleted: fence state flipped downstream —
|
||||
// restyle the whole document, keeping the caret put.
|
||||
fenceDelims = delims
|
||||
let selected = tv.selectedRange()
|
||||
tv.textStorage?.setAttributedString(ProsePresenter.attribute(storage.string))
|
||||
tv.setSelectedRange(selected)
|
||||
}
|
||||
tv.typingAttributes = ProseTypography.bodyAttributes
|
||||
if let sessionRef {
|
||||
sessionRef.edit(storage.string)
|
||||
|
||||
Reference in new issue
Block a user