The bottom clamp parked the scroll and no-oped every keystroke when typing at the document end — the natural writing position. Padding the text container by half the viewport (typewriter breathing room) lets the clamp center the last lines. Calibration ruling: typewriter centering and breathing room are editor-wide, not focus-gated.
This commit is contained in:
1 parent
695ad5e5f9
commit
34aa88b020
2 files changed
+36
-14
No files matched your search
@@ -164,11 +164,31 @@ nonisolated enum CaretCentering {
|
||||
return clamped
|
||||
}
|
||||
|
||||
/// #21 calibration defect: typing at the document END (the natural
|
||||
/// writing position) parked at the bottom clamp and no-oped — the caret
|
||||
/// rode the lower edge forever. Breathing room: pad the document by
|
||||
/// half the viewport so the clamp can center the last lines (and the
|
||||
/// first — the inset is symmetric). ponytail: window resizes between
|
||||
/// updateNSView passes re-sync on the next keystroke via the guard.
|
||||
/// Calibration amendment (2026-10-09): typewriter is EDITOR-WIDE, not
|
||||
/// focus-gated — Alexander's call at the #88 gate; revert = restore the
|
||||
/// focused guard at the call sites.
|
||||
@MainActor
|
||||
static func syncTypewriterInset(textView: NSTextView) {
|
||||
guard let clip = textView.enclosingScrollView?.contentView else { return }
|
||||
let target = clip.bounds.height / 2
|
||||
guard textView.textContainerInset.height != target else { return }
|
||||
textView.textContainerInset = NSSize(width: 0, height: target)
|
||||
// Re-clamp the origin to the resized document (short-doc floor).
|
||||
textView.scrollRangeToVisible(textView.selectedRange())
|
||||
}
|
||||
|
||||
/// Applied: animate the scroll so the caret settles back toward the
|
||||
/// center. Typing only — never route scroll or selection events here.
|
||||
@MainActor
|
||||
static func centerCaretWhileTyping(textView: NSTextView) {
|
||||
guard let window = textView.window else { return }
|
||||
syncTypewriterInset(textView: textView)
|
||||
let sel = textView.selectedRange()
|
||||
guard sel.length == 0, sel.location >= 0 else { return }
|
||||
// firstRect(forCharacterRange:) answers in SCREEN coordinates.
|
||||
|
||||
Reference in new issue
Block a user