mirror of
https://github.com/storytold/effectcraft.git
synced 2026-10-31 05:27:08 -06:00
#2459: test the text-field Undo and Redo labels in the native Edit menu
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RDvxCS8xcR28VArjzn1x7U
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user