Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix IME input of CompositionEnd without a CompositionStart #3768

Merged
merged 2 commits into from
Jan 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion crates/egui/src/widgets/text_edit/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1050,7 +1050,8 @@ fn events(
}

Event::CompositionEnd(prediction) => {
if prediction != "\n" && prediction != "\r" && state.has_ime {
// CompositionEnd only characters may be typed into TextEdit without trigger CompositionStart first, so do not check `state.has_ime = true` in the following statement.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it still correct to check it for Event::CompositionUpdate above?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This page show that compositionstart could be fired after a user starts entering a Chinese character using a Pinyin, so when entering some word except compositionend character, componentstart fires and state.has_ime will always be true, and compositionupdate will work well. so it's still correct to check it for compositionupdate because state.has_ime is always true when entring word.

I have test the situation that remove all state.has_ime in CompositionStart, CompositionUpdate,CompositionEnd, it works well.

Also, state.has_ime is a variable that indicating current input state, maybe some other features will use this variable, so i think keep this variable is a good choice, although it seems useless at current time.

if prediction != "\n" && prediction != "\r" {
state.has_ime = false;
let mut ccursor = delete_selected(text, &cursor_range);
if !prediction.is_empty() {
Expand Down