Skip to content

Keep IME candidate confirmation from sending or stopping chat - #1038

Open
PeterDaveHello wants to merge 1 commit into
masterfrom
fix/input-ime-enter
Open

Keep IME candidate confirmation from sending or stopping chat#1038
PeterDaveHello wants to merge 1 commit into
masterfrom
fix/input-ime-enter

Conversation

@PeterDaveHello

@PeterDaveHello PeterDaveHello commented Aug 6, 2026

Copy link
Copy Markdown
Member

Problem

CJK input methods commonly use Enter to confirm candidate text while composition is still active. The input box treated every unshifted Enter as a chat action, which could send incomplete text or stop an active response instead of confirming the IME candidate.

With Preact compat, composition state may be exposed on the synthetic event or its underlying native keyboard event. Some browser and IME combinations also use the legacy keyCode value 229.

Changes

  • Ignore Enter keydowns when either the direct or native event reports active composition.
  • Cover the legacy keyCode === 229 IME fallback.
  • Preserve button clicks, modern and legacy plain Enter submission, and Shift+Enter line breaks.
  • Test the key and keyCode Enter paths independently so either path cannot regress unnoticed.

Validation

  • node --test tests/unit/components/input-box-action.test.mjs — 6 tests passed in an isolated source mirror.
  • The combined focused suite for all five independent fixes — 39 tests passed.
  • node --check passed for the changed JavaScript modules.
  • Greptile and GitHub Copilot completed their amended-head reviews successfully with no new comments.
  • Skipped: full npm test, npm run test:coverage, npm run lint, npm run build, artifact checks, and native Chromium/Firefox IME smoke tests. This execution environment could not obtain a complete repository checkout or install its dependencies, and the repository's pr-tests workflow did not start automatically for this connector-created PR.

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

InputBox now delegates click and keyboard action filtering to shouldHandleInputAction. The helper excludes Shift+Enter, active IME composition, key code 229, and unrelated keyboard events. Unit tests cover accepted and rejected cases.

Changes

Input action handling

Layer / File(s) Summary
Input action predicate and tests
src/components/InputBox/input-action.mjs, tests/unit/components/input-box-action.test.mjs
Added shouldHandleInputAction and tests for clicks, Enter, Shift+Enter, IME composition, key code 229, and unrelated keyboard events.
InputBox event integration
src/components/InputBox/index.jsx
Replaced inline event filtering with shouldHandleInputAction(e). Existing submission and stop-generation behavior remains unchanged for handled events.

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

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes preventing IME candidate confirmation from submitting or stopping chat.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/input-ime-enter

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.

@qodo-code-review

Copy link
Copy Markdown
Contributor

PR Summary by Qodo

Prevent IME Enter confirmation from sending/stopping chat

🐞 Bug fix 🧪 Tests 🕐 10-20 Minutes

Grey Divider

AI Description

• Ignore Enter keydowns during active IME composition to avoid premature send/stop.
• Support legacy IME detection via keyCode === 229 fallback.
• Extract action-decision logic into a helper and cover with unit tests.
Diagram

graph TD
  A["InputBox (index.jsx)"] --> B["shouldHandleInputAction (input-action.mjs)"] --> C(["Unit tests (input-box-action.test.mjs)"])
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Track composition state via compositionstart/end in component state
  • ➕ Can be more explicit and resilient than relying on per-event flags
  • ➕ Allows richer behaviors (e.g., buffering actions until composition ends)
  • ➖ More component state and event wiring
  • ➖ Harder to unit test without heavier UI/event simulation
2. Use `beforeinput` / `inputType` to distinguish composition confirmation
  • ➕ More semantically aligned with text input mutations than key events
  • ➕ Potentially avoids legacy keyCode quirks
  • ➖ Browser support/behavior differences and more edge cases to validate
  • ➖ More invasive change to current keydown/click flow

Recommendation: The chosen approach (early-return on isComposing and legacy keyCode === 229, isolated into a helper) is the best fit for a targeted fix: it’s minimal, low risk, and now covered deterministically by unit tests. Consider a compositionstart/end state approach only if future requirements need more nuanced composition-aware behaviors.

Files changed (3) +61 / -1

Bug fix (2) +10 / -1
index.jsxDelegate send/stop decision to IME-aware helper +2/-1

Delegate send/stop decision to IME-aware helper

• Replaces inline click/Enter detection with 'shouldHandleInputAction(e)' inside the shared keydown/click handler. This prevents Enter during IME composition from triggering chat send/stop while preserving existing click and Enter behaviors.

src/components/InputBox/index.jsx

input-action.mjsAdd IME-safe input action predicate +8/-0

Add IME-safe input action predicate

• Introduces 'shouldHandleInputAction(event)' to decide whether an event should trigger an input action. It allows clicks and plain Enter, ignores Shift+Enter, and suppresses handling during composition via 'isComposing' or legacy 'keyCode === 229'.

src/components/InputBox/input-action.mjs

Tests (1) +51 / -0
input-box-action.test.mjsUnit tests for IME/Enter input action rules +51/-0

Unit tests for IME/Enter input action rules

• Adds node:test coverage for click handling, Enter vs Shift+Enter behavior, and IME composition suppression including the legacy 'keyCode === 229' fallback. Ensures unrelated key events are ignored.

tests/unit/components/input-box-action.test.mjs

@greptile-apps

greptile-apps Bot commented Aug 6, 2026

Copy link
Copy Markdown

Greptile Summary

