Skip to content

feat(ai): add enterToSubmit prop to ChatComposer#4

Open
b-client-vm wants to merge 2 commits into
spacedriveapp:mainfrom
b-client-vm:feat/chat-composer-enter-prop
Open

feat(ai): add enterToSubmit prop to ChatComposer#4
b-client-vm wants to merge 2 commits into
spacedriveapp:mainfrom
b-client-vm:feat/chat-composer-enter-prop

Conversation

@b-client-vm
Copy link
Copy Markdown

@b-client-vm b-client-vm commented May 13, 2026

Summary

  • Adds an optional enterToSubmit prop (default true) to <ChatComposer> in @spacedrive/ai.
  • When true: Enter sends, Shift+Enter inserts a newline (current behavior — backward compatible).
  • When false: Enter inserts a newline; ⌘/Ctrl/Alt+Enter sends.
  • Also guards the keydown handler against IME composition events (event.nativeEvent.isComposing) so dead-keys / CJK composition no longer accidentally submit.

Motivation

Some users frequently send multi-line messages and want Enter to insert newlines, with a modifier+Enter to send. Exposing this as a prop lets consumers (spacebot, etc.) wire it to a user preference.

Companion PR

Consumed by spacedriveapp/spacebot#600 (closes spacedriveapp/spacebot#599).
This PR must merge and a new @spacedrive/ai release be published before that one can land.

Test plan

  • No prop passed → existing behavior unchanged (Enter sends, Shift+Enter newline)
  • enterToSubmit={false} → Enter inserts newline, ⌘/Ctrl/Alt+Enter sends
  • IME composition (e.g. typing Japanese/Chinese) — pressing Enter to commit a candidate no longer submits

Lets consumers opt into modifier-based send (Enter for newline,
Cmd/Ctrl/Alt+Enter to send) instead of Enter-to-send. Defaults to
true so existing usage is unchanged. Also guards against IME
composition events.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 13, 2026

Review Change Stack

Warning

Rate limit exceeded

@b-client-vm has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 47 minutes and 10 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 89029467-6046-43db-97be-115c8e24f5db

📥 Commits

Reviewing files that changed from the base of the PR and between 2e91fbf and 17392f6.

📒 Files selected for processing (1)
  • packages/ai/src/ChatComposer.tsx

Walkthrough

The ChatComposer component now accepts an enterToSubmit prop that controls Enter key behavior. When true (default), Enter submits and Shift+Enter inserts a newline. When false, Enter inserts a newline unless a modifier key is held, then submits. The textarea handler was refactored to use a dedicated handleKeyDown function.

Changes

Enter Key Submission Control

Layer / File(s) Summary
Enter key submission behavior
packages/ai/src/ChatComposer.tsx
KeyboardEvent type is imported, ChatComposerProps interface gains the optional enterToSubmit boolean prop with documentation, handleKeyDown function encapsulates conditional Enter key logic with support for both submit-on-Enter and submit-on-modifier modes, and textarea onKeyDown is wired to the new handler function.

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely describes the main change: adding an enterToSubmit prop to ChatComposer.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The pull request description clearly explains the changes: adding an enterToSubmit prop to control Enter key behavior, with detailed motivation, companion PR context, and a comprehensive test plan.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/ai/src/ChatComposer.tsx`:
- Around line 74-85: In handleKeyDown, avoid calling onSend when sending is
disabled by respecting the existing canSend guard (so keyboard behavior matches
the Send button); before calling onSend() (both in the enterToSubmit branch and
the modifier-keys branch) check if canSend is true (or compute same guard:
!isSending && draft.trim().length > 0) and return early if not, and only call
event.preventDefault() when you will actually invoke onSend; locate
handleKeyDown and apply the guard there.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3233877e-567a-48e6-b223-1d2b977b7feb

📥 Commits

Reviewing files that changed from the base of the PR and between a48b170 and 2e91fbf.

📒 Files selected for processing (1)
  • packages/ai/src/ChatComposer.tsx

Comment thread packages/ai/src/ChatComposer.tsx
Match the Send button's enabled state: keyboard-triggered send is now
suppressed when the draft is empty or isSending=true. In Enter-to-send
mode, Enter still preventDefaults so it never inserts a newline; in
modifier-to-send mode, we only preventDefault when we'll actually send.

Addresses CodeRabbit review on spacedriveapp#4.
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.

Chat input: configurable Enter behavior + auto-expanding textarea

2 participants