Skip to content

fix(mobile): send Native Chat on hardware Enter - #14782

Closed
innocarpe wants to merge 3 commits into
stablyai:mainfrom
innocarpe:fix/mobile-native-chat-hardware-enter
Closed

innocarpe wants to merge 3 commits into
stablyai:mainfrom
innocarpe:fix/mobile-native-chat-hardware-enter

Conversation

@innocarpe

Copy link
Copy Markdown
Contributor

Description

Hardware Enter/Return in mobile Native Chat now sends the message.
Shift+Enter still inserts a newline.

Focused fix

  • In scope: hardware Enter → existing handleSend().
  • Out of scope: removing multiline.

Preserves

  • Soft-keyboard multiline and IME composition are unchanged.

Evidence

  • Test: cd mobile && pnpm exec vitest run src/session/MobileNativeChatComposer.test.ts
  • 18 passed.

Fixes #14744

@coderabbitai

coderabbitai Bot commented Aug 15, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Important

Review skipped

We couldn't safely recover the incremental review. No full review was started, and the last reviewed checkpoint was preserved. Retry later, or explicitly request a full review by commenting @coderabbitai full review.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
Walkthrough

Added hardware Enter handling to MobileNativeChatComposer. Eligible Enter presses use the existing send path. Shift+Enter preserves newlines, and IME-composing Enter does not submit. The composer suppresses the trailing newline emitted by multiline TextInput after submission. Tests cover these behaviors, whitespace-only drafts, and blocked newline updates.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the fix and testing, but it omits most required template sections, including ELI5, Why, Visual Proof, Review, and Checklist. Complete the required template sections and provide visual proof or state N/A with a reason.
Linked Issues check ⚠️ Warning The implementation matches the issue's alternative behavior but not its acceptance criteria, which require Cmd+Enter to send and plain Enter to insert a newline. Implement Cmd+Enter submission while preserving plain Enter as newline, or update the issue acceptance criteria if the alternative behavior is intended.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the mobile Native Chat hardware Enter submission fix.
Out of Scope Changes check ✅ Passed The code and tests remain focused on hardware Enter handling, multiline behavior, IME composition, and existing send-state protections.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@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: 2

🧹 Nitpick comments (2)
mobile/src/session/MobileNativeChatComposer.test.ts (2)

140-155: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Cover the disabled state separately from whitespace-only input.

This test covers only a whitespace draft. The PR objective also requires hardware Enter to remain blocked when disabled is true. Add a non-empty draft with disabled: true and assert that onSend is not called.

Suggested test addition
+  it('does not send hardware Enter when disabled', async () => {
+    const onSend = vi.fn().mockResolvedValue(true)
+    await act(async () => {
+      renderer = create(
+        createElement(MobileNativeChatComposer, {
+          value: 'hello',
+          onChangeText: vi.fn(),
+          onSend,
+          disabled: true
+        })
+      )
+    })
+
+    await act(async () => composerInput().props.onKeyPress?.({ nativeEvent: { key: 'Enter' } }))
+
+    expect(onSend).not.toHaveBeenCalled()
+  })

80-138: 📐 Maintainability & Code Quality | 🔵 Trivial | 🏗️ Heavy lift

Add native coverage for TextInput key delivery.

These tests run with a mocked TextInput and invoke onKeyPress directly. They cover handleKeyPress, but not the documented React Native event contract. Add native or adapter-level coverage for Android hardware Enter, soft Return, Shift+Enter, and IME composition. React Native 0.83 documents only nativeEvent.key and does not dispatch Android hardware-keyboard input through onKeyPress.

Source: MCP tools


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 84832541-9a1b-41b7-9fed-5d983761d7d2

📥 Commits

Reviewing files that changed from the base of the PR and between c0a7754 and 294042a3cc217caa28bb987ff5af5d691b8f8697.

📒 Files selected for processing (2)
  • mobile/src/session/MobileNativeChatComposer.test.ts
  • mobile/src/session/MobileNativeChatComposer.tsx

@innocarpe
innocarpe force-pushed the fix/mobile-native-chat-hardware-enter branch from 294042a to 86e29a4 Compare August 15, 2026 13:36
@innocarpe

Copy link
Copy Markdown
Contributor Author

Follow-up for the CodeRabbit notes:

  • Hardware Enter still sends through the existing handleSend path.
  • The multiline TextInput newline is now suppressed at the active selection (value.slice(0, start) + '\n' + value.slice(end)), not only value + '\n'.

Out of scope: a native hardware-keyboard / IME adapter. React Native 0.83 TextInput.onKeyPress only documents nativeEvent.key. Optional shiftKey / isComposing remain defensive when the native event provides them.

Validation: mobile/src/session/MobileNativeChatComposer.test.ts 19 passed, including the mid-caret newline case.

@greptile-apps

greptile-apps Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] Adds hardware Enter key handling to the chat composer.

The native event handling should be corrected before merge because Shift+Enter or IME confirmation can submit text when the platform does not provide the assumed event fields.

Findings

  1. P1 Native modifiers are not preserved ▶

Summary

The PR routes Enter key events from the mobile native-chat multiline composer through the existing send path while attempting to preserve Shift+Enter and IME behavior.

  • Adds Enter-key submission and suppression of the multiline newline generated after submission.
  • Adds focused tests for Enter, Shift+Enter, IME composition, disabled sending, and newline suppression.

Reviews (1) · Last reviewed commit: "test(mobile): type hardware Enter helper..." · Reviewed by Greptile

Comment on lines +266 to +271
const handleKeyPress = (event: {
nativeEvent: { key: string; shiftKey?: boolean; isComposing?: boolean }
}): void => {
const { key, shiftKey, isComposing } = event.nativeEvent
// Why: IME Enter confirms composition; submitting would send a partial draft.
if (key !== 'Enter' || shiftKey || isComposing || !canSend) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Native modifiers are not preserved

When native onKeyPress omits the optional shiftKey or isComposing fields, the new handler treats Shift+Enter or IME-confirming Enter as an ordinary Enter and calls handleSend(), causing multiline or partially composed text to be submitted unexpectedly.

Knowledge Base Used: Mobile sessions and terminal interaction

Hardware Enter/Return in the mobile Native Chat composer now calls the
existing handleSend() path. Multiline stays on so Shift+Enter and the
soft-keyboard return can still insert a newline. IME composition Enter
does not submit.

Fixes stablyai#14744
Hardware Enter still sends through handleSend. The follow-up TextInput
newline is suppressed at the active selection, not only at value + \\n.
The composer now requires a send surface, and the selection callback has to
stay visible on the input helper after the field moved.
@innocarpe
innocarpe force-pushed the fix/mobile-native-chat-hardware-enter branch from 6cdd44c to a22952f Compare November 2, 2026 09:19
@nwparker

nwparker commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Closing as superseded — the linked issue (#14744) has been resolved on main by #38267 (776917931b). Thanks for the contribution!

@nwparker nwparker closed this Nov 5, 2026
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

4 participants