Skip to content

Windows: the Korean IME composition caret sits after the syllable (winit#4746) - #673

Merged
echelon merged 2 commits into
storytold:mainfrom
cyfung1031:fix/winit-4746-win-ime-cursor
Oct 10, 2026
Merged

echelon merged 2 commits into
storytold:mainfrom
cyfung1031:fix/winit-4746-win-ime-cursor

Conversation

@cyfung1031

@cyfung1031 cyfung1031 commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

With the Microsoft Korean IME on Windows, winit reports the composition's cursor at the start of the syllable (Ime::Preedit("한", Some((0, 0)))). egui 0.36.2 recognises that exact report on Windows and drops the range (a workaround in egui-winit), so PdfCraft shows no caret at all while Korean is being composed. With this change winit reports the cursor at the end (Some((3, 3))), and egui draws the caret after the syllable.

Port of rust-windowing/winit#4746 (reviewed head 3787f3d644) to the vendored winit 0.30.13. It is the same change.

PdfCraft impact

Korean composition in every egui text field on Windows: Search, form fields, the JavaScript console, comments.

Root cause

vendor/winit/src/platform_impl/windows/ime.rs, get_composing_text_and_cursor: when a composition has no target clause, winit calls ImmGetCompositionStringW(GCS_CURSORPOS) without checking that the WM_IME_COMPOSITION lParam has GCS_CURSORPOS set. The Microsoft Korean IME never sets it (lParam is 0x6018: GCS_COMPSTR | GCS_COMPATTR | CS_INSERTCHAR | CS_NOMOVECARET), so the read gives 0.

Change

WM_IME_COMPOSITION passes its lParam on. When there is no target clause, the cursor comes from GCS_CURSORPOS only if that flag is set; otherwise it goes at the end of the composition. Firefox reads the cursor the same way, and SDL fixed the same bug by putting it at the end.

IMEs that report a target clause or a cursor position (Japanese, Chinese) take the same path as before, and commits are unchanged.

Not included

Nothing else from winit master.

Verification

  • Upstream checked it on Windows 11 with the Microsoft Korean IME: 한 now gives Preedit("한", Some((3, 3))), 안녕 is the same per syllable, the Hanja candidate window opens at the caret, and commits are unchanged.
  • Not run here: this machine has no Windows. To check by hand: Windows 11, Microsoft Korean IME, type 한 / 안녕 / 한국어 in Search and in a form field. The caret should sit after the syllable being composed, with Japanese IME and Pinyin composing as before.
  • apps/pdfcraft/tests/winit_windows_ime_cursor.rs fails if a re-vendored winit reads GCS_CURSORPOS without the flag again.

Automated checks

  • The vendored winit built on its own for aarch64-apple-darwin, x86_64-pc-windows-msvc and x86_64-unknown-linux-musl (cargo clippy --lib, lints capped to warnings): the warnings are the same as on main for all three (the one existing clippy::iter_kv_map in linux/x11/event_processor.rs).
  • cargo check --locked -p winit inside the PdfCraft workspace, with PdfCraft's own Cargo.lock, on macOS and on the tree with all nine fixes merged: clean.
  • The new test was compiled and run against this branch (passes) and against main (fails); rustfmt --check and clippy -D warnings on it are clean.
  • Not run locally: the full cargo test --workspace and workspace clippy (the machine is short of disk space for a full build). CI runs them on Linux and Windows.

Risk

The change only affects compositions with no target clause whose IME doesn't set GCS_CURSORPOS: before, the cursor read as 0 (or as whatever ImmGetCompositionStringW returned); now it is at the end of the text. egui's workaround (egui-winit lib.rs, "Workaround for a bug on Windows where winit incorrectly reports the cursor position at the start of the preedit text") still applies to any IME that genuinely reports a cursor at 0; it no longer fires for the Microsoft Korean IME.

Revert and removal

This change is independent of the other winit PRs and can be reverted on its own. Drop it, together with the test and README item (3), once PdfCraft uses a winit release that includes rust-windowing/winit#4746 or an equivalent fix.

Merging alongside the other winit PRs

This is one of nine fixes to vendor/winit sent together: #672 (Wayland IME after a capability change), #673 (Windows Korean IME caret), #674 (Windows maximized start-up), #675 (X11 input context focus), #676 (macOS IME commit state), #677 (macOS stale composition), and, building on #676, #678 (macOS emoji picker), #679 (macOS Korean double space), #680 (macOS first Korean key). Each adds one numbered item to the single winit row in vendor/README.md, so they conflict with each other on that one line, and nowhere else (each test is in its own file). The item numbers (2)–(10) are fixed in advance: to resolve, keep every item in numeric order. All nine were merged locally in one tree (only that line conflicted); the combined vendored winit builds for macOS, Windows and Linux with the same clippy output as main, and all nine tests pass on it.

🤖 Generated with Claude Code

…nit#4746)

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>
@echelon
echelon merged commit 5437390 into storytold:main Oct 10, 2026
4 of 5 checks passed
@echelon

echelon commented Oct 10, 2026

Copy link
Copy Markdown
Member

Merged, thank you! Reading GCS_CURSORPOS only when Windows sets it (winit#4746) puts the Korean composition caret after the syllable. Patch (3).

If you haven't already, come join us on Discord: https://discord.gg/artcraft

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>
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.

2 participants