Skip to content

Windows: place IME cursor at the end when GCS_CURSORPOS is not reported - #4746

Open
seunghan91 wants to merge 1 commit into
rust-windowing:masterfrom
seunghan91:fix/win32-ime-cursor-without-cursorpos
Open

seunghan91 wants to merge 1 commit into
rust-windowing:masterfrom
seunghan91:fix/win32-ime-cursor-without-cursorpos

Conversation

@seunghan91

Copy link
Copy Markdown

With the Microsoft Korean IME, Ime::Preedit always has the cursor at Some((0, 0)), so applications draw the caret before the syllable being composed (e.g. |한 instead of 한|). It also moves the IME candidate window to the start of the composition when the app positions it at the caret.

The IME never sets GCS_CURSORPOS in the WM_IME_COMPOSITION lParam: during composition it is always 0x6018 (GCS_COMPSTR | GCS_COMPATTR | CS_INSERTCHAR | CS_NOMOVECARET). It doesn't mark a target clause either. winit then falls back to ImmGetCompositionStringW(GCS_CURSORPOS) without checking the flag, gets 0, and reports the start of the composition.

This passes the lParam to get_composing_text_and_cursor. When there is no target clause, it reads GCS_CURSORPOS only if the flag is set; otherwise it puts the cursor at the end of the composition. IMEs that report a cursor position or a target clause are unaffected. Firefox also reads the cursor only when GCS_CURSORPOS is set. SDL fixed the same issue by placing the cursor at the end (8e6fed2, b608108).

  • Tested on all platforms changed: Windows 11 with the Microsoft Korean IME, in a Blitz/dioxus-native app built against 0.31.0-beta.3 with this patch, logging the lParam and Ime events, 2 runs per case. Composing 한 now gives Preedit("한", Some((3, 3))) instead of Some((0, 0)), and the caret is drawn after the syllable. 안녕 behaves the same per syllable. The Hanja candidate window now opens at the caret. Commits are unchanged. cargo check/clippy -p winit-win32 --target x86_64-pc-windows-msvc on master.
  • Added an entry to the changelog module if knowledge of this change could be valuable to users
  • Updated documentation to reflect any user-facing changes, including notes of platform-specific behavior (not needed)
  • Created or updated an example program if it would help users understand this functionality (not needed)

echelon added a commit to storytold/pdfcraft that referenced this pull request Oct 10, 2026
…nit#4746) (#673)

When a composition has no target clause, winit 0.30.13 reads the cursor with
ImmGetCompositionStringW(GCS_CURSORPOS) without checking that the
WM_IME_COMPOSITION lParam has GCS_CURSORPOS set. The Microsoft Korean IME
never sets it (lParam 0x6018), so the read gives 0 and winit reports
Ime::Preedit("한", Some((0, 0))). egui 0.36.2 recognises that exact report on
Windows and drops the range, so PdfCraft draws no caret while Korean is being
composed.

vendor/winit now reads GCS_CURSORPOS only when the flag says the IME set it
and otherwise puts the cursor at the end of the composition, as
rust-windowing/winit#4746 does on winit master (Firefox and SDL do the same).
IMEs that report a cursor or a target clause (Japanese, Chinese) are
unchanged. A test fails if a re-vendored winit loses the patch.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Brandon Thomas <echelon@gmail.com>
krichelj pushed a commit to krichelj/pdfcraft that referenced this pull request Oct 11, 2026
…nit#4746) (storytold#673)

When a composition has no target clause, winit 0.30.13 reads the cursor with
ImmGetCompositionStringW(GCS_CURSORPOS) without checking that the
WM_IME_COMPOSITION lParam has GCS_CURSORPOS set. The Microsoft Korean IME
never sets it (lParam 0x6018), so the read gives 0 and winit reports
Ime::Preedit("한", Some((0, 0))). egui 0.36.2 recognises that exact report on
Windows and drops the range, so PdfCraft draws no caret while Korean is being
composed.

vendor/winit now reads GCS_CURSORPOS only when the flag says the IME set it
and otherwise puts the cursor at the end of the composition, as
rust-windowing/winit#4746 does on winit master (Firefox and SDL do the same).
IMEs that report a cursor or a target clause (Japanese, Chinese) are
unchanged. A test fails if a re-vendored winit loses the patch.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Brandon Thomas <echelon@gmail.com>
@seunghan91
seunghan91 force-pushed the fix/win32-ime-cursor-without-cursorpos branch from 3787f3d to 63f7546 Compare October 21, 2026 09:14
@seunghan91

Copy link
Copy Markdown
Author

Rebased onto master (the only conflict was in the changelog); CI is green again. @ogoffart, since you merged #4700, would you have a moment to look at this? Windows has no code owner, so it hasn't been picked up.

richerfu pushed a commit to richerfu/winit that referenced this pull request Nov 2, 2026
Port of rust-windowing#4746.

Originally "M15.1: fix Windows Korean IME caret" in storytold/wordcraft#787 (same change as storytold/pdfcraft vendor/winit).

This branch has not been deployed

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant