Text selection

On iOS, a single-finger long press requests host text selection. GhosttyKit sends a viewport snapshot, a suggested UTF-16 range, and the source point for anchoring UI.

Flow

  1. The user long-presses the terminal view for 0.5 seconds.
  2. The view asks Ghostty for a viewport text snapshot and a quicklook word anchor.
  3. TerminalTextSelectionRequest arrives at the delegate.
  4. The host presents its own UI, commonly a UITextView sheet or popover.

Delegate

final class SelectionCoordinator: TerminalSurfaceTextSelectionRequestDelegate {
    func terminalDidRequestTextSelection(_ request: TerminalTextSelectionRequest) {
        let textView = UITextView()
        textView.text = request.text

        if let range = request.anchorRange {
            textView.selectedRange = range
        } else {
            textView.selectAll(nil)
        }

        presentSelectionUI(textView, sourcePoint: request.sourcePoint)
    }
}

Ranges

anchorRange uses UTF-16 units so it can be assigned directly to UITextView.selectedRange. Duplicate words on the same row are disambiguated with the long-press x coordinate and Ghostty cell metrics.

The MVP targets the in-memory backend and viewport text. Full scrollback selection belongs in a host selection surface.