Fix: IME input handling to prevent unintended message submission#439
Open
seijikohara wants to merge 1 commit intowinfunc:mainfrom
Open
Fix: IME input handling to prevent unintended message submission#439seijikohara wants to merge 1 commit intowinfunc:mainfrom
seijikohara wants to merge 1 commit intowinfunc:mainfrom
Conversation
…bmission - Add shared IME utilities (src/utils/ime.ts) as single source of truth - Add useIMESafeEnterSubmit custom hook for reusable IME handling - Fix justEndedRef reset condition from keyCode !== 229 to e.key !== "Enter" - Implement multi-layered IME detection: isComposing, composition events, keyCode 229 Supports all IME languages: Japanese, Chinese, Korean, Vietnamese, etc.
63d5855 to
ba4e6d2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes a bug where pressing Enter to confirm IME (Input Method Editor) conversion unintentionally triggers message submission in chat interfaces.
Closes #19
Supersedes #278 (more comprehensive fix applied across all input components)
Problem
When users type with IME for East Asian languages, they press Enter to confirm character conversion (e.g., hiragana → kanji). The application incorrectly interpreted this Enter keypress as a submit action.
Root Cause
The
justEndedRefflag reset logic was flawed:Since Enter has
keyCode === 13(not 229), the conditionkeyCode !== 229evaluated totrue, resetting the flag before the Enter key check could use it.Event Sequence Diagram
sequenceDiagram participant User participant IME participant Browser participant App User->>IME: Type "nihon" IME->>Browser: compositionstart Browser->>App: Set isComposingRef = true User->>IME: Press Enter (confirm) IME->>Browser: compositionend Browser->>App: Set isComposingRef = false Browser->>App: Set justEndedRef = true Browser->>App: keydown (Enter) Note over App: Check justEndedRef → true App->>App: Skip submission ✓ App->>App: Reset justEndedRef = false User->>IME: Press Enter (submit) Browser->>App: keydown (Enter) Note over App: Check justEndedRef → false App->>App: Submit message ✓Solution
1. Fix Flag Reset Condition
Changed the reset condition to only reset on non-Enter keys:
2. Multi-Layered IME Detection
Implemented a detection strategy for cross-browser compatibility:
flowchart TD A[keydown event] --> B{e.isComposing?} B -->|true| Z[Skip: IME active] B -->|false| C{native.isComposing?} C -->|true| Z C -->|false| D{isComposingRef?} D -->|true| Z D -->|false| E{keyCode === 229?} E -->|true| Z E -->|false| F{justEndedRef?} F -->|true| Y[Skip: Just confirmed] F -->|false| G[Process Enter]isComposingpropertykeyCode === 2293. Shared Utilities (DRY/SSOT)
Created centralized utilities to eliminate code duplication:
Comparison with #278
e.key !== "Enter")useIMESafeEnterSubmit)onBlurcleanupChanges
src/utils/ime.tssrc/hooks/useIMESafeEnterSubmit.tssrc/components/FloatingPromptInput.tsxsrc/components/ClaudeCodeSession.tsxsrc/components/TimelineNavigator.tsxsrc/components/WebviewPreview.tsxsrc/components/AgentExecution.tsxSupported Languages
This implementation is language-agnostic and supports any IME using composition events:
Testing
tsc --noEmit)References