Repository navigation
[Windows] Fix Korean 3-beolsik IME dropping space, digits and punctuation - #194270
auto-submit[bot] merged 12 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request modifies the Windows platform shell to defer ending IME compositions when a result string is queued, resolving issues with certain IME layouts like Microsoft Korean 3-beolsik. It introduces state variables to track composition status, utilizes Win32PeekMessage to detect queued results, and updates TextInputManager to allow reading result strings after composition ends. Unit tests are added to verify these behaviors. The review feedback suggests replacing std::optional::value() with operator* when retrieving the committed text to avoid exception-handling overhead and adhere to the Google C++ Style Guide.
mattkae
left a comment
There was a problem hiding this comment.
Wow Microsoft did not make this easy 🤦 Thanks for tackling this! I will get @loic-sharma as the second reviewer
| std::optional<std::u16string> TextInputManager::GetResultString() const { | ||
| // Unlike the composing string, the result string is read even when no IME | ||
| // window is active: some IMEs deliver it after WM_IME_ENDCOMPOSITION, or | ||
| // without a preceding WM_IME_STARTCOMPOSITION. |
There was a problem hiding this comment.
I wonder if we should keep the ime_active_ checks here unchanged, and instead keep all the logic about deferred IME end in flutter_window.cc.
From my understanding:
- We receive
WM_IME_ENDCOMPOSITION. If the next message isWM_IME_COMPOSITIONwithGCS_RESULTSTR, we enter the deferred end case and do not end composition.ime_active_remains true. - We receive the
WM_IME_COMPOSITIONmessage. - We read
GetResultString()andime_active_is stilltrue.
There was a problem hiding this comment.
Thanks for the suggestion! I tried to keep TextInputManager unchanged, but the deferred end alone doesn’t cover the case where nothing is being composed.
ime_active_ is only set by CreateImeWindow() (on WM_IME_SETCONTEXT or WM_IME_STARTCOMPOSITION) and cleared by DestroyImeWindow() when a composition ends. In 3-beolsik, a bare space/punctuation key sends WM_IME_ENDCOMPOSITION + GCS_RESULTSTR without any WM_IME_STARTCOMPOSITION. So once an earlier composition has ended (e.g. typing a syllable followed by two spaces), ime_active_ is already false and GetResultString() returns nullopt, dropping the second space. I verified this on Windows 10 by reverting just this change.
The existing tests mock GetResultString(), so they couldn’t catch this. I moved the IMM read in TextInputManager into a protected virtual ReadImmString() (no behavior change), so that a test can mock only that and run the real ime_active_ handling. The new OnImeCompositionResultAfterPreviousCompositionIsText test types a syllable followed by two spaces and fails if the ime_active_ check is restored.
The decision of whether to use a result now lives in FlutterWindow (it is ignored when there is no composition and no deferred end), so TextInputManager just reports what IMM holds.
There was a problem hiding this comment.
Should we update this logic to skip this branch if ime_composing_ is false?
There was a problem hiding this comment.
Done. A composing string outside a composition would otherwise be inserted as plain text by ComposeChangeHook. The existing tests that sent GCS_COMPSTR without WM_IME_STARTCOMPOSITION now start a composition first, matching the real message order, and I added OnImeCompositionComposeWithoutCompositionIsIgnored.
5781c3d to
4fd4943
Compare
|
Hi @mariamhas 👋 Following up on your Flutter Korea 2026 talk 🇰🇷: this PR fixes a Korean IME localization issue on Windows (#140537, open since 2023), and we're getting user complaints about it in our app 🙏 loic-sharma is the assigned reviewer and re-review was requested after all feedback was addressed, but it hasn't moved since. Could you help move it forward? Thanks so much! 😊 |
|
autosubmit label was removed for flutter/flutter/194270, because The base commit of the PR is older than 7 days and can not be merged. Please merge the latest changes from the main into this branch and resubmit the PR. |
|
autosubmit label was removed for flutter/flutter/194270, because This PR has not met approval requirements for merging. The PR author is not a member of flutter-hackers and needs 2 more review(s) in order to merge this PR.
|
|
autosubmit label was removed for flutter/flutter/194270, because - The status or check suite ci.yaml validation has failed. Please fix the issues identified (or deflake) before re-applying this label. |
4fd4943 to
70f0908
Compare
72b5f95 to
8a942b3
Compare
loic-sharma
left a comment
There was a problem hiding this comment.
Thank you for the excellent contribution!
|
autosubmit label was removed for flutter/flutter/194270, because - The status or check suite Tree_analyze has failed. Please fix the issues identified (or deflake) before re-applying this label. |
…ITION
IMM32 does not guarantee the order of WM_IME_COMPOSITION (GCS_RESULTSTR)
and WM_IME_ENDCOMPOSITION. Most IMEs send the result first, and
FlutterWindow relies on that: WM_IME_ENDCOMPOSITION commits the
composing text and destroys the IME window, and DefWindowProc is
suppressed for these messages so that the result is not inserted twice.
The Microsoft Korean IME in the 3-beolsik (390 / Final) layouts consumes
every key and, when a space, digit or punctuation key ends a
composition, sends WM_IME_ENDCOMPOSITION *before* the GCS_RESULTSTR
(for example "겨 "). With nothing being composed it sends
WM_IME_ENDCOMPOSITION followed by the result (" ") without any
WM_IME_STARTCOMPOSITION. In both cases the result string could not be
read after the composition had ended and was dropped, and because
DefWindowProc was suppressed there was no WM_CHAR fallback either, so
the typed character was lost.
When WM_IME_ENDCOMPOSITION arrives while a GCS_RESULTSTR message is
already queued, defer ending the composition until that result has been
applied. A result that arrives with no composition in progress but with
a deferred end is delivered as text input. A result that arrives after a
non-deferred end (the IME re-sends the committed text when the window
loses focus) is ignored so that it is not inserted twice. The result
string is now readable without an active IME window; the composing
string keeps its previous behaviour.
IMEs that send the result before WM_IME_ENDCOMPOSITION never take the
deferred path and behave as before.
Fixes flutter#140537
8a942b3 to
f04c9ac
Compare
Roll Flutter from b75c5b30406a to 06f1c24345a2 (37 revisions) flutter/flutter@b75c5b3...06f1c24 2026-11-25 [email protected] Roll Skia from a60d883b3fe3 to e84ecd98d9f2 (2 revisions) (flutter/flutter#197375) 2026-11-25 [email protected] Roll Skia from ca229e319550 to a60d883b3fe3 (4 revisions) (flutter/flutter#197371) 2026-11-25 [email protected] Roll Skia from 6f75212e5a23 to ca229e319550 (2 revisions) (flutter/flutter#197369) 2026-11-25 [email protected] Roll Skia from 75d95595f14e to 6f75212e5a23 (1 revision) (flutter/flutter#197364) 2026-11-25 [email protected] [Windows] Fix Korean 3-beolsik IME dropping space, digits and punctuation (flutter/flutter#194270) 2026-11-25 [email protected] [flutter_tools] Strip embedded credentials from repository URLs (flutter/flutter#197219) 2026-11-25 [email protected] [flutter_tools] Add structured extension.log notifications for tool extensions (flutter/flutter#196714) 2026-11-25 [email protected] [flutter_tools] Share Depfile in flutter_tools_core and make BuildTarget.targetPlatform optional (flutter/flutter#194965) 2026-11-25 [email protected] Reply null asynchronously to ignored web platform messages and unskip missing-asset tests (flutter/flutter#197267) 2026-11-25 [email protected] Roll Dart SDK from 87f515c52de9 to 5202130a51b8 (1 revision) (flutter/flutter#197363) 2026-11-25 [email protected] [web] Retain queued scene pictures via ContainerLayer render pinning (flutter/flutter#196748) 2026-11-25 [email protected] [flutter_tools] Include dependency manifests in copyAssets depfile (flutter/flutter#196596) 2026-11-25 [email protected] Print the Intel Mac deprecation warning on every command (flutter/flutter#194071) 2026-11-25 [email protected] Roll Skia from 243c0dc9f662 to 75d95595f14e (2 revisions) (flutter/flutter#197351) 2026-11-25 [email protected] iOS: Ignore platform messages after the engine is destroyed (flutter/flutter#197310) 2026-11-24 [email protected] Bump customer tests to pick up material_ui cache extent test updates (flutter/flutter#197266) 2026-11-24 [email protected] [flutter_tools] Use refreshed FlutterVersion for flutter doctor feature flags (flutter/flutter#196944) 2026-11-24 [email protected] [flutter_tools] Do not crash if buildXcodeProject temporary directory is deleted before cleanup (flutter/flutter#195918) 2026-11-24 [email protected] Fix some `parameter_assignments` warnings (flutter/flutter#196815) 2026-11-24 [email protected] [flutter_tools] Extract PlatformDebuggingOptions and move WebDebugConfig (flutter/flutter#197229) 2026-11-24 [email protected] Fix desktop apps installing to the system prefix after a failed build (flutter/flutter#196482) 2026-11-24 [email protected] [flutter_tools] Write flutter test native_assets.json outside targetDir (flutter/flutter#196300) 2026-11-24 [email protected] iOS: Check the presented composition order in platform view tests (flutter/flutter#197302) 2026-11-24 [email protected] Run the shared Vulkan embedder tests under Impeller as well as Skia (flutter/flutter#193004) 2026-11-24 [email protected] Roll Fuchsia Linux SDK from BOgXtIYxLYcCkRou2... to HtAKfFLbfAQ6g96RY... (flutter/flutter#197334) 2026-11-24 [email protected] Roll Skia from b3dec9325fe1 to 243c0dc9f662 (6 revisions) (flutter/flutter#197333) 2026-11-24 [email protected] [flutter_tools] Delete globals.dart and context_runner.dart (flutter/flutter#196095) 2026-11-24 [email protected] Update viewInsets docs for translucent and rounded system UI (flutter/flutter#196355) 2026-11-24 [email protected] [flutter_tools] Check that dartaotruntime can run before starting the frontend server (flutter/flutter#194206) 2026-11-24 [email protected] [framework] Fix DraggableScrollableSheet '_hold == null' assertion when touch lifts during snap (flutter/flutter#195771) 2026-11-24 [email protected] [web] Release ImageSource on GC and fix Picture finalizer cycles (flutter/flutter#197245) 2026-11-24 [email protected] [flutter_tools] Fix web compiler output tracking in web builds (flutter/flutter#196563) 2026-11-24 [email protected] Upgrade CI to Xcode 27.2 (flutter/flutter#196807) 2026-11-24 [email protected] Roll Packages from 5b93485 to f455dfa (6 revisions) (flutter/flutter#197316) 2026-11-24 [email protected] [Linux] Fix deadlock presenting to a Wayland subsurface (flutter/flutter#196945) 2026-11-24 [email protected] Roll Skia from 2140958ee284 to b3dec9325fe1 (1 revision) (flutter/flutter#197309) 2026-11-24 [email protected] Roll Fuchsia Test Scripts from oEU515sDqSTvD8Spx... to GPtykFNizlaauBqzs... (flutter/flutter#197313) If this roll has caused a breakage, revert this CL and set the roller to dry run mode using the controls here: https://autoroll.skia.org/r/flutter-packages Please CC [email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose ...
Fixes #140537
Problem
With the Microsoft Korean IME set to a 3-beolsik layout (390 or Final), a space, digit or punctuation character typed into a
TextFieldon Windows is silently dropped, both while Hangul is being composed and when nothing is being composed. 2-beolsik is unaffected.Screen Recordings
Microsoft Korean IME, 3-beolsik 390, windows 10 22H2
Before - the space, digit and period are dropped.
before.mov
After - all characters are inserted.
after.mov
Cause
IMM32 does not guarantee the relative order of
WM_IME_COMPOSITIONwithGCS_RESULTSTRandWM_IME_ENDCOMPOSITION: the WM_IME_COMPOSITION, WM_IME_ENDCOMPOSITION and WM_IME_STARTCOMPOSITION pages describe each message in isolation, and Microsoft's own sample inserts the result string whenGCS_RESULTSTRis set without referring toWM_IME_ENDCOMPOSITIONat all. Most IMEs send the result first, andFlutterWindowis written for that order:OnImeEndCompositioncommits the composing text and destroys the IME window, andDefWindowProcis suppressed for these messages so that the result is not inserted twice viaWM_IME_CHAR/WM_CHAR.In the 3-beolsik layouts the IME consumes every key (
WM_KEYDOWNwithVK_PROCESSKEY) and emits the characters itself. Captured with a Win32 message probe on Windows 10 22H2 (19045), Microsoft Korean IME, 3-beolsik 390:After
WM_IME_ENDCOMPOSITIONthe composing text had already been committed andTextInputManager::GetStringrefused to read the result (ime_active_was false), so the result string was dropped. Native controls are unaffected becauseDefWindowProcconverts the result toWM_IME_CHAR/WM_CHARregardless of order; Flutter suppresses that path.Fix
FlutterWindow::OnImeEndCompositionpeeks the message queue (PM_NOREMOVE, the same approachKeyboardManageralready uses to look for a followingWM_CHAR) and, if aWM_IME_COMPOSITIONwithGCS_RESULTSTRis already queued, defers ending the composition until that result has been processed. IMEs that send the result first see no change: nothing is queued, so the composition ends immediately as before.FlutterWindow::OnImeCompositionapplies a result to the composition when one is in progress (unchanged); delivers it viaOnTextwhen there is no composition but the end was deferred (the bare-space case above); and ignores a result that arrives after a non-deferred end. The last case happens when the window loses focus during composition: the Korean IME sendsWM_IME_ENDCOMPOSITIONwith nothing queued and then re-sends the committed text as a result, which previously was dropped only as a side effect of theime_active_check.TextInputManager::GetResultStringno longer requires an active IME window.GetComposingStringkeeps the previous check, so composing-string handling is unchanged.Tests
MockWindow.OnImeEndCompositionWaitsForQueuedResult: the end is deferred until the queued result, and the result is applied to the composition beforeOnComposeEnd.MockWindow.OnImeCompositionResultWithoutCompositionIsText: end + result with no composition is delivered viaOnText.MockWindow.OnImeCompositionResultAfterEndCompositionIsIgnored: the focus-loss re-send is not inserted again.OnImeCompositionResultandOnImeCompositionResultAndComposenow start a composition first, matching the real message order.MockWindowgained aWin32PeekMessagemock.Pre-launch Checklist
///).