The PR prevents Enter from triggering chat actions while an IME composition is active, including the legacy key-code fallback.

  • Extracts input-action classification into a standalone module.
  • Preserves click submission, plain Enter actions, and Shift+Enter line breaks.
  • Adds focused unit coverage for keyboard, click, and IME event states.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
src/components/InputBox/index.jsx Replaces the inline Enter-key condition with the extracted IME-aware action predicate.
src/components/InputBox/input-action.mjs Defines deterministic classification for click, Enter, Shift+Enter, and active-composition events.
tests/unit/components/input-box-action.test.mjs Covers supported chat actions and the IME conditions that must suppress them.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  E[Input event] --> C{Click?}
  C -->|Yes| A[Handle chat action]
  C -->|No| K{Keydown?}
  K -->|No| I[Ignore]
  K -->|Yes| M{Composing or keyCode 229?}
  M -->|Yes| I
  M -->|No| N{Enter without Shift?}
  N -->|Yes| A
  N -->|No| I
Loading

Reviews (2): Last reviewed commit: "Keep IME candidate confirmation from sen..." | Re-trigger Greptile

@qodo-code-review

qodo-code-review Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📜 Skill insights (0)

Grey Divider


Informational

1. Long shouldHandleInputAction test line ✗ Dismissed 📘 Rule violation ⚙ Maintainability
Description
A new test line exceeds the 100-character source line limit. This reduces readability and violates
the repository’s line-length compliance requirement.
Code

tests/unit/components/input-box-action.test.mjs[8]

+    shouldHandleInputAction({ type: 'keydown', key: 'Enter', keyCode: 13, shiftKey: false }),
Evidence
PR Compliance ID 2261946 requires source lines to be 100 characters or fewer. The added assertion
call on line 8 is a single long line containing a full object literal argument and exceeds this
limit.

Rule 2261946: Limit source line length to 100 characters
tests/unit/components/input-box-action.test.mjs[8-8]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
A newly added test line exceeds the 100 character maximum line length.

## Issue Context
The project compliance checklist requires non-comment, non-whitespace source lines to be at most 100 characters.

## Fix Focus Areas
- tests/unit/components/input-box-action.test.mjs[8-8]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Context used
✅ Compliance rules (platform): 6 rules

To customize comments, go to the Qodo configuration screen, or learn more in the docs.

Qodo Logo

Comment thread tests/unit/components/input-box-action.test.mjs Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
tests/unit/components/input-box-action.test.mjs (1)

5-10: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Test the modern and legacy Enter paths separately.

The current fixture sets both key: 'Enter' and keyCode: 13. The test passes if either detection branch is removed. Add one key-only case and one keyCode-only case.

Proposed test adjustment
   assert.equal(
-    shouldHandleInputAction({ type: 'keydown', key: 'Enter', keyCode: 13, shiftKey: false }),
+    shouldHandleInputAction({ type: 'keydown', key: 'Enter', shiftKey: false }),
     true,
   )
+  assert.equal(
+    shouldHandleInputAction({ type: 'keydown', keyCode: 13, shiftKey: false }),
+    true,
+  )
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/unit/components/input-box-action.test.mjs` around lines 5 - 10, The
test “input actions handle button clicks and plain Enter keys” must isolate both
Enter detection branches. Keep the click assertion, then add separate keydown
cases: one with only key set to “Enter” and one with only keyCode set to 13,
with the other Enter field omitted, and assert both are handled.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/components/InputBox/input-action.mjs`:
- Line 4: Update shouldHandleInputAction to read the IME composition state from
event.nativeEvent?.isComposing while retaining the keyCode === 229 guard, so
composing Enter events are ignored. Add a test invoking shouldHandleInputAction
with a native event object whose isComposing is true.

---

Nitpick comments:
In `@tests/unit/components/input-box-action.test.mjs`:
- Around line 5-10: The test “input actions handle button clicks and plain Enter
keys” must isolate both Enter detection branches. Keep the click assertion, then
add separate keydown cases: one with only key set to “Enter” and one with only
keyCode set to 13, with the other Enter field omitted, and assert both are
handled.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: a96a3f3c-55a4-458c-a797-43095c21db96

📥 Commits

Reviewing files that changed from the base of the PR and between 6b2b2f5 and c117c3a.

📒 Files selected for processing (3)
  • src/components/InputBox/index.jsx
  • src/components/InputBox/input-action.mjs
  • tests/unit/components/input-box-action.test.mjs

Comment thread src/components/InputBox/input-action.mjs Outdated
CJK input methods use Enter to confirm candidate text. Treating that
keydown as an input action can submit incomplete text or stop an active
response.

Read composition state from both direct and synthetic native events,
retain the legacy keyCode 229 fallback, and test each Enter path alone.
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

Copilot AI left a comment

Copy link
Copy Markdown

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 IME (CJK) usability bug in the InputBox: confirming an IME candidate with Enter during active composition no longer triggers the extension’s “send/stop” action.

Changes:

  • Introduces a shared shouldHandleInputAction helper to gate click/Enter handling and ignore Enter during IME composition (including legacy keyCode === 229).
  • Updates InputBox to use the helper instead of inline Enter/click logic.
  • Adds focused unit tests to prevent regressions across key, keyCode, Shift+Enter, composition flags, and unrelated keys.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
tests/unit/components/input-box-action.test.mjs Adds unit coverage for the new input-action gating logic (Enter, Shift+Enter, IME composition, legacy 229).
src/components/InputBox/input-action.mjs Implements shouldHandleInputAction to ignore IME composition Enter keydowns while preserving click and plain Enter behavior.
src/components/InputBox/index.jsx Replaces inline click/Enter handling with shouldHandleInputAction to prevent unintended send/stop during IME composition.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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