From 5961eb8f6c65994d155a5c9852d2b496925a1d9e Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Thu, 1 Aug 2024 19:58:37 +0900 Subject: [PATCH 1/7] Update builder.rs --- crates/egui/src/widgets/text_edit/builder.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/crates/egui/src/widgets/text_edit/builder.rs b/crates/egui/src/widgets/text_edit/builder.rs index 86d281256b7..15c3d4368a9 100644 --- a/crates/egui/src/widgets/text_edit/builder.rs +++ b/crates/egui/src/widgets/text_edit/builder.rs @@ -746,6 +746,10 @@ impl<'t> TextEdit<'t> { } } + if state.ime_enabled && response.lost_focus() { + state.ime_enabled = false; + } + state.clone().store(ui.ctx(), id); if response.changed { From b277d39d3e1c227431da47a0eb8f530c4fa133b2 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sat, 3 Aug 2024 20:37:32 +0900 Subject: [PATCH 2/7] Update builder.rs --- crates/egui/src/widgets/text_edit/builder.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/egui/src/widgets/text_edit/builder.rs b/crates/egui/src/widgets/text_edit/builder.rs index 15c3d4368a9..5524dafbe33 100644 --- a/crates/egui/src/widgets/text_edit/builder.rs +++ b/crates/egui/src/widgets/text_edit/builder.rs @@ -1005,6 +1005,8 @@ fn events( if text_mark == "\n" || text_mark == "\r" { None } else { + state.ime_enabled = false; + // Empty prediction can be produced when user press backspace // or escape during IME, so we clear current text. let mut ccursor = text.delete_selected(&cursor_range); From 07e8de267d80bf6dcd922611d384e1543dba801c Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sat, 3 Aug 2024 21:54:12 +0900 Subject: [PATCH 3/7] Update builder.rs --- crates/egui/src/widgets/text_edit/builder.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/crates/egui/src/widgets/text_edit/builder.rs b/crates/egui/src/widgets/text_edit/builder.rs index 5524dafbe33..15c3d4368a9 100644 --- a/crates/egui/src/widgets/text_edit/builder.rs +++ b/crates/egui/src/widgets/text_edit/builder.rs @@ -1005,8 +1005,6 @@ fn events( if text_mark == "\n" || text_mark == "\r" { None } else { - state.ime_enabled = false; - // Empty prediction can be produced when user press backspace // or escape during IME, so we clear current text. let mut ccursor = text.delete_selected(&cursor_range); From 81ef0bfb96cbe467d4e4290434057b07203a46ab Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sun, 4 Aug 2024 18:55:01 +0900 Subject: [PATCH 4/7] Update builder.rs --- crates/egui/src/widgets/text_edit/builder.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/crates/egui/src/widgets/text_edit/builder.rs b/crates/egui/src/widgets/text_edit/builder.rs index 15c3d4368a9..798161a79f8 100644 --- a/crates/egui/src/widgets/text_edit/builder.rs +++ b/crates/egui/src/widgets/text_edit/builder.rs @@ -748,6 +748,10 @@ impl<'t> TextEdit<'t> { if state.ime_enabled && response.lost_focus() { state.ime_enabled = false; + if let Some(mut ccursor_range) = state.cursor.char_range() { + ccursor_range.secondary.index = ccursor_range.primary.index; + state.cursor.set_char_range(Some(ccursor_range)); + } } state.clone().store(ui.ctx(), id); From 104bef219a814e0c6a2e7d0aa5188484b450ec26 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sun, 4 Aug 2024 20:02:25 +0900 Subject: [PATCH 5/7] Update builder.rs --- crates/egui/src/widgets/text_edit/builder.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/egui/src/widgets/text_edit/builder.rs b/crates/egui/src/widgets/text_edit/builder.rs index 798161a79f8..4cf3a2cde4b 100644 --- a/crates/egui/src/widgets/text_edit/builder.rs +++ b/crates/egui/src/widgets/text_edit/builder.rs @@ -746,12 +746,14 @@ impl<'t> TextEdit<'t> { } } + // IME-related processing when focus is lost in IME enabled state. if state.ime_enabled && response.lost_focus() { state.ime_enabled = false; if let Some(mut ccursor_range) = state.cursor.char_range() { ccursor_range.secondary.index = ccursor_range.primary.index; state.cursor.set_char_range(Some(ccursor_range)); } + ui.input_mut(|i| i.events.retain(|e| !matches!(e, Event::Ime(_)))); } state.clone().store(ui.ctx(), id); From bb0dfe4bf08a6fb294ca4d150bdfd82a1c57c8b0 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Tue, 27 Aug 2024 16:50:11 +0900 Subject: [PATCH 6/7] Update builder.rs --- crates/egui/src/widgets/text_edit/builder.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/egui/src/widgets/text_edit/builder.rs b/crates/egui/src/widgets/text_edit/builder.rs index 4cf3a2cde4b..2ae6a4ee79c 100644 --- a/crates/egui/src/widgets/text_edit/builder.rs +++ b/crates/egui/src/widgets/text_edit/builder.rs @@ -746,8 +746,8 @@ impl<'t> TextEdit<'t> { } } - // IME-related processing when focus is lost in IME enabled state. - if state.ime_enabled && response.lost_focus() { + // IME-related processing when focus is gained or lost in IME enabled state. + if state.ime_enabled && (response.gained_focus() || response.lost_focus()) { state.ime_enabled = false; if let Some(mut ccursor_range) = state.cursor.char_range() { ccursor_range.secondary.index = ccursor_range.primary.index; From 6ef2ef55c4e662762d47ca6639fed5a522cc1159 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Tue, 27 Aug 2024 18:03:53 +0900 Subject: [PATCH 7/7] Update builder.rs --- crates/egui/src/widgets/text_edit/builder.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/egui/src/widgets/text_edit/builder.rs b/crates/egui/src/widgets/text_edit/builder.rs index b432e88d12e..9552275a038 100644 --- a/crates/egui/src/widgets/text_edit/builder.rs +++ b/crates/egui/src/widgets/text_edit/builder.rs @@ -746,7 +746,7 @@ impl<'t> TextEdit<'t> { } } - // IME-related processing when focus is gained or lost in IME enabled state. + // Ensures correct IME behavior when the text input area gains or loses focus. if state.ime_enabled && (response.gained_focus() || response.lost_focus()) { state.ime_enabled = false; if let Some(mut ccursor_range) = state.cursor.char_range() {