EffectCraft: An open-source motion graphics and compositing tool written by scratch in pure Rust
#2459: test the text-field Undo and Redo labels in the native Edit menu
Claude6a8e28126ed5
diff --git a/crates/ui-egui/src/native_menu.rs b/crates/ui-egui/src/native_menu.rsindex 6fbbdad9a..e89aae5c9 100644--- a/crates/ui-egui/src/native_menu.rs+++ b/crates/ui-egui/src/native_menu.rs@@ -745,4 +745,41 @@ mod tests {assert!(edits_text("edit.copy") && edits_text("edit.paste"));assert!(!edits_text("layer.newNull"));}+ /// #2459: while a text field has the keyboard the Edit menu's Undo and Redo act on the field and+ /// read plain "Undo" / "Redo"; the project history labels come back once focus leaves.+ #[test]+ fn a_focused_text_field_gets_plain_undo_and_redo_labels() {+ fn label(menu: &NativeMenu, id: &str) -> String {+ menu.items().into_iter().find(|i| i.command == id).map(|i| i.label.to_string()).unwrap_or_default()+ }+ let mut app = app();+ app.session.execute("layer.newNull", json!({})).unwrap();+ app.session.execute("layer.newNull", json!({})).unwrap();+ app.session.execute("edit.undo", json!({})).unwrap();+ let ctx = egui::Context::default();+ let history = label(&build_now(&app, &ctx), "edit.undo");+ let redo_history = label(&build_now(&app, &ctx), "edit.redo");+ assert!(history.starts_with("Undo") && history != "Undo", "{history}");+ assert!(redo_history.starts_with("Redo") && redo_history != "Redo", "{redo_history}");+ let mut text = String::new();+ let mut id = None;+ for _ in 0..2 {+ let mut out = ctx.run_ui(egui::RawInput::default(), |ui| {+ let r = ui.text_edit_singleline(&mut text);+ r.request_focus();+ id = Some(r.id);+ });+ out.textures_delta.clear();+ }+ assert!(text_field_window(&ctx).is_some());+ let typing = build_now(&app, &ctx);+ assert_eq!(label(&typing, "edit.undo"), "Undo");+ assert_eq!(label(&typing, "edit.redo"), "Redo");+ assert!(typing.items().into_iter().any(|i| i.command == "edit.undo" && i.enabled));+ ctx.memory_mut(|m| m.surrender_focus(id.unwrap_or(egui::Id::NULL)));+ assert!(text_field_window(&ctx).is_none());+ let after = build_now(&app, &ctx);+ assert_eq!(label(&after, "edit.undo"), history);+ assert_eq!(label(&after, "edit.redo"), redo_history);+ }}