fix(editor): typewriter centering works at document end, editor-wide (#88, #21)

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:
AlexKucera committed 2026-10-09 20:24:51 +02:00
1 parent 695ad5e5f9
commit 34aa88b020
2 files changed
+36 -14

No files matched your search

+16 -14
View File
@@ -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 {