mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-04 19:41:36 -05:00
Tests: the palette, Cmd+Alt+L and Cmd+Alt+N cases tap their keys, a press and its release, as a keyboard does: the framework now reads a second press with no release between as a repeat
This commit is contained in:
@@ -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<egui::Event> {
|
||||
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();
|
||||
|
||||
@@ -360,8 +360,9 @@ fn cmd_alt_l_opens_new_layer_options() {
|
||||
// PLAN: assumed `Chord::parse(&str) -> Option<Chord>` 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.
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user