Orca is the place for working with a fleet of agents (e.g. Grok Bot, Claude Code). Run any coding agent with your own subscription. Available on desktop, mobile and remote runtime.
TypeScript adeagent-ideai-agentsautomationbotclaude-codecodexghosttygrok-bothermes-agentmobile-appmuseopenclawopencodeorchestrationpiruntimeterminalworktreesyc-backed
fix(mobile): forward iOS keys and Shift+Enter (#36120)
Kelvin Amoaba7a805621b288
diff --git a/mobile/src/session/terminal-field-submit-binding-send.test.tsx b/mobile/src/session/terminal-field-submit-binding-send.test.tsxindex 254be9734c0..75bf282405f 100644--- a/mobile/src/session/terminal-field-submit-binding-send.test.tsx+++ b/mobile/src/session/terminal-field-submit-binding-send.test.tsx@@ -2,11 +2,13 @@ import { terminalInputSend } from '../terminal/mobile-terminal-operations'// @vitest-environment happy-domimport { createElement, useEffect, useRef, type RefObject } from 'react'import { act, create, type ReactTestRenderer } from 'react-test-renderer'-import { describe, expect, it, vi } from 'vitest'+import { beforeEach, describe, expect, it, vi } from 'vitest'+import { hostOs } from '../platform/host-os'import { useMobileSessionTerminalSendActions } from './use-mobile-session-terminal-send-actions'import { useTerminalLiveInputCommit } from '../terminal/use-terminal-live-input-commit'import type { TerminalLiveInputSender } from '../terminal/terminal-live-input-sender'import type { MobileSessionTerminalWebviewModel } from './use-mobile-session-terminal-webview'+import type { TerminalModes } from '../terminal/terminal-webview-contract'// Bind once before the client/handle arrives, then dispatch after rerender to prove the frozen field listener reads current send state.const mocks = vi.hoisted(() => {@@ -31,7 +33,7 @@ vi.mock('../terminal/mobile-terminal-operations', () => ({interpret: () => true}}))-vi.mock('../platform/host-os', () => ({ hostOs: () => 'android' }))+vi.mock('../platform/host-os', () => ({ hostOs: vi.fn(() => 'android') }))// The page's own sibling, because the listener this test dispatches to only exists there.vi.mock(@@ -44,6 +46,7 @@ type Session = {readonly activeHandle: string | nullreadonly canSend: booleanreadonly draft: string+ readonly modes?: TerminalModes}const OFFLINE: Session = { client: null, activeHandle: null, canSend: false, draft: '' }@@ -75,7 +78,11 @@ function buildScope(session: Session): MobileSessionTerminalWebviewModel {connStateRef: { current: 'connected' },liveInputRef: { current: null },commandInputRef: { current: null },- ptyModesRef: { current: new Map() },+ ptyModesRef: {+ current: new Map(+ session.activeHandle && session.modes ? [[session.activeHandle, session.modes]] : []+ )+ },liveInputFocusTimerRef: { current: null },sendLiveTerminalInputRef: { current: async () => true },sessionTabActionSheetKeyboardHideSubRef: { current: null },@@ -185,8 +192,10 @@ function LiveHarness({ session }: { readonly session: Session }): null {canSend: session.canSend,sendLiveTerminalInputRef: sender})- changeLiveText = (text) =>+ changeLiveText = (text) => {+ liveField.value = textcommit.handleLiveInputChange({ nativeEvent: { text, isComposing: false } })+ }useEffect(() => {actions.bindLiveInputField(liveFieldRef)return () => actions.bindLiveInputField(null)@@ -211,6 +220,17 @@ function pressEnter(): void {)}+function pressShiftEnter(): KeyboardEvent {+ const event = new KeyboardEvent('keydown', {+ key: 'Enter',+ shiftKey: true,+ bubbles: true,+ cancelable: true+ })+ liveField.dispatchEvent(event)+ return event+}+function holdAcknowledgement(): () => void {let release = (): void => {}const pending = new Promise<void>((resolve) => {@@ -223,7 +243,11 @@ function holdAcknowledgement(): () => void {}}-describe('keyboard controls through the live pending-text queue', () => {+describe.each(['android', 'ios'] as const)('the %s live pending-text queue', (os) => {+ beforeEach(() => {+ vi.mocked(hostOs).mockReturnValue(os)+ })+it('sends the control once only after pending text is acknowledged', async () => {mocks.sent.length = 0const release = holdAcknowledgement()@@ -245,26 +269,63 @@ describe('keyboard controls through the live pending-text queue', () => {})it.each([- { key: 'Ctrl-C', press: pressControl, fieldAfter: 'hellox', expected: 'hello\x03x' },- { key: 'Enter', press: pressEnter, fieldAfter: 'x', expected: 'hello\rx' }- ])('keeps text typed right after $key behind it', async ({ press, fieldAfter, expected }) => {- mocks.sent.length = 0- const release = holdAcknowledgement()- let renderer: ReactTestRenderer | null = null- await act(async () => {- renderer = create(createElement(LiveHarness, { session: READY }))- })- await act(async () => {- changeLiveText('hello')- press()- changeLiveText(fieldAfter)- })- await act(async () => {- release()- })- expect(mocks.sent.map((send) => send.text).join('')).toBe(expected)- act(() => renderer?.unmount())- })+ { key: 'Ctrl-C', press: pressControl, fieldAfter: 'hellox', bytes: '\x03' },+ { key: 'Shift+Enter (legacy)', press: pressShiftEnter, fieldAfter: 'x', bytes: '\x1b\r' },+ {+ key: 'Shift+Enter (Kitty)',+ press: pressShiftEnter,+ fieldAfter: 'x',+ bytes: '\x1b[13;2u',+ kittyKeyboardFlags: 1+ },+ {+ key: 'Shift+Enter (modifyOtherKeys)',+ press: pressShiftEnter,+ fieldAfter: 'x',+ bytes: '\x1b[27;2;13~',+ modifyOtherKeys: 2+ },+ { key: 'Enter', press: pressEnter, fieldAfter: 'x', bytes: '\r' }+ ])(+ 'keeps text typed right after $key behind it',+ async ({ press, fieldAfter, bytes, kittyKeyboardFlags = 0, modifyOtherKeys = 0 }) => {+ mocks.sent.length = 0+ const release = holdAcknowledgement()+ let renderer: ReactTestRenderer | null = null+ let fieldAfterControl = ''+ await act(async () => {+ renderer = create(+ createElement(LiveHarness, {+ session: {+ ...READY,+ modes: {+ bracketedPasteMode: false,+ altScreen: false,+ mouseTrackingMode: 'none',+ sgrMouseMode: false,+ sgrMousePixelsMode: false,+ applicationCursorKeysMode: false,+ kittyKeyboardFlags,+ modifyOtherKeys+ }+ }+ })+ )+ })+ await act(async () => {+ changeLiveText('hello')+ press()+ fieldAfterControl = liveField.value+ changeLiveText(fieldAfter)+ })+ await act(async () => {+ release()+ })+ act(() => renderer?.unmount())+ expect(mocks.sent.map((send) => send.text).join('')).toBe(`hello${bytes}x`)+ expect(fieldAfterControl).toBe(fieldAfter === 'x' ? '' : 'hello')+ }+ )it.each([{ key: 'Ctrl-C', press: pressControl, change: 'terminal switch' },diff --git a/mobile/src/terminal/terminal-live-text-commit.ts b/mobile/src/terminal/terminal-live-text-commit.tsindex 5b64ae1090f..68e84222547 100644--- a/mobile/src/terminal/terminal-live-text-commit.ts+++ b/mobile/src/terminal/terminal-live-text-commit.ts@@ -1,5 +1,9 @@import { getTerminalLiveSpecialKeyBytes } from './terminal-live-input'import { readUtf8CodePointAt } from '../../../src/shared/utf8-byte-limits'+import {+ encodeModifyOtherKeysEnter,+ TERMINAL_KITTY_SHIFT_ENTER_INPUT+} from '../../../src/shared/terminal-modified-enter-encoding'export type TerminalLiveSpecialKeyDecision =| { readonly kind: 'ignore' }@@ -61,10 +65,14 @@ export function getTerminalLiveSpecialKeyDecision({return { kind: 'send-now', bytes }}-// An ending Return gives echoed text to the terminal and resets the field mirror.+// An ending Return or Shift+Enter gives echoed text to the terminal and resets the field mirror.// Use endsWith because custom keys can contain command plus Return; an internal Return does not end this payload.export function terminalLiveAccessoryInputEndsLine(bytes: string): boolean {- return bytes.endsWith('\r')+ return (+ bytes.endsWith('\r') ||+ bytes === TERMINAL_KITTY_SHIFT_ENTER_INPUT ||+ bytes === encodeModifyOtherKeysEnter(1, 2)+ )}export function getTerminalLiveAccessoryBytesDecision({diff --git a/mobile/src/terminal/terminal-text-field-submit-binding.web.test.ts b/mobile/src/terminal/terminal-text-field-submit-binding.web.test.tsindex 4922c9146fa..040611cf93c 100644--- a/mobile/src/terminal/terminal-text-field-submit-binding.web.test.ts+++ b/mobile/src/terminal/terminal-text-field-submit-binding.web.test.ts@@ -107,8 +107,9 @@ describe('the web sibling', () => {})})-describe('live terminal keyboard chords', () => {- function setup(accept = true) {+describe.each(['android', 'ios'] as const)('live terminal keyboard chords on %s', (os) => {+ function setup(accept = true, platform: ReturnType<typeof hostOs> = os) {+ vi.mocked(hostOs).mockReturnValueOnce(platform)const field = mountField()const onChord = vi.fn(() => accept)const unbind = bindOnWeb(asField(field), vi.fn(), onChord)@@ -134,7 +135,8 @@ describe('live terminal keyboard chords', () => {['Tab', { shiftKey: true }, '\x1b[Z'],['ArrowUp', {}, '\x1b[A'],['ArrowLeft', { ctrlKey: true }, '\x1b[1;5D'],- ['b', { altKey: true }, '\x1bb']+ ['Enter', { shiftKey: true }, '\x1b[13;2u'],+ ['ArrowLeft', { altKey: true }, '\x1b[1;3D']])('claims %s once before RNWeb can resend it', (name, options, bytes) => {const { field, onChord, key } = setup()const parentKey = vi.fn()@@ -144,9 +146,22 @@ describe('live terminal keyboard chords', () => {expect(parentKey).not.toHaveBeenCalled()})+ it.each(['b', '@', '[', ']', '{', ' '])(+ 'keeps Option-generated %j native on iOS and Alt chords on Android',+ (name) => {+ const { onChord, key } = setup()+ expect(key(name, { altKey: true }).defaultPrevented).toBe(os === 'android')+ expect(onChord.mock.calls).toEqual(os === 'android' ? [[{ bytes: `\x1b${name}` }]] : [])+ }+ )+it.each([['a', {}],['Enter', {}],+ ['Enter', { ctrlKey: true, shiftKey: true }],+ ['Enter', { altKey: true, shiftKey: true }],+ ['Enter', { shiftKey: true, isComposing: true }],+ ['Enter', { shiftKey: true, keyCode: 229 }],['Backspace', {}],['Delete', {}],['ArrowLeft', {}],@@ -183,9 +198,8 @@ describe('live terminal keyboard chords', () => {expect(onChord).not.toHaveBeenCalled()})- it.each(['ios', 'web'] as const)('leaves %s keyboard handling unchanged', (os) => {- vi.mocked(hostOs).mockReturnValueOnce(os)- const { key, onChord } = setup()+ it('leaves standalone web keyboard handling unchanged', () => {+ const { key, onChord } = setup(true, 'web')expect(key('Tab').defaultPrevented).toBe(false)expect(key('c', { ctrlKey: true }).defaultPrevented).toBe(false)expect(onChord).not.toHaveBeenCalled()diff --git a/mobile/src/terminal/terminal-text-field-submit-binding.web.ts b/mobile/src/terminal/terminal-text-field-submit-binding.web.tsindex 86177631b94..3ed01f94329 100644--- a/mobile/src/terminal/terminal-text-field-submit-binding.web.ts+++ b/mobile/src/terminal/terminal-text-field-submit-binding.web.ts@@ -28,7 +28,8 @@ export function bindTerminalTextFieldSubmit(event.preventDefault()onSubmit()}- const captureAndroidChords = hostOs() === 'android'+ const os = hostOs()+ const captureHardwareChords = os === 'android' || os === 'ios'let composing = falseconst startComposition = (): void => {composing = true@@ -41,7 +42,7 @@ export function bindTerminalTextFieldSubmit(return}if (- !captureAndroidChords ||+ !captureHardwareChords ||!onKeyChord ||event.defaultPrevented ||composing ||@@ -50,13 +51,14 @@ export function bindTerminalTextFieldSubmit(event.metaKey ||event.getModifierState('AltGraph') ||(event.ctrlKey && event.altKey) ||+ (os === 'ios' && event.altKey && event.key.length === 1) ||(event.ctrlKey && event.key === ' ')) {return}- const specialKey = getTerminalLiveSpecialKeyId(event.key)+ const specialKey = event.key === 'Enter' ? 'enter' : getTerminalLiveSpecialKeyId(event.key)if (- event.key === 'Enter' ||+ (event.key === 'Enter' && (!event.shiftKey || event.ctrlKey || event.altKey)) ||event.key === 'Backspace' ||event.key === 'Delete' ||(FIELD_CARET_KEYS.has(event.key) && !event.ctrlKey && !event.altKey && !event.shiftKey) ||