From 97df62547b2b8e2d4ebe84d9695983fe93f250f0 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 6 Nov 2026 23:17:56 -0800 Subject: [PATCH] Tests: the hex paste dialog tests release Enter after each press A dialog's OK ignores a repeat of Enter, and an egui context keeps a key down until it is released. The Color Picker, Swatch Options and Define Grid tests pressed Enter in one context without releasing it, so every press after the first was a repeat and the dialog stayed open. Each test now releases Enter after pressing it. --- crates/ui-egui/src/dialogs/tests.rs | 4 ++++ crates/ui-egui/src/dialogs/tests_perspective.rs | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/dialogs/tests.rs b/crates/ui-egui/src/dialogs/tests.rs index bdc4f0b44..555b21d1f 100644 --- a/crates/ui-egui/src/dialogs/tests.rs +++ b/crates/ui-egui/src/dialogs/tests.rs @@ -978,6 +978,8 @@ fn a_hex_code_pasted_into_the_hex_field_replaces_its_digits() { texts }; let key = |key| egui::Event::Key { key, physical_key: None, pressed: true, repeat: false, modifiers: Default::default() }; + // The context keeps a key down until it is let go, and a dialog ignores a repeat of Enter. + let release = |key| egui::Event::Key { key, physical_key: None, pressed: false, repeat: false, modifiers: Default::default() }; let button = |pos, pressed| egui::Event::PointerButton { pos, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() }; type Open = fn(&mut VectorcraftApp); type Applied = fn(&VectorcraftApp) -> String; @@ -1024,6 +1026,7 @@ fn a_hex_code_pasted_into_the_hex_field_replaces_its_digits() { let shows = frame(&mut app, vec![egui::Event::Paste(paste.into())]); assert!(shows.iter().any(|(t, _)| t == hex), "{name}: the # field keeps {hex} after pasting {paste:?}"); frame(&mut app, vec![key(egui::Key::Enter)]); + frame(&mut app, vec![release(egui::Key::Enter)]); assert!(app.ui.dialog.is_none(), "{name}: Enter closes the dialog after pasting {paste:?}"); assert_eq!(applied(&app), before, "{name}: pasting {paste:?} changes no color"); } @@ -1050,6 +1053,7 @@ fn a_hex_code_pasted_into_the_hex_field_replaces_its_digits() { click_in(&mut app); frame(&mut app, vec![egui::Event::Paste(paste.into())]); frame(&mut app, vec![key(egui::Key::Enter)]); + frame(&mut app, vec![release(egui::Key::Enter)]); assert!(app.ui.dialog.is_none(), "{name}: Enter closes the dialog after pasting {paste:?}"); assert_eq!(applied(&app), "#00ff00", "{name}: Enter applies {paste:?}"); app.run("swatch.edit", json!({"name": "Sky", "color": "#3366cc"})).unwrap(); diff --git a/crates/ui-egui/src/dialogs/tests_perspective.rs b/crates/ui-egui/src/dialogs/tests_perspective.rs index f83613913..97255bd22 100644 --- a/crates/ui-egui/src/dialogs/tests_perspective.rs +++ b/crates/ui-egui/src/dialogs/tests_perspective.rs @@ -94,7 +94,8 @@ fn define_grid_takes_a_three_digit_color() { texts }; let button = |pos, pressed| egui::Event::PointerButton { pos, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() }; - let enter = egui::Event::Key { key: egui::Key::Enter, physical_key: None, pressed: true, repeat: false, modifiers: Default::default() }; + // The context keeps a key down until it is let go, and a dialog ignores a repeat of Enter. + let enter = |pressed| egui::Event::Key { key: egui::Key::Enter, physical_key: None, pressed, repeat: false, modifiers: Default::default() }; for (how, input) in [("pasted", egui::Event::Paste("0f0".into())), ("typed", egui::Event::Text("0f0".into()))] { app.run("ui.perspectiveGridDialog", json!({})).unwrap(); set(&mut app, "leftColor", json!("#123456")); @@ -107,7 +108,8 @@ fn define_grid_takes_a_three_digit_color() { frame(&mut app, vec![button(at, false)]); frame(&mut app, vec![]); frame(&mut app, vec![input]); - frame(&mut app, vec![enter.clone()]); + frame(&mut app, vec![enter(true)]); + frame(&mut app, vec![enter(false)]); assert_eq!(kind(&app), None, "{how}: Enter closes the dialog"); assert_eq!(grid(&app).left_color.hex(), "#00ff00", "{how}: the grid takes the color"); }