Skip to content

Commit 9ccdecc

Browse files
committed
core: Commit pending IME text on losing focus
Flash commits the IME preedit text when losing focus.
1 parent 6954bb8 commit 9ccdecc

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

core/src/display_object/edit_text.rs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1872,13 +1872,15 @@ impl<'gc> EditText<'gc> {
18721872
let ImeData {
18731873
ime_start: old_ime_start,
18741874
ime_end: old_ime_end,
1875+
..
18751876
} = ime_data;
18761877

18771878
self.replace_text(old_ime_start, old_ime_end, &text, context);
18781879

18791880
self.0.write(context.gc()).ime_data = Some(ImeData {
18801881
ime_start: old_ime_start,
18811882
ime_end: old_ime_start + text.len(),
1883+
text: text_utf8,
18821884
});
18831885

18841886
let new_selection = cursor.map(|(from, to)| {
@@ -1904,13 +1906,17 @@ impl<'gc> EditText<'gc> {
19041906
let ime_data = ImeData {
19051907
ime_start: selection.start(),
19061908
ime_end: selection.start(),
1909+
text: String::new(),
19071910
};
19081911
write.ime_data = Some(ime_data.clone());
19091912
ime_data
19101913
}
19111914

19121915
fn ensure_ime_finished(self, context: &mut UpdateContext<'gc>) {
1913-
let Some(ImeData { ime_start, ime_end }) = self.0.read().ime_data else {
1916+
let Some(ImeData {
1917+
ime_start, ime_end, ..
1918+
}) = self.0.read().ime_data
1919+
else {
19141920
return;
19151921
};
19161922

@@ -1919,6 +1925,15 @@ impl<'gc> EditText<'gc> {
19191925
self.0.write(context.gc()).ime_data = None;
19201926
}
19211927

1928+
fn ensure_ime_committed(self, context: &mut UpdateContext<'gc>) {
1929+
let Some(ImeData { text, .. }) = self.0.read().ime_data.clone() else {
1930+
return;
1931+
};
1932+
1933+
self.ensure_ime_finished(context);
1934+
self.text_input(text, context);
1935+
}
1936+
19221937
/// Find the new position in the text for the given control code.
19231938
///
19241939
/// * For selection codes it will represent the "to" part of the selection.
@@ -3124,9 +3139,15 @@ impl<'gc> TInteractiveObject<'gc> for EditText<'gc> {
31243139
focused: bool,
31253140
_other: Option<InteractiveObject<'gc>>,
31263141
) {
3127-
let is_avm1 = !self.movie().is_action_script_3();
3128-
if !focused && is_avm1 {
3129-
self.set_selection(None, context.gc());
3142+
if !focused {
3143+
// Commit IME on focus lost.
3144+
self.ensure_ime_committed(context);
3145+
3146+
let is_avm1 = !self.movie().is_action_script_3();
3147+
if is_avm1 {
3148+
// Clear selection on focus lost in AVM1 only.
3149+
self.set_selection(None, context.gc());
3150+
}
31303151
}
31313152

31323153
// Notify about IME
@@ -3655,4 +3676,5 @@ impl Default for EditTextStyleSheet<'_> {
36553676
struct ImeData {
36563677
ime_start: usize,
36573678
ime_end: usize,
3679+
text: String,
36583680
}

0 commit comments

Comments
 (0)