Skip to content

Send mobile chat prompts with a hardware keyboard's Return - #36426

Closed
hjhart wants to merge 4 commits into
stablyai:mainfrom
hjhart:hjhart/mobile-enter-key-submit
Closed

hjhart wants to merge 4 commits into
stablyai:mainfrom
hjhart:hjhart/mobile-enter-key-submit

Conversation

@hjhart

@hjhart hjhart commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

With a keyboard plugged into an iPhone or iPad, pressing Return in Orca's chat box started a new line instead of sending. Now Return sends, the same as on desktop. If you're typing on the on-screen keyboard, Return still starts a new line.

What Changed

Before: in the Native Chat composer and the terminal Message box, a hardware Return inserted a newline. The only way to send was tapping Send.

After: on iOS/iPadOS, Return sends while no on-screen keyboard is up, which is the case when a hardware keyboard is in use. With the on-screen keyboard showing, Return still inserts a newline.

Line breaks are still possible: press Shift+Enter to insert a newline on a hardware keyboard, the same as on desktop. This applies to the chat and terminal screens served by the desktop page bundle (the /h routes), which is where these composers render. On the fallback native field, Shift+Enter also sends, because iOS doesn't report modifier keys to React Native. Use the on-screen keyboard's Return there for a newline.

After a hardware Return send, both the chat composer and the terminal Message box keep focus so the next message can be typed straight away. The Send button still dismisses the keyboard as before.

