mirror of
https://github.com/emilk/egui.git
synced 2026-09-01 06:10:06 -04:00
Fix IME bug where currently typed characters got copied
* Closes #3730 Fix IME: Currently typed characters get copied when switching TextEdit fields
This commit is contained in:
@@ -940,6 +940,7 @@ fn events(
|
|||||||
if !text_mark.is_empty() {
|
if !text_mark.is_empty() {
|
||||||
text.insert_text_at(&mut ccursor, text_mark, char_limit);
|
text.insert_text_at(&mut ccursor, text_mark, char_limit);
|
||||||
}
|
}
|
||||||
|
state.ime_cursor_range = cursor_range;
|
||||||
Some(CCursorRange::two(start_cursor, ccursor))
|
Some(CCursorRange::two(start_cursor, ccursor))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
@@ -947,12 +948,16 @@ fn events(
|
|||||||
}
|
}
|
||||||
|
|
||||||
Event::CompositionEnd(prediction) => {
|
Event::CompositionEnd(prediction) => {
|
||||||
// CompositionEnd only characters may be typed into TextEdit without trigger CompositionStart first, so do not check `state.has_ime = true` in the following statement.
|
// CompositionEnd only characters may be typed into TextEdit without trigger CompositionStart first,
|
||||||
|
// so do not check `state.has_ime = true` in the following statement.
|
||||||
if prediction != "\n" && prediction != "\r" {
|
if prediction != "\n" && prediction != "\r" {
|
||||||
state.has_ime = false;
|
state.has_ime = false;
|
||||||
let mut ccursor = text.delete_selected(&cursor_range);
|
let mut ccursor;
|
||||||
if !prediction.is_empty() {
|
if !prediction.is_empty() && cursor_range == state.ime_cursor_range {
|
||||||
|
ccursor = text.delete_selected(&cursor_range);
|
||||||
text.insert_text_at(&mut ccursor, prediction, char_limit);
|
text.insert_text_at(&mut ccursor, prediction, char_limit);
|
||||||
|
} else {
|
||||||
|
ccursor = cursor_range.primary.ccursor;
|
||||||
}
|
}
|
||||||
Some(CCursorRange::one(ccursor))
|
Some(CCursorRange::one(ccursor))
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -44,6 +44,10 @@ pub struct TextEditState {
|
|||||||
#[cfg_attr(feature = "serde", serde(skip))]
|
#[cfg_attr(feature = "serde", serde(skip))]
|
||||||
pub(crate) has_ime: bool,
|
pub(crate) has_ime: bool,
|
||||||
|
|
||||||
|
// cursor range for IME candidate.
|
||||||
|
#[cfg_attr(feature = "serde", serde(skip))]
|
||||||
|
pub(crate) ime_cursor_range: CursorRange,
|
||||||
|
|
||||||
// Visual offset when editing singleline text bigger than the width.
|
// Visual offset when editing singleline text bigger than the width.
|
||||||
#[cfg_attr(feature = "serde", serde(skip))]
|
#[cfg_attr(feature = "serde", serde(skip))]
|
||||||
pub(crate) singleline_offset: f32,
|
pub(crate) singleline_offset: f32,
|
||||||
|
|||||||
Reference in New Issue
Block a user