diff --git a/crates/ui-egui/src/palette.rs b/crates/ui-egui/src/palette.rs index 5c54be48bf..955b7b37a5 100644 --- a/crates/ui-egui/src/palette.rs +++ b/crates/ui-egui/src/palette.rs @@ -2299,9 +2299,11 @@ mod tests { time: f64, } - /// A press of `key` with no modifiers. - fn key(key: egui::Key) -> egui::Event { - egui::Event::Key { key, physical_key: None, pressed: true, repeat: false, modifiers: egui::Modifiers::NONE } + /// A tap of `key` with no modifiers, its press and its release: a second press with no release + /// between is a repeat. + fn key(key: egui::Key) -> Vec { + let event = |pressed| egui::Event::Key { key, physical_key: None, pressed, repeat: false, modifiers: egui::Modifiers::NONE }; + vec![event(true), event(false)] } impl Window { @@ -2355,9 +2357,9 @@ mod tests { self.frame(vec![]); self.frame(vec![egui::Event::Text(query.into())]); for _ in 0..down { - self.frame(vec![key(egui::Key::ArrowDown)]); + self.frame(key(egui::Key::ArrowDown)); } - self.frame(vec![key(egui::Key::Enter)]); + self.frame(key(egui::Key::Enter)); self.frame(vec![]); self.frame(vec![]); } @@ -2456,7 +2458,7 @@ mod tests { seen.push(built(&window)); window.frame(vec![egui::Event::Text("group".into())]); seen.push(built(&window)); - window.frame(vec![key(egui::Key::Enter)]); + window.frame(key(egui::Key::Enter)); window.frame(vec![]); seen.push(built(&window)); window.app.run("select.none", json!({})).unwrap(); diff --git a/crates/ui-egui/src/panels/layers/tests.rs b/crates/ui-egui/src/panels/layers/tests.rs index e34b3f8f2f..2ac1b0af3f 100644 --- a/crates/ui-egui/src/panels/layers/tests.rs +++ b/crates/ui-egui/src/panels/layers/tests.rs @@ -360,8 +360,9 @@ fn cmd_alt_l_opens_new_layer_options() { // PLAN: assumed `Chord::parse(&str) -> Option` and `Chord::to_egui_shortcut() -> egui::KeyboardShortcut`. let press = |app: &mut VectorcraftApp, chord: &str| { let shortcut = Chord::parse(chord).unwrap().to_egui_shortcut(); - let key = egui::Event::Key { key: shortcut.logical_key, physical_key: None, pressed: true, repeat: false, modifiers: shortcut.modifiers }; - crate::tests::synthetic::key_frame(app, &ctx, vec![key]); + let key = |pressed| egui::Event::Key { key: shortcut.logical_key, physical_key: None, pressed, repeat: false, modifiers: shortcut.modifiers }; + // A keyboard's tap: a second press with no release between is a repeat. + crate::tests::synthetic::key_frame(app, &ctx, vec![key(true), key(false)]); }; let open = |app: &VectorcraftApp| app.dialogs().map(|d| d.with(|host| host.open_dialogs())).unwrap_or_default(); // The window's first frame builds its keymap. diff --git a/crates/ui-egui/src/tests/home.rs b/crates/ui-egui/src/tests/home.rs index d6068f3b0d..37dfdcc8a5 100644 --- a/crates/ui-egui/src/tests/home.rs +++ b/crates/ui-egui/src/tests/home.rs @@ -85,8 +85,9 @@ fn cmd_alt_n_makes_a_document_without_the_new_document_dialog() { // The first frame of a context builds the keymap the key stage reads. crate::tests_synthetic::key_frame(app, &ctx, vec![]); let modifiers = egui::Modifiers::COMMAND | egui::Modifiers::ALT; - let ev = egui::Event::Key { key: egui::Key::N, physical_key: None, pressed: true, repeat: false, modifiers }; - crate::tests_synthetic::key_frame(app, &ctx, vec![ev]); + let ev = |pressed| egui::Event::Key { key: egui::Key::N, physical_key: None, pressed, repeat: false, modifiers }; + // A keyboard's tap: a second press with no release between is a repeat. + crate::tests_synthetic::key_frame(app, &ctx, vec![ev(true), ev(false)]); }; let made = |app: &VectorcraftApp| { let d = &app.session.active().expect("a document").doc;