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.
|
||||
|
||||
@@ -226,7 +226,9 @@ struct PostEditorView: View {
|
||||
}
|
||||
}
|
||||
.padding(.horizontal, 16)
|
||||
.frame(minHeight: 40)
|
||||
// #90: align with the Posts header and mentor header at the
|
||||
// export's 52px pane-head height.
|
||||
.frame(minHeight: 52)
|
||||
}
|
||||
|
||||
private func saveNow() {
|
||||
@@ -336,9 +338,11 @@ struct ProseTextView: NSViewRepresentable {
|
||||
// #77: squiggles follow the posture toggle (default off).
|
||||
tv.isContinuousSpellCheckingEnabled = spellChecking
|
||||
tv.usesFindBar = true
|
||||
// #21: focus ground joins the workspace background (NSColor(Color)
|
||||
// bridges; white in the unfocused card).
|
||||
tv.backgroundColor = focused ? NSColor(DesignTokens.background) : NSColor.white
|
||||
// #21/#89: page ground — surface (cream page) unfocused, chrome in
|
||||
// focus. One editing color + one focus color, nothing hardcoded.
|
||||
tv.backgroundColor = focused ? NSColor(DesignTokens.background) : NSColor(DesignTokens.surface)
|
||||
// #89: accent caret — findable, matches the app's rust.
|
||||
tv.insertionPointColor = NSColor(DesignTokens.accent)
|
||||
tv.typingAttributes = ProseTypography.bodyAttributes
|
||||
tv.delegate = context.coordinator
|
||||
tv.layoutManager?.allowsNonContiguousLayout = true
|
||||
@@ -361,7 +365,7 @@ struct ProseTextView: NSViewRepresentable {
|
||||
// out at rest (iOS-like), instead of always occupying the right edge.
|
||||
scroll.scrollerStyle = .overlay
|
||||
scroll.drawsBackground = true
|
||||
scroll.backgroundColor = focused ? NSColor(DesignTokens.background) : NSColor.white
|
||||
scroll.backgroundColor = focused ? NSColor(DesignTokens.background) : NSColor(DesignTokens.surface)
|
||||
context.coordinator.textView = tv
|
||||
context.coordinator.sessionRef = session // strong: both die with the editor
|
||||
return scroll
|
||||
@@ -372,10 +376,12 @@ struct ProseTextView: NSViewRepresentable {
|
||||
// #77: posture toggle while editing — cheap idempotent set.
|
||||
tv.isContinuousSpellCheckingEnabled = spellChecking
|
||||
// #21: the ground follows focus in/out without a remount.
|
||||
let ground = focused ? NSColor(DesignTokens.background) : NSColor.white
|
||||
let ground = focused ? NSColor(DesignTokens.background) : NSColor(DesignTokens.surface)
|
||||
tv.backgroundColor = ground
|
||||
scroll.backgroundColor = ground
|
||||
context.coordinator.focused = focused
|
||||
// #21 calibration amendment: typewriter inset is editor-wide now —
|
||||
// every editing surface gets the breathing room, focus or not.
|
||||
CaretCentering.syncTypewriterInset(textView: tv)
|
||||
if let session {
|
||||
context.coordinator.sessionRef = session
|
||||
// Load only when the generation moved (open, Yes-reload) — never
|
||||
@@ -439,9 +445,6 @@ struct ProseTextView: NSViewRepresentable {
|
||||
var sessionRef: EditorSession?
|
||||
var loadedGeneration = -1
|
||||
var appliedCaretToken = -1
|
||||
/// #21: focus posture mirror — soft centering applies while typing
|
||||
/// in focus only.
|
||||
var focused = false
|
||||
/// #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.
|
||||
@@ -469,10 +472,9 @@ struct ProseTextView: NSViewRepresentable {
|
||||
}
|
||||
tv.typingAttributes = ProseTypography.bodyAttributes
|
||||
// #21: soft caret centering — typing only, never scrollback or
|
||||
// drag-selection (the reader never gets fought).
|
||||
if focused {
|
||||
CaretCentering.centerCaretWhileTyping(textView: tv)
|
||||
}
|
||||
// drag-selection (the reader never gets fought). Calibration
|
||||
// amendment: editor-wide, no longer focus-gated.
|
||||
CaretCentering.centerCaretWhileTyping(textView: tv)
|
||||
if let sessionRef {
|
||||
sessionRef.edit(storage.string)
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user