Fix iOS keyboard focus ownership after photo picker

Merged
AZ
4mo ago
+1360-755

Fixes first-tap keyboard recovery and bottom-dock coordination in workspace detail.

The terminal, composer, photo picker, and scene lifecycle now share one input-session reducer. Ordinary terminal taps focus synchronously before asynchronous artifact/click work. UIKit responder results remain the source of actual ownership.

Tests:

  • 11 TerminalInputSessionReducer tests
  • iOS Simulator SwiftPM builds for CmuxMobileTerminal and CmuxMobileShellUI
  • Terminal dock transition and letterbox geometry suites
  • Focused XCUITests for terminal and composer recovery after picker cancellation

Hosted XCUITests are currently blocked before execution by the unrelated WorkspaceListTableCoordinatorDropTests compile error already present on main.


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

Fixes iOS keyboard focus after the Photos picker by centralizing terminal/composer input ownership so the first tap reliably restores the keyboard and keeps the bottom dock aligned using UIKit’s keyboard guide. Also restricts foreground-only recovery by requiring a live client for secondary aggregation and skipping it during redial/validation.

  • Bug Fixes

    • First-tap keyboard recovery after cancelling PhotosPicker for both terminal and composer; no stale owner after dismissal.
    • Dock pinned via UIKit’s keyboard guide; deterministic align/letterbox and full-height return when the keyboard hides.
    • Foreground recovery: secondary Mac aggregation runs only when connected with a live client and not redialing/validating.
  • Refactors

    • Centralized input ownership with TerminalInputSessionReducer and TerminalInputSessionCoordinator; UIKit/SwiftUI first-responder changes flow through one owner.
    • Added GhosttySurfaceViewDelegate.inputPolicyForTap… and TerminalInputTapIntent; immediate focus only with a fresh artifact snapshot, otherwise deferred until classification.
    • TerminalComposerView routes focus and PhotosPicker lifecycle through the input session; SwiftUI @FocusState mirrors UIKit; TerminalInputTextView reports first-responder changes.
    • Cached visible-text snapshot now returns columns and generation for artifact hit testing; async clicks are invalidated by a click generation counter.
    • Removed custom dock transition planner and tests (TerminalDockKeyboardTransition*, TerminalKeyboardHeightAnimation).

Summary by CodeRabbit

  • New Features

    • Improved terminal and composer focus coordination across scene changes, modal presentations, and keyboard interactions.
    • Added more reliable handling for terminal taps on clickable artifacts.
    • Improved photo-picker presentation, dismissal, and focus restoration behavior.
    • Added richer accessibility diagnostics for input ownership and keyboard state.
  • Bug Fixes

    • Fixed stale focus and keyboard states after photo-picker cancellation.
    • Improved focus recovery after terminal and composer handoffs.
    • Prevented disconnected recovery attempts from triggering duplicate background reconnect activity.
  • Tests

    • Expanded coverage for focus transitions, artifact taps, modal cancellation, recovery, and keyboard restoration.