Skip to content

fix: improve language detection for IME composition (Chinese input)#1230

Open
p0ssword wants to merge 1 commit into
pot-app:masterfrom
p0ssword:master
Open

fix: improve language detection for IME composition (Chinese input)#1230
p0ssword wants to merge 1 commit into
pot-app:masterfrom
p0ssword:master

Conversation

@p0ssword
Copy link
Copy Markdown

@p0ssword p0ssword commented Jan 9, 2026

Problem

When typing Chinese characters using an IME (Input Method Editor), the language detection was frequently incorrect, often detecting the text as English instead of Chinese.

Root Cause

The language detection was triggered during the IME composition process (while the user is still typing), leading to detection of incomplete text fragments.

Solution

Implemented IME composition event handling to prevent language detection during composition:

  • Added compositionstart and compositionend event handlers
  • Track IME composition state with isComposingRef flag
  • Skip language detection while IME composition is active
  • Perform language detection immediately after composition completes

Changes

  • Modified SourceArea/index.jsx to add composition event handlers
  • Updated changeSourceText function to check composition state
  • Language detection now waits for complete text input before detection

Testing

✓ Tested with Chinese IME input
✓ Language is now correctly detected as Chinese
✓ Works with dynamic translation feature

- Add compositionstart/compositionend event handlers to track IME composition state
- Prevent language detection while user is composing text with IME
- Use isComposingRef flag to skip detection during IME composition
- Perform language detection immediately after composition completes
- Fix issue where Chinese input was incorrectly detected as English
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.

1 participant