FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust
Type text committed by an input method into text layers on the monitor (#1083)
MarekSpodBiedryadefe9c3fd83
diff --git a/crates/ui-egui/src/panels/graphics.rs b/crates/ui-egui/src/panels/graphics.rsindex 7cf5f47b3..b1df16dba 100644--- a/crates/ui-egui/src/panels/graphics.rs+++ b/crates/ui-egui/src/panels/graphics.rs@@ -1012,7 +1012,8 @@ fn text_edit(app: &mut FilmcraftApp, ui: &mut egui::Ui, v: &LayerView, mut ed: G};for ev in events {match ev {- egui::Event::Text(s) | egui::Event::Paste(s) => {+ // an input method (Chinese, Japanese, Korean) hands over its finished text as a commit (#1083)+ egui::Event::Text(s) | egui::Event::Paste(s) | egui::Event::Ime(egui::ImeEvent::Commit(s)) => {let s: String = s.chars().filter(|c| !c.is_control() || *c == '\n').collect();if s.is_empty() {continue;diff --git a/crates/ui-egui/tests/graphics_handles_ui.rs b/crates/ui-egui/tests/graphics_handles_ui.rsindex b29aa89bb..a417d8111 100644--- a/crates/ui-egui/tests/graphics_handles_ui.rs+++ b/crates/ui-egui/tests/graphics_handles_ui.rs@@ -330,6 +330,24 @@ fn type_tool_drag_makes_paragraph_text_and_a_click_point_text() {assert_eq!(list["layers"][1]["box"], json!(null));}+/// Chinese, Japanese and Korean input methods hand over the finished text as `Ime(Commit)`, not+/// `Text`; it is typed into the text being edited on the monitor (#1083).+#[test]+fn text_committed_by_an_input_method_is_typed_on_the_monitor() {+ let mut d = Driver::new();+ d.ok("ui.set", json!({"tool": "Type"}));+ d.frames(3);+ let pic = d.rect("program.picture");+ d.ok("ui.click", json!({"x": pic[0] + pic[2] * 0.3, "y": pic[1] + pic[3] * 0.2}));+ d.ok("ui.type", json!({"text": "A"}));+ // the events Microsoft Pinyin sends for "ni hao" picked as 你好+ let preedit = |text: &str| egui::Event::Ime(egui::ImeEvent::Preedit { text: text.into(), active_range_chars: None });+ d.harness.input_mut().events.extend([preedit("ni hao"), preedit(""), egui::Event::Ime(egui::ImeEvent::Commit("你好".into()))]);+ d.frames(4);+ let list = d.exec("graphics.list", json!({}));+ assert_eq!(list["layers"][0]["text"], "A你好");+}+#[test]fn text_properties_switches_between_point_and_paragraph_text() {let mut d = Driver::new();