Skip to content

[Windows] Fix Korean 3-beolsik IME dropping space, digits and punctuation - #194270

Merged
auto-submit[bot] merged 12 commits into
flutter:masterfrom
sujeong000:windows-ime-result-after-endcomposition
Nov 25, 2026
Merged

auto-submit[bot] merged 12 commits into
flutter:masterfrom
sujeong000:windows-ime-result-after-endcomposition

Conversation

@sujeong000

Copy link
Copy Markdown
Contributor

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 TextField on 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_COMPOSITION with GCS_RESULTSTR and WM_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 when GCS_RESULTSTR is set without referring to WM_IME_ENDCOMPOSITION at all. Most IMEs send the result first, and FlutterWindow is written for that order: OnImeEndComposition commits the composing text and destroys the IME window, and DefWindowProc is suppressed for these messages so that the result is not inserted twice via WM_IME_CHAR/WM_CHAR.

In the 3-beolsik layouts the IME consumes every key (WM_KEYDOWN with VK_PROCESSKEY) and emits the characters itself. Captured with a Win32 message probe on Windows 10 22H2 (19045), Microsoft Korean IME, 3-beolsik 390:

// "겨" is being composed, user presses Space
WM_KEYDOWN            vk=VK_PROCESSKEY scan=0x39
WM_IME_ENDCOMPOSITION                     <- arrives first; the GCS_RESULTSTR is already queued
WM_IME_COMPOSITION    GCS_RESULTSTR="겨 "  <- arrives after the end

// nothing is being composed, user presses Space
WM_KEYDOWN            vk=VK_PROCESSKEY scan=0x39
WM_IME_ENDCOMPOSITION                     <- no WM_IME_STARTCOMPOSITION was ever sent
WM_IME_COMPOSITION    GCS_RESULTSTR=" "

After WM_IME_ENDCOMPOSITION the composing text had already been committed and TextInputManager::GetString refused to read the result (ime_active_ was false), so the result string was dropped. Native controls are unaffected because DefWindowProc converts the result to WM_IME_CHAR/WM_CHAR regardless of order; Flutter suppresses that path.

Fix

  • FlutterWindow::OnImeEndComposition peeks the message queue (PM_NOREMOVE, the same approach KeyboardManager already uses to look for a following WM_CHAR) and, if a WM_IME_COMPOSITION with GCS_RESULTSTR is 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::OnImeComposition applies a result to the composition when one is in progress (unchanged); delivers it via OnText when 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 sends WM_IME_ENDCOMPOSITION with nothing queued and then re-sends the committed text as a result, which previously was dropped only as a side effect of the ime_active_ check.
  • TextInputManager::GetResultString no longer requires an active IME window. GetComposingString keeps 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 before OnComposeEnd.
  • MockWindow.OnImeCompositionResultWithoutCompositionIsText: end + result with no composition is delivered via OnText.
  • MockWindow.OnImeCompositionResultAfterEndCompositionIsIgnored: the focus-loss re-send is not inserted again.
  • OnImeCompositionResult and OnImeCompositionResultAndCompose now start a composition first, matching the real message order. MockWindow gained a Win32PeekMessage mock.

Pre-launch Checklist

@sujeong000
sujeong000 requested a review from a team as a code owner October 13, 2026 04:23
@github-actions github-actions Bot added a: text input Entering text in a text field or keyboard related problems engine flutter/engine related. See also e: labels. platform-windows Building on or for Windows specifically a: desktop Running on desktop team-windows Owned by the Windows platform team labels Oct 13, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
mattkae previously approved these changes Oct 21, 2026

@mattkae mattkae left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow Microsoft did not make this easy 🤦 Thanks for tackling this! I will get @loic-sharma as the second reviewer

@mattkae
mattkae requested a review from loic-sharma October 21, 2026 15:23
@loic-sharma loic-sharma added the CICD Run CI/CD label Oct 21, 2026
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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. We receive WM_IME_ENDCOMPOSITION. If the next message is WM_IME_COMPOSITION with GCS_RESULTSTR, we enter the deferred end case and do not end composition. ime_active_ remains true.
  2. We receive the WM_IME_COMPOSITION message.
  3. We read GetResultString() and ime_active_ is still true.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we update this logic to skip this branch if ime_composing_ is false?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@sujeong000
sujeong000 force-pushed the windows-ime-result-after-endcomposition branch from 5781c3d to 4fd4943 Compare October 26, 2026 06:31
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Oct 26, 2026
@justinmc
justinmc requested a review from mattkae November 5, 2026 21:27
@p1318k

p1318k commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

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! 😊

@mattkae mattkae added autosubmit Merge PR when tree becomes green via auto submit App CICD Run CI/CD labels Nov 12, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Nov 12, 2026
@auto-submit

auto-submit Bot commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

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.

@auto-submit

auto-submit Bot commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

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.

  • Merge guidelines: A PR needs at least one approved review if the author is already part of flutter-hackers or two member reviews if the author is not a member of flutter-hackers before re-applying the autosubmit label. Reviewers: If you left a comment approving, please use the "approve" review action instead.

@auto-submit

auto-submit Bot commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

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.

mattkae
mattkae previously approved these changes Nov 12, 2026

@mattkae mattkae left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-acking on my end

@mattkae
mattkae force-pushed the windows-ime-result-after-endcomposition branch from 4fd4943 to 70f0908 Compare November 12, 2026 15:16
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Nov 12, 2026
@mattkae mattkae added the CICD Run CI/CD label Nov 12, 2026
@loic-sharma
loic-sharma force-pushed the windows-ime-result-after-endcomposition branch from 72b5f95 to 8a942b3 Compare November 23, 2026 22:38
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Nov 23, 2026
@loic-sharma loic-sharma added the CICD Run CI/CD label Nov 23, 2026

@loic-sharma loic-sharma left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the excellent contribution!

@loic-sharma loic-sharma added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 23, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Nov 23, 2026
@auto-submit

auto-submit Bot commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

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
@loic-sharma
loic-sharma force-pushed the windows-ime-result-after-endcomposition branch from 8a942b3 to f04c9ac Compare November 24, 2026 23:03
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Nov 24, 2026
@loic-sharma loic-sharma added autosubmit Merge PR when tree becomes green via auto submit App CICD Run CI/CD labels Nov 24, 2026
@auto-submit
auto-submit Bot added this pull request to the merge queue Nov 25, 2026
Merged via the queue into flutter:master with commit 12464d4 Nov 25, 2026
24 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Nov 25, 2026
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Nov 25, 2026
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

...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: desktop Running on desktop a: text input Entering text in a text field or keyboard related problems CICD Run CI/CD engine flutter/engine related. See also e: labels. platform-windows Building on or for Windows specifically team-windows Owned by the Windows platform team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

when using 3-set korean keyboard, textField ignores ' ' - word spacing (space bar key) on Windows

4 participants