test(folds): pin the typing budget at N/2N
CI / ci (push) Canceled after 0s
CI / ci (push) Canceled after 0s
The #142 in-place re-key had correctness coverage but no typing-cost guard — a quiet fallback to the full pass keeps every correctness pin green while restoring O(buffer) work per keystroke. Add an operation-count instrument (never wall-time): ProseList.parents gains an observeLines reporter, refreshFolds/refreshFoldRendering thread a per-call observer, and a per-instance onLineScan hook windows the paths that call refreshFolds() bare (the PostEditorView coordinator tail). No shared state — the hosted suite is parallel. Three pins: zero scanned lines for typing beside a fold at N=204 and 2N=404 lines; an exact-count control (206/406) proving the instrument is live and scaling; and a through-seam pin driving real insertText through a real ProseTextView.Coordinator into refreshFolds() — zero scans, fold survives, self-controlling with its own 206 liveness assert. Mutation-checked: severing the single observer firing fails the control and the through-seam pin.
This commit is contained in:
1 parent
7ed304124e
commit
c460545c59
3 files changed
+126
-5
No files matched your search
@@ -90,6 +90,12 @@ final class ProseListTextView: NSTextView {
|
||||
/// rejected, or none) → the full pass.
|
||||
var pendingPlainEdit: (range: NSRange, delta: Int)?
|
||||
|
||||
/// Brief-24 typing-budget window for paths that call `refreshFolds()`
|
||||
/// bare (the PostEditorView coordinator's textDidChange tail) — a
|
||||
/// per-instance, test-owned hook; nil in production. The per-call
|
||||
/// `observeScan` parameter takes precedence when both are set.
|
||||
var onLineScan: ((Int) -> Void)?
|
||||
|
||||
override func shouldChangeText(in affectedRange: NSRange, replacementString: String?) -> Bool {
|
||||
let accepted = super.shouldChangeText(in: affectedRange, replacementString: replacementString)
|
||||
pendingPlainEdit = nil
|
||||
@@ -202,7 +208,11 @@ final class ProseListTextView: NSTextView {
|
||||
/// recorded single-line edit takes the in-place re-key (no rescan, no
|
||||
/// storage swap); no folds → chrome-only refresh, everything else → the
|
||||
/// full pass.
|
||||
func refreshFolds() {
|
||||
/// `observeScan` (brief-24): the typing-budget instrument — reports the
|
||||
/// line count of every full-buffer scan this refresh performs. Nil in
|
||||
/// production; the typing-budget pins inject it to prove single-line
|
||||
/// edits take the in-place re-key (zero scans) at any buffer size.
|
||||
func refreshFolds(observeScan: ((Int) -> Void)? = nil) {
|
||||
defer { pendingPlainEdit = nil }
|
||||
if let edit = pendingPlainEdit, !folds.isEmpty, rekeyAfterPlainEdit(edit) {
|
||||
return
|
||||
@@ -211,7 +221,7 @@ final class ProseListTextView: NSTextView {
|
||||
chrome.refresh()
|
||||
return
|
||||
}
|
||||
refreshFoldRendering()
|
||||
refreshFoldRendering(observeScan: observeScan)
|
||||
}
|
||||
|
||||
func toggleFold(_ parent: ProseList.ParentHint) {
|
||||
@@ -227,8 +237,8 @@ final class ProseListTextView: NSTextView {
|
||||
/// same marker text; no match → the fold dies), restyle the document,
|
||||
/// re-hide every live scope, and park a caret that landed inside a
|
||||
/// hidden scope at its parent's marker end.
|
||||
func refreshFoldRendering() {
|
||||
let parents = ProseList.parents(in: string)
|
||||
func refreshFoldRendering(observeScan: ((Int) -> Void)? = nil) {
|
||||
let parents = ProseList.parents(in: string, observeLines: observeScan ?? onLineScan)
|
||||
// ponytail: nearest-same-marker re-key can move a fold across duplicate
|
||||
// marker texts — track the edit delta in shouldChangeText if that bites.
|
||||
var seenKeys = Set<Int>()
|
||||
|
||||
Reference in new issue
Block a user