Skip to content

Prevent chat submit on Enter during Chinese IME composition#51

Draft
Copilot wants to merge 2 commits intomasterfrom
copilot/fix-chinese-ime-enter-key-issue
Draft

Prevent chat submit on Enter during Chinese IME composition#51
Copilot wants to merge 2 commits intomasterfrom
copilot/fix-chinese-ime-enter-key-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 11, 2026

Summary

  • Fixes chat composer Enter handling so IME composition commit (e.g., Pinyin → 中文) does not trigger message send.
  • Adds a composition-aware Enter guard (isComposing + keyCode===229 fallback) and wires it into InputBar keydown flow.
  • Adds focused unit coverage for composing vs non-composing Enter behavior.

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 💥 Breaking change (fix or feature that changes existing behavior)
  • 🎨 UI / design improvement
  • ⚡ Performance improvement
  • ♻️ Refactor (no functional changes)
  • 🧪 Tests / CI
  • 📝 Documentation

Related Issues

How to Test

  1. Enable a Chinese IME (Pinyin/Sogou/Rime), focus the chat composer, type phonetics (e.g., nihao), and press Enter to commit.
  2. Confirm composed text is inserted in the composer and not sent.
  3. Press Enter again (not composing) and confirm normal send still works; verify Shift+Enter still inserts a newline.

Screenshots / Screen Recording

Issue reproduction screenshot:
https://github.com/user-attachments/assets/9e2b4292-c306-4d65-aabd-faba0ce50aef

Implementation Notes

  • Input key handling

    • InputBar now uses shouldSubmitOnEnter(event) instead of raw Enter && !Shift logic.
  • IME-safe predicate

    • Added shouldSubmitOnEnter in input-bar-utils.ts:
      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
        );
      }
  • Tests

    • Added cases covering:
      • isComposing === true
      • nativeEvent.isComposing === true
      • nativeEvent.keyCode === 229
      • normal Enter / Shift+Enter / non-Enter behavior

Checklist

  • I've tested this on macOS (required for Electron/native features)
  • TypeScript compiles with no errors (pnpm build)
  • No any types introduced
  • Logical margins used (ms-*/me-* instead of ml-*/mr-*)
  • User-generated content containers have wrap-break-word
  • New shared types go in shared/types/, not src/types/
  • Large components/hooks are decomposed into sub-components/sub-hooks if needed

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
    • Triggering command: /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:

Copilot AI changed the title [WIP] Fix Chinese IME Enter key behavior for composition Prevent chat submit on Enter during Chinese IME composition Apr 11, 2026
Copilot AI requested a review from OpenSource03 April 11, 2026 09:53
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 shouldSubmitOnEnter to guard Enter submission when IME composition is active (isComposing and keyCode 229 fallback).
  • Wires the predicate into InputBar’s keydown flow in place of raw Enter && !Shift logic.
  • 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", () => {
Copy link

Copilot AI Apr 12, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment on lines +160 to +167
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
);
Copy link

Copilot AI Apr 12, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
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]: Chinese IME Enter key submits input instead of committing composition

3 participants