Files
orca/mobile/src/session/MobileSessionCommandDock.tsx
T
Kelvin Amoaba 854928969e feat(mobile): add Shift, Ctrl and Alt latches and opt-in agent keys to the terminal key row (#38776)
* feat(mobile): smart rail keys for the terminal agent's state, with Shift/Ctrl/Alt latches

* fix(mobile): cancel key presses only when the key row really moves

* fix(mobile): keep Smart rail on through Reset Defaults and finish two-write keys

* fix(mobile): only a finger scrolling the key row cancels its presses

* fix(mobile): hold the smart group until the tap's press lands, and drop clicks on keys that moved

* refactor(mobile): simplify the smart rail touch hook and layout read

* chore(mobile): allowlist the Shift, Ctrl and Alt key names

* feat(mobile): Codex async question keys on the smart rail

* fix(mobile): drop the Codex Always key, whose key differs by approval

Codex binds "don't ask again" to p for a command-prefix rule and a for session and file approvals (0.136 through 0.166). The permission hook doesn't say which one is on screen.
2026-11-09 21:19:11 +00:00

153 lines
5.7 KiB
TypeScript

import { useRef, type ReactNode } from 'react'
import { View } from 'react-native'
import { Keyboard as KeyboardIcon } from 'lucide-react-native'
import { composerInputStyles as inputStyles } from '../components/composer-input/composer-input-styles'
import { TextField } from '../components/composer-input/TextField'
import { MobileTerminalLiveInputStatus } from '../terminal/session/MobileTerminalLiveInputStatus'
import { MobileTerminalInputActions } from '../terminal/session/MobileTerminalInputActions'
import { MobileSessionAccessoryKeys } from '../terminal/session/MobileSessionAccessoryKeys'
import { MobileTerminalMoreKeysSheet } from '../terminal/session/MobileTerminalMoreKeysSheet'
import { sessionCommandDockShown } from './mobile-session-command-dock-shown'
import { useSessionTerminalKeyRail } from '../terminal/session/use-session-terminal-key-rail'
import { terminalDockStyles as dockStyles } from '../terminal/session/terminal-dock-styles'
import { colors } from '../theme/mobile-theme'
import { useMobileColorScheme } from '../theme/use-mobile-color-scheme'
import { useMobileTranslation } from '../i18n/use-mobile-translation'
import type { MobileSessionController } from './use-mobile-session-controller'
import { useMobileSessionKeyboardLift } from '../terminal/session/use-mobile-session-keyboard-lift'
import { useLiveInputCaptureText } from '../terminal/session/live-input-capture'
// The key row above one live field: every letter typed goes straight to the terminal, shell or agent.
export function MobileSessionCommandDock({ controller }: { controller: MobileSessionController }) {
useMobileColorScheme()
const rail = useSessionTerminalKeyRail(controller)
const keyboardLift = useMobileSessionKeyboardLift(controller.dockBottomInset)
// The field's ✕, which the held mic may be released over.
const dictationCancelRef = useRef<View>(null)
const {
insets,
dictationMode,
dictationEnabled,
canSend,
dictation,
liveDictationText,
cancelDictation,
handleDictationToggle,
handleDictationPressIn,
handleDictationPressOut,
isAttaching,
attachImage
} = controller
if (!sessionCommandDockShown(controller)) {
return null
}
return (
<View
style={[
dockStyles.dock,
{ paddingBottom: insets.bottom, transform: [{ translateY: -keyboardLift }] }
]}
>
{rail.keysInRail ? (
<MobileTerminalMoreKeysSheet
controller={controller}
visible={rail.moreKeysVisible}
onClose={rail.closeMoreKeys}
/>
) : (
<MobileSessionAccessoryKeys controller={controller} />
)}
<View style={dockStyles.inputBar}>
<LiveInputField
controller={controller}
trailing={
<MobileTerminalLiveInputStatus
dictation={dictation}
cancelRef={dictationCancelRef}
dictationMode={dictationMode}
heard={liveDictationText}
isAttaching={isAttaching}
/>
}
/>
<MobileTerminalInputActions
canSend={canSend}
isAttaching={isAttaching}
dictation={dictation}
dictationMode={dictationMode}
dictationEnabled={dictationEnabled}
buttonStyle={inputStyles.controlButton}
dictationCancelRef={dictationCancelRef}
disabledButtonStyle={inputStyles.disabled}
onAttachImage={() => void attachImage('library')}
onAttachFile={() => void attachImage('files')}
onDictationToggle={handleDictationToggle}
onDictationPressIn={handleDictationPressIn}
onDictationPressOut={handleDictationPressOut}
onDictationCancel={cancelDictation}
/>
</View>
</View>
)
}
// Only this field reads the typed text, so a keystroke re-renders it and not the dock or session.
function LiveInputField({
controller,
trailing
}: {
controller: MobileSessionController
trailing: ReactNode
}) {
const t = useMobileTranslation()
const {
liveInputCapture,
handleLiveInputChange,
handleLiveInputKeyPress,
bindLiveInputField,
liveInputRef,
submitLiveInput,
canSend,
dockKeys
} = controller
const text = useLiveInputCaptureText(liveInputCapture)
return (
<TextField
inputRef={bindLiveInputField}
monospace
style={dockStyles.liveField}
leading={<KeyboardIcon size={17} color={colors.textSecondary} strokeWidth={2} />}
label={t('session.terminalLiveInputStatus.liveInput', 'Live input')}
trailing={trailing}
value={text}
onChange={(event) => {
// A held Shift, Ctrl or Alt on the key row or the Duo rail turns the next typed letter into a combo.
if (!dockKeys.interceptTypedCharacter(text, event.nativeEvent.text, liveInputRef)) {
handleLiveInputChange(event)
}
}}
onKeyPress={handleLiveInputKeyPress}
onSubmitEditing={submitLiveInput}
placeholder={t('session.commandDock.tapToShowKeyboard', 'Tap to show keyboard')}
accessibilityLabel={t('session.commandDock.liveInputLabel', 'Live terminal input')}
accessibilityHint={t(
'session.commandDock.liveInputHint',
'Typed text is sent directly to the active terminal'
)}
showSoftInputOnFocus
autoCapitalize="none"
autoCorrect={false}
spellCheck={false}
smartInsertDelete={false}
// Why: iOS textContentType overrides autoComplete and can narrow the keyboard; keep IME switching available.
autoComplete="off"
// Why: ASCII-only keyboard types hide non-Latin IMEs.
keyboardType="default"
returnKeyType="default"
blurOnSubmit={false}
editable={canSend}
importantForAutofill="no"
/>
)
}