Skip to content

Conversation

@aojunhao123
Copy link
Contributor

@aojunhao123 aojunhao123 commented Dec 24, 2025

Summary by CodeRabbit

发布说明

  • 新功能

    • 在示例中添加了新的输入控件,展示额外的 UI 元素。
  • Bug修复

    • 改进了 Escape 键处理逻辑:在输入法(IME)组合输入时不会触发 onEsc,提升输入体验。
  • 测试

    • 新增测试以覆盖 IME 组合输入状态下的 Escape 键行为,确保回归不再发生。

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Dec 24, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

在 Escape 键处理逻辑中添加了对 IME 组合状态(isComposing)的判断,防止在输入法组合期间触发 onEsc;添加对应测试并在示例中新增一个输入控件用于复现场景。 (≤50 字)

Changes

Cohort / File(s) 变更摘要
文档与示例
docs/examples/basic.tsx
在顶层 React.StrictMode 下新增一个 <input type="text" /> 元素,提供 IME 组合场景的可交互示例。
键盘处理 Hook
src/useEscKeyDown.ts
在 keydown 事件处理里加入 event.isComposing(IME 组合)判断,只有当非组合状态且按下 Escape 时才触发 onEsc 回调。
测试
tests/index.test.tsx
新增测试:在输入处于 IME composing (isComposing: true) 时按 Escape,断言 onEsc 不被调用。

Sequence Diagram(s)

(本次变更为局部键盘事件处理和测试示例,交互流程简单,故未生成序列图。)

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • zombieJ

Poem

兔兔轻跳键盘前,🐇
IME 组合静悄然,
Escape 暂停不触发,
测试守护小心间,
提交欢喜又安然。

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题清晰准确地反映了主要变更:在IME输入法组合状态下不触发onEsc回调,与所有修改的文件(useEscKeyDown.ts、tests、docs示例)都相关。
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cc6ddde and a890c09.

📒 Files selected for processing (1)
  • tests/index.test.tsx
🔇 Additional comments (1)
tests/index.test.tsx (1)

360-372: 测试用例结构合理,有效验证了 IME 组合状态下的行为。

这个测试用例正确地验证了新增的功能:

  • 正确使用 jest.fn() 创建模拟函数
  • 通过 isComposing: true 模拟 IME 组合状态
  • 断言在组合状态下 onEsc 不被触发

关于您在第 369 行的评论,虽然单元测试确实无法完全模拟真实 IME 的复杂行为,但这个测试仍然有重要价值:

  1. 它验证了代码正确检查了 isComposing 标志
  2. 防止未来有人意外移除这个检查导致回归
  3. 文档化了预期行为

另外,现有测试已覆盖正常情况(isComposingfalseundefined 时触发 onEsc),因此无需在此重复测试。


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.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @aojunhao123, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a crucial fix to prevent unintended onEsc callback invocations during Input Method Editor (IME) composition. By adding a simple check for the isComposing property of keyboard events, the system now correctly distinguishes between a deliberate Escape key press and one occurring as part of an IME input sequence. This enhancement significantly improves the user experience, especially for users typing in languages that rely on IMEs, by ensuring that the onEsc handler only responds when appropriate. The change is validated with a new, specific test case.

Highlights

  • Fix IME Composition: Resolved an issue where the onEsc callback was incorrectly triggered when the Escape key was pressed during an active Input Method Editor (IME) composition session.
  • Enhanced useEscKeyDown Hook: The handleEscKeyDown function in useEscKeyDown.ts now includes a check for !event.isComposing to prevent onEsc from firing prematurely during IME input.
  • New Test Case: A dedicated test has been added to tests/index.test.tsx to ensure that onEsc is not invoked when the Escape key is pressed while an IME is composing.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly prevents the onEsc event from firing during IME composition by checking the event.isComposing property. The change is simple, effective, and is accompanied by a new test case that properly validates the fix. The addition of an input field to the basic example is also a good touch for manual testing and demonstration. I have one minor suggestion to improve code clarity in the new test.

@codecov
Copy link

codecov bot commented Dec 24, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.24%. Comparing base (14f9f08) to head (a890c09).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master      #32   +/-   ##
=======================================
  Coverage   94.24%   94.24%           
=======================================
  Files           7        7           
  Lines         139      139           
  Branches       48       48           
=======================================
  Hits          131      131           
  Misses          8        8           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

</Portal>,
);

fireEvent.keyDown(window, { key: 'Escape', isComposing: true });
Copy link
Contributor Author

Choose a reason for hiding this comment

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

测试中其实无法模拟真实世界中IME的行为,这里有点脱裤子放屁的嫌疑(

Copy link

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

🧹 Nitpick comments (1)
docs/examples/basic.tsx (1)

25-25: 建议移除或说明此输入框的用途。

这个未绑定任何处理器的 <input> 元素看起来与 IME 修复无关。如果它是为了手动测试 IME 行为而添加的,建议:

  • 添加注释说明其用途
  • 或者在测试完成后将其移除

否则这个孤立的输入框会让示例代码难以理解。

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 14f9f08 and cc6ddde.

📒 Files selected for processing (3)
  • docs/examples/basic.tsx
  • src/useEscKeyDown.ts
  • tests/index.test.tsx
🔇 Additional comments (2)
src/useEscKeyDown.ts (1)

12-12: 修复正确!

添加 !event.isComposing 检查能够正确防止在 IME 输入法组合期间触发 onEsc 回调。isComposing 是标准的 KeyboardEvent 属性,这是解决该问题的标准做法。

tests/index.test.tsx (1)

360-371: 测试用例编写正确!

该测试用例正确验证了在 IME 组合状态下按下 Escape 键不会触发 onEsc 回调。测试结构清晰,断言准确。

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@zombieJ zombieJ merged commit f6d834f into react-component:master Dec 24, 2025
8 checks passed
@aojunhao123 aojunhao123 deleted the fix/IME-esc branch December 24, 2025 09:37
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.

2 participants