@@ -1872,13 +1872,15 @@ impl<'gc> EditText<'gc> {
1872
1872
let ImeData {
1873
1873
ime_start : old_ime_start,
1874
1874
ime_end : old_ime_end,
1875
+ ..
1875
1876
} = ime_data;
1876
1877
1877
1878
self . replace_text ( old_ime_start, old_ime_end, & text, context) ;
1878
1879
1879
1880
self . 0 . write ( context. gc ( ) ) . ime_data = Some ( ImeData {
1880
1881
ime_start : old_ime_start,
1881
1882
ime_end : old_ime_start + text. len ( ) ,
1883
+ text : text_utf8,
1882
1884
} ) ;
1883
1885
1884
1886
let new_selection = cursor. map ( |( from, to) | {
@@ -1904,13 +1906,17 @@ impl<'gc> EditText<'gc> {
1904
1906
let ime_data = ImeData {
1905
1907
ime_start : selection. start ( ) ,
1906
1908
ime_end : selection. start ( ) ,
1909
+ text : String :: new ( ) ,
1907
1910
} ;
1908
1911
write. ime_data = Some ( ime_data. clone ( ) ) ;
1909
1912
ime_data
1910
1913
}
1911
1914
1912
1915
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 {
1914
1920
return ;
1915
1921
} ;
1916
1922
@@ -1919,6 +1925,15 @@ impl<'gc> EditText<'gc> {
1919
1925
self . 0 . write ( context. gc ( ) ) . ime_data = None ;
1920
1926
}
1921
1927
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
+
1922
1937
/// Find the new position in the text for the given control code.
1923
1938
///
1924
1939
/// * For selection codes it will represent the "to" part of the selection.
@@ -3124,9 +3139,15 @@ impl<'gc> TInteractiveObject<'gc> for EditText<'gc> {
3124
3139
focused : bool ,
3125
3140
_other : Option < InteractiveObject < ' gc > > ,
3126
3141
) {
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
+ }
3130
3151
}
3131
3152
3132
3153
// Notify about IME
@@ -3655,4 +3676,5 @@ impl Default for EditTextStyleSheet<'_> {
3655
3676
struct ImeData {
3656
3677
ime_start : usize ,
3657
3678
ime_end : usize ,
3679
+ text : String ,
3658
3680
}
0 commit comments