Skip to content

fix(web-ui): soft keyboard Enter inserts a line break instead of sending - #1141

Merged
iruriQ merged 3 commits into
BytePioneer-AI:mainfrom
koeria:fix/mobile-enter-newline
Nov 25, 2026
Merged

iruriQ merged 3 commits into
BytePioneer-AI:mainfrom
koeria:fix/mobile-enter-newline

Conversation

@koeria

@koeria koeria commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Summary

  • On coarse-pointer (touch) inputs, a plain Enter keydown in the chat composer now falls through to Lexical's line break instead of submitting the draft, since mobile soft keyboards cannot produce Shift+Enter.
  • Desktop behavior is unchanged: Enter submits, Shift+Enter inserts a line break, Ctrl/Cmd+Enter keeps the accelerated submit, IME composition and menu arbitration guards are untouched.

fixes #1118

Mobile soft keyboards cannot send Shift+Enter, so the Enter (newline) key
submitted the draft directly. On coarse-pointer inputs, plain Enter now
falls through to Lexical's line break (the same path as Shift+Enter); the
send button remains the submit gesture, and Ctrl/Cmd+Enter keeps the
accelerated submit. fixes BytePioneer-AI#1118
@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • 修复
    • 在触屏设备上,按 Enter 可插入换行,而不会直接提交内容。
    • 按住 Ctrl 或 Meta 并按 Enter 时,仍按原有方式提交。

新增粗指针检测。粗指针设备上,未按 Ctrl 或 Meta 时,Enter 会插入换行;其他情况沿用原有提交处理。

Changes: 移动端 Enter 处理

Layer / File(s) Summary
粗指针检测与 Enter 处理
apps/web-ui/packages/client/ui-conversation/src/client/input/editor/keymap.ts
新增 isSoftKeyboardEnter() 检测粗指针。在 Enter 通过菜单仲裁后,如果检测为粗指针且未按 Ctrl 或 Meta,则返回 false,由 Lexical 插入换行。

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: bytepioneer-ai

Merge Risk: Minimal · previous review 78350

On touch devices, pressing Enter on the soft keyboard now inserts a line break instead of sending the draft. Desktop behavior is unchanged. No merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed PR 标题描述了主要变更:在触摸设备(粗指针)上,软键盘的 Enter 键插入换行而不是发送消息。raw_summary 显示 keymap.ts 新增 isSoftKeyboardEnter(),在粗指针且未按 Ctrl/Meta 时返回 false,使 Lexical 插入换行。标题与变更一致,格式符合 conventional commit 风格。
Description check Passed PR 描述与变更相关:说明触摸输入上普通 Enter 改为换行,桌面端行为保持不变,并关联 issue #1118。描述与 raw_summary 中 keymap.ts 的改动一致。
Linked Issues check Passed [#1118] 要求:手机软键盘换行键在光标处插入换行并保留草稿,提交通过发送按钮完成;桌面 Enter 发送和 Shift+Enter 换行可保持不变。

证据:审查 keymap.ts 的差异(mergeBase a02ef3b 至 head 7835030)。新增 isSoftKeyboardEnter(),它在 window.matchMedia("(pointer: coarse)"…
Out of Scope Changes check Passed 差异仅修改 keymap.ts,新增 23 行。新增的 isSoftKeyboardEnter() 辅助函数和 Enter 分支中的粗指针判断,直接对应 #1118 的换行键问题。未发现与该问题无关的改动。IME 组合、菜单仲裁和 Ctrl/Cmd+Enter 相关逻辑在差异中未被修改。
Full details: Linked Issues check

Explanation

[#1118] 要求:手机软键盘换行键在光标处插入换行并保留草稿,提交通过发送按钮完成;桌面 Enter 发送和 Shift+Enter 换行可保持不变。

证据:审查 keymap.ts 的差异(mergeBase a02ef3b 至 head 7835030)。新增 isSoftKeyboardEnter(),它在 window.matchMedia("(pointer: coarse)") 为真时返回 true。在 Enter 提交分支中,若该条件成立且 ctrlKey、metaKey 均不为 true,代码返回 false,交由 Lexical 执行与 Shift+Enter 相同的换行路径。该分支位于 preventDefault 与 canSubmit 检查之前,因此不会提交草稿。

满足情况:粗指针输入下的普通 Enter 插入换行;发送按钮仍是提交方式;桌面(细指针)行为未改变;Ctrl/Cmd+Enter 仍提交。

剩余不确定点:差异中未包含自动化测试。该 issue 未明确要求测试,因此不作为未满足的编码要求。粗指针且带硬件键盘的设备(例如平板)上,普通 Enter 也不再提交,这是设计上的取舍,issue 未对其作出要求。

  • 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

@iruriQ
iruriQ merged commit d1e9ca5 into BytePioneer-AI:main Nov 25, 2026
@iruriQ

iruriQ commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

Thanks for fixing #1118! Before merging into main, we formatted keymap.ts with Prettier, added focused Lexical keymap-enter.test.ts coverage (8/8 tests across coarse/fine pointers, Ctrl/Cmd+Enter, IME, and menu arbitration), and verified coarse-pointer multiline Enter + fine-pointer direct Enter in an isolated Web run.

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.

[Bug] 手机 Web 聊天框按软键盘换行键会直接发送消息

3 participants