mirror of
https://github.com/emilk/egui.git
synced 2026-06-26 22:53:14 -04:00
May close #8087, but cannot test macOS builtin Japanese IME. ## Summary PR #8031 (harfrust text shaping) introduced a regression: when harfrust shapes multi-codepoint clusters (flag emojis, ligatures, combining marks) into fewer glyphs than input characters, the invariant `glyphs.len() == char_count` breaks. This causes IME composition to duplicate characters and text selection to behave incorrectly. ## Fix In `layout_shaped_run()`, after emitting shaped glyphs for a cluster, we now check if the cluster had more characters than glyphs. If so, zero-width "continuation" glyphs are emitted for the extra characters, restoring the 1:1 glyph-to-character mapping. Continuation glyphs have `UvRect::default()` (`is_nothing() == true`), so `tessellate_glyphs` skips them entirely. Background, underline, and strikethrough rendering handle zero-width glyphs naturally. Only `crates/epaint/src/text/text_layout.rs` is modified. No changes to cursor logic, selection code, or public API. ## Test plan - [x] `cargo fmt --all -- --check` - [x] `cargo clippy -p epaint --tests` - [x] `cargo test -p epaint -p egui` (all pass) - [x] New test `test_grapheme_cluster_glyph_count`: verifies glyph count == char count for flag emojis, combining marks, and plain ASCII - [x] New test `test_grapheme_cluster_cursor_roundtrip`: verifies cursor position stability through `pos_from_cursor` -> `cursor_from_pos` round-trips on text containing flag emojis - [x] Manual testing with demo app: selection and cursor navigation work correctly on `A🇯🇵B` - [ ] IME testing (macOS Japanese IME) needs to be validated by someone on macOS --- **This PR was developed with the assistance of Claude Code.** --------- Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>