|
1 | | -use crate::action::exec_after; |
| 1 | +use crate::action::{exec_after, set_ime_allowed, set_ime_cursor_area}; |
2 | 2 | use crate::event::{EventListener, EventPropagation}; |
3 | 3 | use crate::id::ViewId; |
4 | 4 | use crate::keyboard::{self, KeyEvent, Modifiers}; |
@@ -134,7 +134,15 @@ pub fn text_input(buffer: RwSignal<String>) -> TextInput { |
134 | 134 | { |
135 | 135 | create_effect(move |_| { |
136 | 136 | let text = buffer.get(); |
137 | | - id.update_state((text, is_focused.get())); |
| 137 | + let is_focused = is_focused.get(); |
| 138 | + id.update_state((text, is_focused)); |
| 139 | + set_ime_allowed(is_focused); |
| 140 | + |
| 141 | + let rect = id.layout_rect(); |
| 142 | + set_ime_cursor_area( |
| 143 | + Point::new(rect.x0, rect.y0), |
| 144 | + id.get_size().unwrap_or(Size::ZERO), |
| 145 | + ); |
138 | 146 | }); |
139 | 147 | } |
140 | 148 |
|
@@ -881,7 +889,7 @@ impl TextInput { |
881 | 889 |
|
882 | 890 | // FIXME: any way to improve performance? |
883 | 891 | // but string commited by ime should be not too long, is it necessary to optimize? |
884 | | - (0.. ch.chars().count()).all(|_| self.move_cursor(Movement::Glyph, TextDirection::Right)) |
| 892 | + (0..ch.chars().count()).all(|_| self.move_cursor(Movement::Glyph, TextDirection::Right)) |
885 | 893 | } |
886 | 894 |
|
887 | 895 | fn move_selection( |
@@ -1109,7 +1117,13 @@ impl View for TextInput { |
1109 | 1117 | false |
1110 | 1118 | } |
1111 | 1119 | Event::KeyDown(event) => self.handle_key_down(cx, event), |
1112 | | - Event::ImeCommit(str) => self.insert_text(&SmolStr::from(str.as_str())), |
| 1120 | + Event::ImeCommit(str) => { |
| 1121 | + if self.is_focused { |
| 1122 | + self.insert_text(&SmolStr::from(str.as_str())) |
| 1123 | + } else { |
| 1124 | + false |
| 1125 | + } |
| 1126 | + } |
1113 | 1127 | _ => false, |
1114 | 1128 | }; |
1115 | 1129 |
|
|
0 commit comments