How it works: a new useHardwareKeyboardEnterSubmit hook (mobile/src/components/composer-input/) reads the existing soft-keyboard state from useSoftKeyboard. If no soft keyboard is showing, or only one shorter than 150pt (iOS's hardware-keyboard shortcut bar), it treats Return as send. The page-bundle path measures the keyboard height at each keypress, so a composer that mounts under an already-open keyboard keeps its newline.

  • Page bundle (.web.ts, which renders the /h routes): react-native-web ignores submitBehavior, and blurOnSubmit would drop focus after each send. So the hook cancels the plain Enter keydown and sends. Shift/Alt/Ctrl/Cmd+Enter and IME composition are left alone, so Shift+Enter keeps its newline.
  • Native field (.ts): switches submitBehavior between submit and newline. iOS reports neither modifiers nor key source to React Native, so Shift+Enter also sends on this path.

Both composers only pass a submit callback when there is something to send, so an empty draft never fires a bare Enter at the terminal.

Why

React Native and WebKit report the same Return key for the on-screen and hardware keyboards. Whether a full-height soft keyboard is showing is the signal the app already tracks that tells them apart. Changing every Return to send would break newlines for people typing on the glass. A Cmd+Enter-only shortcut (#21238) doesn't reach the native field, which never sees modifiers.

Linked Issue

Fixes #14744

Visual Proof

N/A for now: this is a keyboard behavior change with no visual difference. I haven't tested it end to end yet. The /h routes come from the desktop-served page bundle, so it needs a desktop built from this branch.

Testing

  • I manually tested these changes locally. A Release build of this branch is installed on an iPhone 16 Pro Max with a hardware keyboard. The chat screen there is served by the released desktop's page bundle, so the page-bundle path still needs testing with a desktop built from this branch.
  • Automated tests added/updated: hardware-keyboard-enter-submit.web.test.ts renders a real react-native-web multiline TextInput and checks that plain Enter sends and blocks the newline, while Shift+Enter and IME-composing Enter fall through to the textarea's line break. hardware-keyboard-enter-submit.test.tsx covers the native decision logic (no keyboard → submit, shortcut bar → submit, soft keyboard → newline, mounted under an open keyboard → newline, nothing to send or not iOS → untouched). Existing composer/dock test mocks gained Keyboard.addListener / Platform, which the composer now reaches.

Ran vitest across mobile/ (all pass except mobile-agent-launch-architecture.test.ts, which also fails on the base commit, and two suites that need the root oxc-parser install) and the mobile typecheck.

AI Disclosure

Written with Claude Code (Claude Opus 5.5).

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Cross-platform: iOS/iPadOS only. Android is unchanged, since its IME caches the Enter-key config at focus, which needs separate handling.
  • Remote/mixed versions: the page-bundle half ships with desktop, the native half with the app. Either works without the other.
  • Known quirk: an iPad floating soft keyboard reports a small frame and so would send on Return. The Send button is unaffected.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Walkthrough

The change adds iOS and web hooks that submit on hardware-keyboard Enter when the soft keyboard is not active. The hooks preserve newline behavior for a visible soft keyboard, modified Enter, or IME composition as applicable to each platform. Native Chat and the session command dock use the hooks. Their send paths can retain focus, and related tests and keyboard mocks are updated.

Severity of issue fixed: Medium

Merge Risk: Low · up to 3759e

Hardware Return now saves an active chat edit rather than inserting a newline. Confirm that this edit behavior is intended; otherwise the change is mergeable with bounded owner awareness.

Pre-merge checks: Passed 3 · Failed 2

Failed Failed checks: 2 warnings

Check name Status Explanation Resolution
Linked Issues check Warning Issue [#14744] requires Cmd+Enter to send and plain Enter to insert a newline. The web hook ignores all modified Enter events, so Cmd+Enter does not send. The native hook cannot inspect modifier… Implement one of the shortcut contracts accepted by issue [#14744] on the Native Chat path. The implementation must provide the required send and newline behavior, prevent submission during native IME composition, and add tests for the nati…
Docstring Coverage Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 3 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: sending mobile chat prompts with a hardware keyboard's Return key.
Description check Passed The description is mostly complete and covers the user impact, implementation, rationale, linked issue, testing, platform scope, known limitation, and checklist. The Risk section and explicit risk lev…
Out of Scope Changes check Passed The hook, keyboard-state detection, composer integration, focus retention, send-state gating, tests, and React Native mock updates support hardware-keyboard submission. The terminal Message box uses t…
Full details: Description check

Explanation

The description is mostly complete and covers the user impact, implementation, rationale, linked issue, testing, platform scope, known limitation, and checklist. The Risk section and explicit risk level are missing, and end-to-end testing plus several validation commands remain incomplete.

Full details: Out of Scope Changes check

Explanation

The hook, keyboard-state detection, composer integration, focus retention, send-state gating, tests, and React Native mock updates support hardware-keyboard submission. The terminal Message box uses the same related composer behavior and send-path focus option. No demonstrated change is unrelated to this keyboard-submission objective.

Full details: Linked Issues check

Explanation

Issue [#14744] requires Cmd+Enter to send and plain Enter to insert a newline. The web hook ignores all modified Enter events, so Cmd+Enter does not send. The native hook cannot inspect modifiers and submits every Return when no full-height soft keyboard is visible, so plain hardware Enter cannot insert a newline and native Shift+Enter also sends. The native path also has no IME-composition guard. The implementation does reuse the existing send path, preserves empty or disabled-send gating, keeps the on-screen Send button, and adds web IME coverage.

Resolution

Implement one of the shortcut contracts accepted by issue [#14744] on the Native Chat path. The implementation must provide the required send and newline behavior, prevent submission during native IME composition, and add tests for the native modifier or composition cases.

Full details: Docstring Coverage

Explanation

Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 9 functions across 16 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

Minor · Keep the composer focused after a hardware-keyboard send. · MobileNativeChatComposer.tsx:244

mobile/src/session/native-chat/composer/MobileNativeChatComposer.tsx:244
Minor · Functional Correctness · Quick win

Keep the composer focused after a hardware-keyboard send.

On iOS, a successful hardware-keyboard Return submission uses submitBehavior: 'submit' and calls handleSend. For regular chat sends, that path still calls Keyboard.dismiss(), which removes focus. Keep dismissal for Send button submissions, but skip it for hardware-keyboard submissions.


Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f3005425-c21a-405a-a431-05009a2e7a0c
Commits

Reviewing files that changed from the base of the PR and between eb3379f and 67a5c6b.

Files selected for processing: 15
  • mobile/src/components/composer-input/hardware-keyboard-enter-submit.test.tsx
  • mobile/src/components/composer-input/hardware-keyboard-enter-submit.ts
  • mobile/src/components/composer-input/hardware-keyboard-enter-submit.web.ts
  • mobile/src/platform/soft-keyboard-shown.ts
  • mobile/src/session/MobileNativeChatView.prompt-presentation.test.ts
  • mobile/src/session/MobileSessionCommandDock.test.tsx
  • mobile/src/session/MobileSessionCommandDock.tsx
  • mobile/src/session/__mocks__/mobile-prompt-render-mocks.ts
  • mobile/src/session/mobile-closed-tab-dictation-lifetime.test.tsx
  • mobile/src/session/mobile-file-search-owner-cleanup.test.tsx
  • mobile/src/session/mobile-queued-edit-hook.test-fixture.tsx
  • mobile/src/session/native-chat/composer/MobileNativeChatComposer.structured.test.ts
  • mobile/src/session/native-chat/composer/MobileNativeChatComposer.test.ts
  • mobile/src/session/native-chat/composer/MobileNativeChatComposer.tsx
  • mobile/web-entry/web-overrides.json

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (2)

Minor · Seed the web keyboard state before enabling the… · hardware-keyboard-enter-submit.web.ts:22-36

mobile/src/components/composer-input/hardware-keyboard-enter-submit.web.ts:22-36
Minor · Functional Correctness · Quick win

Seed the web keyboard state before enabling the Enter handler.

useSoftKeyboard() initializes with height 0 and reads current keyboard metrics only in an effect. When the page-bundle composer mounts while an iOS/iPadOS soft keyboard is already open, the first render can enable the Enter handler. A plain Enter during that window calls preventDefault() and onSubmit() instead of inserting a newline.

Initialize the state with currentSoftKeyboardHeight so the handler uses the current keyboard state on its first render.

Suggested fix
-  const [keyboardLift, setKeyboardLift] = useState(0)
+  const [keyboardLift, setKeyboardLift] = useState(currentSoftKeyboardHeight)
Minor · Preserve focus for hardware sends from the command dock. · MobileSessionCommandDock.tsx:82-84

mobile/src/session/MobileSessionCommandDock.tsx:82-84
Minor · Functional Correctness · Quick win

Preserve focus for hardware sends from the command dock.

The dock’s hardware-Enter handler calls handleSend() without a focus-retention option. For an accepted, unchanged-draft send on a running agent terminal, this reaches dismissTerminalKeyboard, which blurs commandInput. Add a hardware-send-only option and keep the existing Send-button behavior unchanged.

Suggested fix
-  async function handleSend() {
+  async function handleSend(options: { keepFocus?: boolean } = {}) {
...
-      dismissKeyboardAfterAgentSend(sendOrigin, accepted && draftUnchanged)
+      if (!options.keepFocus) {
+        dismissKeyboardAfterAgentSend(sendOrigin, accepted && draftUnchanged)
+      }
-    canSendDraft ? () => void handleSend() : undefined
+    canSendDraft ? () => void handleSend({ keepFocus: true }) : undefined
Nitpick comments: 1
mobile/src/session/MobileSessionCommandDock.test.tsx: 1

30-36: Trivial · Maintainability & Code Quality · Quick win

Preserve Enter props in the dock test double.

MobileSessionCommandDock spreads enterSubmit into MessageBox, but this mock forwards only three props. The current test also renders an empty draft and checks focus only, so it cannot detect Enter forwarding or handler invocation. Forward the remaining props and add a focused non-empty-draft assertion for plain Enter invoking handleSend.

Suggested fix
     MessageBox: ({
       inputRef,
       placeholder,
-      tabIndex
+      tabIndex,
+      ...inputProps
     }: {
       inputRef: React.Ref<unknown>
       placeholder?: string
       tabIndex?: number
+      [key: string]: unknown
-    }) => React.createElement(Input, { ref: inputRef, placeholder, tabIndex })
+    }) => React.createElement(Input, { ref: inputRef, placeholder, tabIndex, ...inputProps })

This is a distinct test-coverage gap. It does not indicate a production failure or duplicate the keyboard-state logic issue.


Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c2964ba9-970b-442a-b8ba-26eb009dd018
Commits

Reviewing files that changed from the base of the PR and between 67a5c6b and 8c23cc0.

Files selected for processing: 11
  • mobile/src/components/composer-input/hardware-keyboard-enter-submit.test.tsx
  • mobile/src/components/composer-input/hardware-keyboard-enter-submit.ts
  • mobile/src/session/MobileNativeChatView.prompt-presentation.test.ts
  • mobile/src/session/MobileSessionCommandDock.test.tsx
  • mobile/src/session/__mocks__/mobile-prompt-render-mocks.ts
  • mobile/src/session/mobile-closed-tab-dictation-lifetime.test.tsx
  • mobile/src/session/mobile-file-search-owner-cleanup.test.tsx
  • mobile/src/session/mobile-queued-edit-hook.test-fixture.tsx
  • mobile/src/session/native-chat/composer/MobileNativeChatComposer.structured.test.ts
  • mobile/src/session/native-chat/composer/MobileNativeChatComposer.test.ts
  • mobile/src/session/native-chat/composer/MobileNativeChatComposer.tsx
Files skipped from review as they are similar to previous changes: 4
  • mobile/src/components/composer-input/hardware-keyboard-enter-submit.test.tsx
  • mobile/src/components/composer-input/hardware-keyboard-enter-submit.ts
  • mobile/src/session/mocks/mobile-prompt-render-mocks.ts
  • mobile/src/session/mobile-queued-edit-hook.test-fixture.tsx

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

hjhart and others added 4 commits November 2, 2026 09:28
On iPhone and iPad, Return on a connected keyboard inserted a newline in
the chat composer and the terminal Message box, so a prompt could only be
sent by tapping Send. Return now sends while no on-screen keyboard is up;
with the on-screen keyboard it still inserts a newline.

The page bundle cancels the plain Enter keydown, so Shift+Enter keeps its
newline there. The native field switches submitBehavior, because iOS
reports neither modifiers nor key source to React Native.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Skip the post-send keyboard dismissal when a hardware Return sent the
message, and seed the native keyboard state from metrics so a composer
mounted under an open soft keyboard keeps Return as a newline.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The page composer now reads the soft keyboard height when Return is
pressed, so one mounted under an open keyboard keeps its newline. A
hardware Return send from the terminal Message box keeps the field
focused, matching the chat composer.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@hjhart
hjhart force-pushed the hjhart/mobile-enter-key-submit branch from a9170a6 to 3759ead Compare November 2, 2026 17:30

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional comments: 1
mobile/src/session/native-chat/composer/MobileNativeChatComposer.tsx-270-271: 1

270-271: Major · Functional Correctness · Quick win

Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.

Keep hardware Return as a newline while editing.

If editSession is active and canSend is true, this callback sends the edit when the user presses hardware Return. The edit controls use handleSend() for Save, so Return can commit an edit that the user intended to continue. Exclude editSession from the Enter-submit callback; leave Save on its existing action. (raw.githubusercontent.com)


Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: cf5d0128-562f-4251-b0cd-310ea9b53205
Commits

Reviewing files that changed from the base of the PR and between a9170a6 and 3759ead.

Files selected for processing: 13
  • mobile/src/components/composer-input/hardware-keyboard-enter-submit.web.test.ts
  • mobile/src/components/composer-input/hardware-keyboard-enter-submit.web.ts
  • mobile/src/session/MobileSessionCommandDock.tsx
  • mobile/src/session/__mocks__/mobile-prompt-render-mocks.ts
  • mobile/src/session/mobile-closed-tab-dictation-lifetime.test.tsx
  • mobile/src/session/mobile-file-search-owner-cleanup.test.tsx
  • mobile/src/session/mobile-queued-edit-hook.test-fixture.tsx
  • mobile/src/session/native-chat/MobileNativeChatView.prompt-presentation.test.ts
  • mobile/src/session/native-chat/composer/MobileNativeChatComposer.structured.test.ts
  • mobile/src/session/native-chat/composer/MobileNativeChatComposer.test.ts
  • mobile/src/session/native-chat/composer/MobileNativeChatComposer.tsx
  • mobile/src/session/use-mobile-session-terminal-send-actions.ts
  • mobile/web-entry/web-overrides.json

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@brennanb2025

brennanb2025 commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Thank you @hjhart for this! We shipped this in #38267, which carries your key-cancellation and focus-preservation work, with you credited as co-author on the commit. iPad users can now send a chat message with Cmd+Enter from a hardware keyboard (Ctrl+Enter on Android). Closing this one since #38267 covers it. Really appreciate the contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(mobile): Support hardware keyboard shortcut to send messages in Native Chat

2 participants