Pin iOS terminal viewport to keyboard without transition flashes

Closed
AZ
2mo ago
+161-94

Fixes iOS terminal keyboard presentation on iOS 27.

The host now owns keyboard transition geometry, clips the terminal at a single dock boundary, freezes Ghostty grid resize until the transition settles, and folds live presentation translation into the next reversal. Sparse terminal content stays visible and the visible terminal edge tracks the keyboard dock within two physical pixels.

Includes behavior coverage for rapid keyboard reversals and genuine in-place control retargets.

Verification: Swift parse and diff checks pass. Tagged Mac build kbr2 passed. The focused hosted E2E run is in progress. Physical iPhone install is queued pending device reconnect.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.


Summary by cubic

Pins the visible iOS terminal viewport to the software keyboard without flashes. Previously the renderer and dock animated separately and could detach during reversals or teardown; now the host owns keyboard geometry, drives a cursor‑aware provisional pin, defers grid resize, and cancels stale animations on window loss or dismantle.

  • Host: animates dock and a presentation wrapper in one transaction behind a clip; uses notification‑derived keyboard geometry on iOS 27 and the system keyboard layout guide earlier. On reversal/interrupt, folds live wrapper translation into the render rect and the dock’s live position into its constraint. Adds cancelKeyboardTransition(resetKeyboardState:) and prepareForDismantle() to clear state.
  • Renderer: adds hostedKeyboardTransitionRenderBottom(to:) for cursor‑aware pinning, foldHostedKeyboardPresentationTranslation(_:) to merge live translation before retarget, and cancelHostedKeyboardTransition(resetKeyboardState:). finishHostedKeyboardTransition settles at the render‑aware bottom. Debug metrics and tests now sample terminalViewportDockPresentationGap; removes hostedTerminalPresentationBottom. Aligns with main by dropping removed TerminalViewportInputs fields at the snapshot call site.
  • Tests: require the viewport to track the dock within two physical pixels during rapid reversals and genuine in‑place control retargets; helper renamed to assertTerminalViewportPinnedToDock and uses doubleTap.

Migration

  • Embedders must call prepareForDismantle() on the host during teardown. SwiftUI GhosttySurfaceRepresentable now forwards this to the host.

Summary by CodeRabbit

  • Bug Fixes
    • Improved keyboard docking and undocking animations for smoother transitions and more accurate cursor-aware positioning.
    • Fixed transition cancellation and interruption handling to prevent visual gaps, stale animations, or incorrect terminal placement.
    • Improved terminal teardown behavior by safely stopping active transitions before removal.
  • Tests
    • Updated keyboard reversal and viewport alignment checks to validate the revised presentation behavior.