Skip to content

fix: ignore the Enter that confirms an IME composition when selecting a mention#325

Open
greymoth-jp wants to merge 1 commit into
react-component:masterfrom
greymoth-jp:fix/ime-composition-enter
Open

fix: ignore the Enter that confirms an IME composition when selecting a mention#325
greymoth-jp wants to merge 1 commit into
react-component:masterfrom
greymoth-jp:fix/ime-composition-enter

Conversation

@greymoth-jp

@greymoth-jp greymoth-jp commented Jun 29, 2026

Copy link
Copy Markdown

When the suggestion dropdown is open and an option is highlighted, pressing Enter selects it. On browsers that report the IME commit keydown as which === ENTER while isComposing is true (Safari is the common case), the Enter that only confirms an IME composition gets treated as a selection. So while typing a Chinese or Japanese name after the trigger, confirming the conversion replaces the composed text with the highlighted option instead of just committing what was typed.

This guards the Enter branch in onInternalKeyDown with event.nativeEvent.isComposing. A composing Enter now returns early and leaves the IME to commit the text, while a real Enter still selects the option. rc-select already ignores Enter while composing in its input, so this brings Mentions in line.

Tests cover both cases: a composing Enter does not select, and a normal Enter still selects.

Summary by CodeRabbit

  • Bug Fixes

    • 修复了输入法组合输入(IME)过程中按 Enter 误触发选择的问题。
    • 现在在中文输入等组合状态下,Enter 不会提前确认候选项;普通 Enter 仍会正常选中当前高亮项并触发选择回调。
  • Tests

    • 新增覆盖组合输入与普通 Enter 场景的回归测试,确保上述行为稳定可用。

… a mention

On browsers that report the IME commit keydown as `which === ENTER` with
`isComposing` true (Safari being the common one), pressing Enter to confirm a
composed CJK mention selected the highlighted option instead of committing the
text. Guard the Enter branch in onInternalKeyDown with
event.nativeEvent.isComposing so a composing Enter falls through to the IME.
@gemini-code-assist

Copy link
Copy Markdown

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@vercel

vercel Bot commented Jun 29, 2026

Copy link
Copy Markdown

@greymoth-jp is attempting to deploy a commit to the afc163's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 043187e3-fb15-4d6d-8344-71cd5923790b

📥 Commits

Reviewing files that changed from the base of the PR and between 3f919a1 and 4426a3f.

📒 Files selected for processing (2)
  • src/Mentions.tsx
  • tests/Composition.spec.tsx

Walkthrough

onInternalKeyDown 的 Enter 分支新增 event.nativeEvent.isComposing 判断,为真时直接返回,防止 IME 组合确认期间错误触发选项选择逻辑。同时新增 tests/Composition.spec.tsx,覆盖 IME Enter 不选中和普通 Enter 正常选中两个场景。

Changes

IME 组合输入 Enter 键守卫

Layer / File(s) Summary
Enter 键 IME 守卫实现与测试
src/Mentions.tsx, tests/Composition.spec.tsx
onInternalKeyDown 在 Enter 分支加入 isComposing 早返回;测试文件新增 imeEnterKeyDown 辅助函数及两条用例,分别断言 IME Enter 不触发 onSelect/onChange、普通 Enter 正常触发 onSelect

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Suggested reviewers

  • afc163
  • zombieJ

🐰 一只小兔敲回车,
IME 组合别乱跳,
isComposing 挡在前,
选项不会误触到,
测试通过乐陶陶~ 🎉

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确概括了在选择 mention 时忽略 IME 组合输入确认 Enter 的核心修复。
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.
✨ 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.

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.

1 participant