@devries-cameron20 / t3code-1 / commits / 71f251d4cf
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(mobile): iOS terminal accepts Chinese, Japanese and Korean input (#30546)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Nov 5, 2026 at 16:48 UTC 71f251d4cf81f55167a97d59dc561d418140326c
6 files changed +80 -20
apps/mobile/modules/t3-terminal/android/src/main/java/expo/modules/t3terminal/T3TerminalModule.kt
+3
@@ -19,6 +19,9 @@ class T3TerminalModule : Module() {
19 view.writeOutput(data, reset)
20 }
21
22 + // The Android input field already clears after every change.
23 + AsyncFunction("resetInput") { _: T3TerminalView -> }
24 +
25 Prop("terminalKey") { view: T3TerminalView, terminalKey: String ->
26 view.terminalKey = terminalKey
27 }
apps/mobile/modules/t3-terminal/ios/T3TerminalModule.swift
+4
@@ -16,6 +16,10 @@ public class T3TerminalModule: Module {
16 view.writeOutput(data, reset: reset)
17 }
18
19 + AsyncFunction("resetInput") { (view: T3TerminalView) in
20 + view.resetInputField()
21 + }
22 +
23 Prop("terminalKey") { (view: T3TerminalView, terminalKey: String) in
24 view.terminalKey = terminalKey
25 }
apps/mobile/modules/t3-terminal/ios/T3TerminalView.swift
+47 -16
@@ -133,12 +133,16 @@ private final class TerminalInputField: UITextField {
133 action: #selector(handleHardwareKeyCommand(_:))
134 )
135
136 + // While an IME composes, arrows, Tab and Escape pick or cancel candidates instead.
137 override var keyCommands: [UIKeyCommand]? {
137 - Self.hardwareKeyCommands
138 + markedTextRange == nil ? Self.hardwareKeyCommands : nil
139 }
140
141 override func deleteBackward() {
141 - onDeleteBackward?()
142 + // Backspace edits marked or committed field text first; the field diff sends that DEL.
143 + if markedTextRange == nil, !hasText {
144 + onDeleteBackward?()
145 + }
146 super.deleteBackward()
147 }
148
@@ -198,6 +202,7 @@ public final class T3TerminalView: ExpoView, UITextFieldDelegate {
202 private var lastAppliedBuffer = ""
203 private var streamedOutput: TerminalOutputBuffer?
204 private var pendingVerticalScrollPoints: CGFloat = 0
205 + private var sentInput = ""
206 private var app: ghostty_app_t?
207 private var surface: ghostty_surface_t?
208 private var isCreatingSurface = false
@@ -348,19 +353,22 @@ public final class T3TerminalView: ExpoView, UITextFieldDelegate {
353 inputField.spellCheckingType = .no
354 inputField.smartDashesType = .no
355 inputField.smartQuotesType = .no
356 + inputField.smartInsertDeleteType = .no
357 inputField.returnKeyType = .send
352 - inputField.keyboardType = .asciiCapable
358 + inputField.keyboardType = .default
359 inputField.enablesReturnKeyAutomatically = false
360 inputField.translatesAutoresizingMaskIntoConstraints = false
361 inputField.alpha = 0.02
362 inputField.isAccessibilityElement = false
363 inputField.accessibilityElementsHidden = true
364 inputField.addTarget(self, action: #selector(handleInputEditingDidBegin), for: .editingDidBegin)
365 + inputField.addTarget(self, action: #selector(handleInputEditingChanged), for: .editingChanged)
366 inputField.onDeleteBackward = { [weak self] in
367 self?.emitInput("\u{7F}")
368 }
369 inputField.onInsert = { [weak self] data in
370 self?.emitInput(data)
371 + self?.resetInputField()
372 }
373
374 focusTapGesture.addTarget(self, action: #selector(handleViewportTap))
@@ -417,21 +425,11 @@ public final class T3TerminalView: ExpoView, UITextFieldDelegate {
425 }
426 }
427
420 - public func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
421 - if !string.isEmpty {
422 - // Some software keyboards deliver Return through this delegate instead of
423 - // textFieldShouldReturn, so normalize that path too.
424 - emitInput(TerminalInputSequence.normalizingReturn(string))
425 - return false
426 - }
427 -
428 - emitInput("\u{7F}")
429 - return false
430 - }
431 -
428 public func textFieldShouldReturn(_ textField: UITextField) -> Bool {
429 + // Return during a composition commits it; that is not Enter.
430 + guard textField.markedTextRange == nil else { return false }
431 emitInput(TerminalInputSequence.carriageReturn)
434 - textField.text = ""
432 + resetInputField()
433 return false
434 }
435
@@ -480,11 +478,44 @@ public final class T3TerminalView: ExpoView, UITextFieldDelegate {
478 }
479 }
480
481 + // Korean keyboards build a syllable by replacing the committed character before the cursor,
482 + // so the field keeps what was sent and each change goes out as DELs plus the new suffix.
483 + // Scalars, not Characters: a Thai or Indic mark joins the previous grapheme, and resending
484 + // that grapheme after one DEL would leave its base twice in a code-point line editor.
485 + @objc
486 + private func handleInputEditingChanged() {
487 + guard inputField.markedTextRange == nil else { return }
488 + let text = inputField.text ?? ""
489 + let fieldScalars = text.unicodeScalars
490 + let sentScalars = sentInput.unicodeScalars
491 + let commonCount = zip(fieldScalars, sentScalars).prefix { $0.0 == $0.1 }.count
492 + let unsent = String(String.UnicodeScalarView(sentScalars.dropFirst(commonCount)))
493 + let added = String(String.UnicodeScalarView(fieldScalars.dropFirst(commonCount)))
494 + // Some software keyboards deliver Return as an inserted newline instead of textFieldShouldReturn.
495 + emitInput(String(repeating: "\u{7F}", count: unsent.count) + TerminalInputSequence.normalizingReturn(added))
496 + sentInput = text
497 + // A Hangul syllable never spans whitespace; past the cap, keep the last character to compose onto.
498 + if text.last?.isWhitespace == true {
499 + resetInputField()
500 + } else if text.count > 64 {
501 + let last = String(text.suffix(1))
502 + inputField.text = last
503 + sentInput = last
504 + }
505 + }
506 +
507 @objc
508 private func handleInputEditingDidBegin() {
509 + // A composition abandoned by losing focus must not reach the PTY with the next keystroke.
510 + resetInputField()
511 textInputModeDidChange()
512 }
513
514 + func resetInputField() {
515 + inputField.text = ""
516 + sentInput = ""
517 + }
518 +
519 private func createSurfaceIfPossible() {
520 guard surface == nil, app == nil, !isCreatingSurface, !surfaceCreationFailed else { return }
521 guard terminalViewport.bounds.width > 0, terminalViewport.bounds.height > 0 else { return }
apps/mobile/src/features/terminal/NativeTerminalSurface.tsx
+21 -4
@@ -39,6 +39,8 @@ interface TerminalResizeEvent {
39 export interface TerminalSurfaceHandle {
40 /** The text fallback focuses its input; the native view follows `keyboardFocusRequest`. */
41 readonly focusKeyboard: () => void;
42 + /** Drops the native field's IME context after input that bypassed it. */
43 + readonly resetInput: () => void;
44 }
45
46 interface TerminalSurfaceProps extends ViewProps {
@@ -102,6 +104,7 @@ const FallbackTerminalSurface = memo(function FallbackTerminalSurface({
104 inputRef.current?.blur();
105 requestAnimationFrame(() => inputRef.current?.focus());
106 },
107 + resetInput: () => {},
108 }));
109
110 return (
@@ -199,14 +202,18 @@ export const TerminalSurface = memo(function TerminalSurface(props: TerminalSurf
202 return <ReadyTerminalSurface key={props.terminalKey} {...props} buffer={buffer} />;
203 });
204
202 -const ReadyTerminalSurface = memo(function ReadyTerminalSurface(props: ReadyTerminalSurfaceProps) {
205 +const ReadyTerminalSurface = memo(function ReadyTerminalSurface({
206 + ref,
207 + grid,
208 + ...props
209 +}: ReadyTerminalSurfaceProps) {
210 const fontSize = props.fontSize ?? MOBILE_TYPOGRAPHY.label.fontSize;
211 const { themeAppearance, themeId } = useAppearancePreferences();
212 const theme = props.theme ?? getMobileTerminalTheme(themeId, themeAppearance);
213 const { onInput, onResize } = props;
214 const NativeTerminalSurfaceView = resolveNativeTerminalSurfaceView();
208 - const gridCols = props.grid?.cols;
209 - const gridRows = props.grid?.rows;
215 + const gridCols = grid?.cols;
216 + const gridRows = grid?.rows;
217 const sharedGrid = useMemo(
218 () => (gridCols !== undefined && gridRows !== undefined ? [gridCols, gridRows] : []),
219 [gridCols, gridRows],
@@ -216,6 +223,16 @@ const ReadyTerminalSurface = memo(function ReadyTerminalSurface(props: ReadyTerm
223 const writerRef = useRef<ReturnType<typeof createTerminalOutputWriter> | null>(null);
224 const [nativeReady, setNativeReady] = useState(false);
225
226 + // The fallback surface binds the same ref itself.
227 + useImperativeHandle(NativeTerminalSurfaceView ? ref : undefined, () => ({
228 + focusKeyboard: () => {},
229 + resetInput: () => {
230 + void nativeRef.current?.resetInput?.().catch((error: unknown) => {
231 + console.error("Terminal input reset failed", error);
232 + });
233 + },
234 + }));
235 +
236 // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- creates the output writer for the native terminal view once it is ready and disposes it on cleanup
237 useEffect(() => {
238 const view = nativeRef.current;
@@ -279,5 +296,5 @@ const ReadyTerminalSurface = memo(function ReadyTerminalSurface(props: ReadyTerm
296 );
297 }
298
282 - return <FallbackTerminalSurface {...props} fontSize={fontSize} theme={theme} />;
299 + return <FallbackTerminalSurface {...props} ref={ref} fontSize={fontSize} theme={theme} />;
300 });
apps/mobile/src/features/terminal/ThreadTerminalRouteScreen.tsx
+3
@@ -751,6 +751,9 @@ function ThreadTerminal(props: {
751 return;
752 }
753
754 + // Toolbar input bypasses the native field, so a syllable it holds must not be recomposed.
755 + surfaceRef.current?.resetInput();
756 +
757 if (action.kind === "clear") {
758 handleClearTerminal();
759 return;
apps/mobile/src/features/terminal/nativeTerminalModule.ts
+2
@@ -44,6 +44,8 @@ export interface NativeTerminalSurfaceProps extends ViewProps {
44
45 export interface NativeTerminalSurfaceHandle {
46 readonly writeOutput: (data: string, reset: boolean) => Promise<void>;
47 + /** Absent on native builds that predate it. */
48 + readonly resetInput?: () => Promise<void>;
49 }
50
51 let cachedNativeTerminalSurfaceView: ComponentType<NativeTerminalSurfaceProps> | undefined;