Files
archived-orca/config/scripts/mobile-web-app/preview/mobile-web-app-live-input-probe-route.mjs
Kelvin Amoaba 3cefb66c96 fix(mobile): send committed IME text to the terminal at commit time (#38699)
* fix(mobile): send committed IME text to the terminal at commit time

WebKit fires no input event after compositionend, so the live input
mirror kept holding committed Japanese text until the next key. Re-run
the mirror with composition ended when the field reports compositionend.

* docs(mobile): say compositionend is the commit signal on every engine
2026-11-05 22:54:05 +00:00

84 lines
2.8 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// No-RPC session has no active handle/live field, so optional ref chain skips native-write defects.
// Mount commit hook against real TextInput like attached device session; this file is probe entry, assertions live in render suite.
export const LIVE_INPUT_HANDLE = 'live-input-probe-handle'
export const LIVE_INPUT_FIELD_ID = 'live-input-probe-field'
// Match dock’s blurOnSubmit=false and ref submit binding; send real browser keystrokes, not direct hook calls.
// Clear in mount effect like session startup so unsupported DOM writes reach PageFaultBoundary as actual page fault.
export function liveInputProbeRouteSource({ bindingModule, commitModule }) {
return `import { useCallback, useEffect, useRef, useState } from 'react'
import { TextInput, View } from 'react-native'
import { useTerminalLiveInputCommit } from ${JSON.stringify(commitModule)}
import { useTerminalTextFieldSubmitBinding } from ${JSON.stringify(bindingModule)}
const HANDLE = ${JSON.stringify(LIVE_INPUT_HANDLE)}
export default function LiveInputProbeRoute() {
const liveInputRef = useRef(null)
const activeHandleRef = useRef(HANDLE)
const activeSessionTabTypeRef = useRef('terminal')
const sentRef = useRef([])
const sendLiveTerminalInputRef = useRef((handle, payload) => {
sentRef.current.push(payload)
return Promise.resolve(true)
})
const [liveInputCapture, setLiveInputCapture] = useState('')
const {
clearPendingLiveInputCommit,
handleLiveInputChange,
handleLiveInputCompositionEnd,
handleLiveInputKeyPress,
handleLiveInputSubmit
} = useTerminalLiveInputCommit({
activeHandle: HANDLE,
activeHandleRef,
activeSessionTabType: 'terminal',
activeSessionTabTypeRef,
connected: true,
liveInputRef,
sendLiveTerminalInputRef,
setLiveInputCapture
})
const onSubmitEditing = useCallback(() => {
void handleLiveInputSubmit()
}, [handleLiveInputSubmit])
const bindLiveInputField = useTerminalTextFieldSubmitBinding(
liveInputRef,
onSubmitEditing,
undefined,
handleLiveInputCompositionEnd
)
// What use-mobile-session-startup.ts does on every session mount, in the same place.
useEffect(() => {
clearPendingLiveInputCommit()
}, [clearPendingLiveInputCommit])
useEffect(() => {
globalThis.__orcaLiveInputProbe = {
sent: () => [...sentRef.current]
}
}, [])
return (
<View testID="live-input-probe">
<TextInput
ref={bindLiveInputField}
nativeID=${JSON.stringify(LIVE_INPUT_FIELD_ID)}
value={liveInputCapture}
onChange={handleLiveInputChange}
onKeyPress={handleLiveInputKeyPress}
onSubmitEditing={onSubmitEditing}
blurOnSubmit={false}
autoCapitalize="none"
autoCorrect={false}
spellCheck={false}
style={{ fontSize: 16 }}
/>
</View>
)
}
`
}