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: A symptom of characters being copied when there are multiple TextEdits. #4374

Closed
wants to merge 9 commits into from
Closed
6 changes: 6 additions & 0 deletions crates/egui/src/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ use std::num::NonZeroU64;
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub struct Id(NonZeroU64);

impl Default for Id {
fn default() -> Self {
Self::NULL
}
}

impl Id {
/// A special [`Id`], in particular as a key to [`crate::Memory::data`]
/// for when there is no particular widget to attach the data.
Expand Down
2 changes: 2 additions & 0 deletions crates/egui/src/widgets/text_edit/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,7 @@ fn events(
Event::Ime(ime_event) => match ime_event {
ImeEvent::Enabled => {
state.ime_enabled = true;
state.ime_target_id = id;
state.ime_cursor_range = cursor_range;
None
}
Expand All @@ -1019,6 +1020,7 @@ fn events(
state.ime_enabled = false;

if !prediction.is_empty()
&& state.ime_target_id == id
&& cursor_range.secondary.ccursor.index
== state.ime_cursor_range.secondary.ccursor.index
{
Expand Down
4 changes: 4 additions & 0 deletions crates/egui/src/widgets/text_edit/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ pub struct TextEditState {
#[cfg_attr(feature = "serde", serde(skip))]
pub(crate) ime_enabled: bool,

// target TextEdit ID for IME candidate.
#[cfg_attr(feature = "serde", serde(skip))]
pub(crate) ime_target_id: Id,
Copy link
Owner

Choose a reason for hiding this comment

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

Won't this always be the same Id as the key used to find TextEditState?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it only stores TextEdit ID.
It's currently working fine without any problems.
If something is wrong or needs to be fixed, please fix it or let me know.

Copy link
Owner

Choose a reason for hiding this comment

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

That the code is working fine is not enough. I need to maintain this, and so I need to understand it. Storing the Id here makes no sense to me, since it is already the key.


// cursor range for IME candidate.
#[cfg_attr(feature = "serde", serde(skip))]
pub(crate) ime_cursor_range: CursorRange,
Expand Down
Loading