emilk / emilk/egui

[IME] Can't input CompositionEnd only characters because of checking ccursor.index and ime_cursor.index

Open
#4,486 2 comments 1 reaction 0 assignees View on GitHub
bug
Dominant language
Rust
Stars
30.6k
Forks
2.1k
Avg merge
1d 9h
Merged PRs (30d)
72

Description

**Describe the bug**
Sometimes can not type IME CompositionEnd characters.

**To Reproduce**
Use 'PinYin' input, type some words, then type in some other character such as `【 】 …… `

**Expected behavior**
Type in any characters, including CompositionEnd characters.

**Screenshots**

https://github.com/emilk/egui/assets/16380650/fe9c1e7a-c665-4726-bf08-081b8c7c0c41

![IME-BUG2](https://github.com/emilk/egui/assets/16380650/67c388f6-6e3b-4815-a61d-a77bdac591ad)

After typing `!@`, can not type any CompositionEnd character like `【】。,;`。

![IME-BUG3](https://github.com/emilk/egui/assets/16380650/c2a451e0-161b-42e1-87e3-2ee90c6ee2b5)
![IME-BUG1](https://github.com/emilk/egui/assets/16380650/d5c7bd5b-7d2a-427f-abc4-0f04fa194b90)

I'm using version 0.27.2, i see branch `master` has changed `CompositionEnd` to `ImeEvent::Commit`, but this bug still exists.
Here is why this happens.
`/crates/egui/src/widgets/text_edit/builder.rs` L974
`if !prediction.is_empty() && cursor_range.secondary.ccursor.index == state.ime_cursor_range.secondary.ccursor.index`
this prediction make sure `cursor_range.secondary.ccursor.index` equals `state.ime_cursor_range.secondary.ccursor.index` .
but when input CompositionEnd only characters after some other characters, `cursor_range.secondary.ccursor.index` is equals to the length of previous characters, and `state.ime_cursor_range.secondary.ccursor.index` equals to `0`.

Below is my solution:
![IME-BUGFIX2](https://github.com/emilk/egui/assets/16380650/8754bc8c-9146-42b4-80de-6eec630eccc1)
![IME-BUGFIX1](https://github.com/emilk/egui/assets/16380650/3dfc587b-08be-4705-ade9-8e4f6b598c4e)

https://github.com/emilk/egui/assets/16380650/6e2d7733-cea6-49e5-89ce-fd74e04963bc

If we check this two `cursors.index` only when ime_state equals true which meanings we triggered `CompositionStart` first and currently continue typing some `IME` characters. if we trigger `CompositionEnd` first, there is no need to check `cursor.index`.

Actually, i don't know why need to check `cursor_range.secondary.ccursor.index == state.ime_cursor_range.secondary.ccursor.index`, can you tell me the reason. Thanks 😊

**Desktop (please complete the following information):**
- OS: Windows11

Contributor guide

Open the contributing guide

Research direction

Start in crates/egui/src/widgets/text_edit/builder.rs around line 974 and reproduce the issue on Windows 11 with PinYin input, typing ordinary characters followed by CompositionEnd characters such as 【】。,;. Trace why the cursor indices differ after CompositionEnd input, then verify that all described characters can be entered without breaking ongoing IME composition.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
desktop, internationalization
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.