| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
…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.
| Back | FazBrowse Home | New Git URL |
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 justEndedRef flag reset logic was flawed:
Since Enter has keyCode === 13 (not 229), the condition keyCode !== 229 evaluated to true, 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]3. Shared Utilities (DRY/SSOT)
Created centralized utilities to eliminate code duplication:
src/ ├── utils/ │ └── ime.ts # Single source of truth └── hooks/ └── useIMESafeEnterSubmit.ts # Reusable hookComparison with #278
Changes
Supported Languages
This implementation is language-agnostic and supports any IME using composition events:
Testing
References