fix: improve language detection for IME composition (Chinese input) - #1230
Open
p0ssword wants to merge 1 commit into
Open
fix: improve language detection for IME composition (Chinese input)#1230p0ssword wants to merge 1 commit into
p0ssword wants to merge 1 commit into
Conversation
- 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
JasonWues
added a commit
to JasonWues/gloss
that referenced
this pull request
Aug 16, 2026
Adapts two upstream fixes (pot-app#1178, pot-app#1230) that predate this fork's Tauri 2 migration and so could not be merged as they stand. Typing Chinese means typing pinyin, and the textarea holds those raw letters until a candidate is chosen. Two paths mistook that for text the user had finished writing: - With dynamic translate on, every keystroke armed the one second timer, so a translation of half-typed syllables would fire mid-word. The timer is checked again when it runs, since composition can start after it was armed. `compositionend` translates straight away, so the wait is not paid twice. - Enter selects the highlighted candidate, and that keystroke reaches the keydown handler before the composition ends. Pressing it therefore translated whatever pinyin was in the box. Upstream's patch does not cover this one, and it is the worse of the two: dynamic translate is off by default, this is not. Enter is guarded on the event's own `isComposing` rather than the ref, because the browser sets it on exactly the keystroke in question, whereas `compositionend` has not run yet at that point. A genuine Enter after the word is committed reports false and still submits. Ollama gets `think: false`. Reasoning models otherwise spend their budget deliberating over a translation and, depending on the server version, return that reasoning as the message content -- so it arrives as if it were the translation. `ChatRequest.think` is in the pinned client, 0.6.3. Verified in the running app by dispatching composition events: Enter while composing is not treated as submit and Enter afterwards is; four keystrokes over more than a second while composing issue no request, and `compositionend` issues one immediately. Prettier is not run over SourceArea. It was already non-conformant before this change and reformatting would rewrite about a thousand lines around a forty line fix; the added lines match the configured style on their own. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
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:
compositionstartandcompositionendevent handlersisComposingRefflagChanges
SourceArea/index.jsxto add composition event handlerschangeSourceTextfunction to check composition stateTesting
✓ Tested with Chinese IME input
✓ Language is now correctly detected as Chinese
✓ Works with dynamic translation feature