Skip to content

Windows: fix UTF-16 IME cursor offsets around surrogate pairs - #4772

Merged
kchibisov merged 4 commits into
rust-windowing:masterfrom
William-Selna:fix/windows-ime-cursor-utf16
Oct 21, 2026
Merged

kchibisov merged 4 commits into
rust-windowing:masterfrom
William-Selna:fix/windows-ime-cursor-utf16

Conversation

@William-Selna

Copy link
Copy Markdown
Contributor

GCS_CURSORPOS counts UTF-16 units, but the Windows fallback counts Rust chars. For a😀b, offset 3 currently becomes byte 6 instead of 5.

Convert using UTF-16 units, round split-surrogate positions down, and clamp oversized offsets. Negative IMM results and clause selection are unchanged. Includes regression tests and a changelog entry.

Related: #4596 fixed the macOS conversion; #4201 fixed Windows clause attributes; #4746 handles a missing cursor-position flag. Neither Windows PR fixes this conversion.

Validation on Windows x64: both new tests fail with the old calculation and pass with the fix.

Convert GCS_CURSORPOS code units to UTF-8 byte offsets instead of
counting Unicode scalar values. Preserve negative-result handling
and clause selection; add regression coverage and a changelog entry.

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

You can use utf16_to_utf8_offset that is present on appkit(by copy it or putting into winit-common).

Move the existing AppKit conversion into winit-common::text and use it
from both backends. Move both backends' conversion regression tests
alongside the shared helper.

Validation: all eight shared tests pass on Linux; the common library
compiles with warnings denied. Native backend builds and nightly
formatting have not been run.
@William-Selna

Copy link
Copy Markdown
Contributor Author

Moved to widget-common , Windows and macOS both share utf16_to_utf8_offset

@kchibisov
kchibisov merged commit d559b05 into rust-windowing:master Oct 21, 2026
105 of 106 checks passed
@William-Selna
William-Selna deleted the fix/windows-ime-cursor-utf16 branch October 21, 2026 16:22
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.

2 participants