Prevent chat submit on Enter during Chinese IME composition#51
Prevent chat submit on Enter during Chinese IME composition#51
Conversation
Agent-Logs-Url: https://github.com/OpenSource03/harnss/sessions/1710c611-f27a-4dfc-9fdc-0b92bd8dd572 Co-authored-by: OpenSource03 <29690431+OpenSource03@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes an Electron/React chat composer edge case where pressing Enter to commit a Chinese IME composition could incorrectly trigger message send, by making Enter-to-submit composition-aware and adding unit tests.
Changes:
- Introduces
shouldSubmitOnEnterto guard Enter submission when IME composition is active (isComposingand keyCode 229 fallback). - Wires the predicate into
InputBar’s keydown flow in place of rawEnter && !Shiftlogic. - Adds unit tests covering composing vs non-composing Enter behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/components/InputBar.test.ts | Adds unit tests for IME composition-aware Enter submission. |
| src/components/input-bar/InputBar.tsx | Uses shouldSubmitOnEnter(e) to avoid submitting during IME composition. |
| src/components/input-bar/input-bar-utils.ts | Adds shouldSubmitOnEnter predicate (composition-aware Enter detection). |
| src/components/input-bar/index.ts | Re-exports shouldSubmitOnEnter from the input-bar barrel. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| shouldSubmitOnEnter, | ||
| } from "./input-bar"; | ||
|
|
||
| describe("InputBar slash command helpers", () => { |
There was a problem hiding this comment.
The describe block name is now misleading: this suite includes shouldSubmitOnEnter behavior in addition to slash command helpers. Consider renaming the describe title or moving the Enter-related tests into a separate describe to keep test intent clear.
| export function shouldSubmitOnEnter(event: EnterKeyEventLike): boolean { | ||
| if (event.key !== "Enter" || event.shiftKey) return false; | ||
| const nativeEvent = event.nativeEvent; | ||
| return !( | ||
| event.isComposing || | ||
| nativeEvent?.isComposing || | ||
| nativeEvent?.keyCode === 229 | ||
| ); |
There was a problem hiding this comment.
nativeEvent?.keyCode === 229 introduces an unexplained magic number. Consider extracting 229 into a named constant (e.g. IME_PROCESS_KEYCODE) with a short comment about why it’s checked so future maintainers know what it represents.
Summary
isComposing+keyCode===229fallback) and wires it intoInputBarkeydown flow.Type of Change
Related Issues
How to Test
nihao), and press Enter to commit.Screenshots / Screen Recording
Issue reproduction screenshot:
https://github.com/user-attachments/assets/9e2b4292-c306-4d65-aabd-faba0ce50aef
Implementation Notes
Input key handling
InputBarnow usesshouldSubmitOnEnter(event)instead of rawEnter && !Shiftlogic.IME-safe predicate
shouldSubmitOnEnterininput-bar-utils.ts:Tests
isComposing === truenativeEvent.isComposing === truenativeEvent.keyCode === 229Checklist
pnpm build)anytypes introducedms-*/me-*instead ofml-*/mr-*)wrap-break-wordshared/types/, notsrc/types/Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
www.electronjs.org/opt/hostedtoolcache/node/24.14.1/x64/bin/node /opt/hostedtoolcache/node/24.14.1/x64/bin/node /home/REDACTED/work/harnss/harnss/node_modules/.pnpm/@electron+rebuild@4.0.3/node_modules/@electron/rebuild/lib/module-type/node-gyp/worker.js(dns block)If you need me to access, download, or install something from one of these locations, you can either: