PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Merge PR #8119: Alt held during a drag is no menu-bar tap, so Enter commits Free Transform (#8113)
aionggdd21538cf5ec
diff --cc crates/ui-egui/src/menu_keys_tests.rsindex af1bb84d4,e026548b5..fc7264876--- a/crates/ui-egui/src/menu_keys_tests.rs+++ b/crates/ui-egui/src/menu_keys_tests.rs@@@ -306,53 -280,58 +306,109 @@@ fn every_menu_row_starts_its_label_afteout.textures_delta.clear();}+/// The whole app (shortcuts, dialogs and the menu bar), for keys other handlers see first.+fn whole_app() -> Harness<'static, PhotocraftApp> {+ let mut h = Harness::builder().with_size(egui::vec2(1280.0, 800.0)).with_max_steps(16).build_eframe(|cc| {+ PhotocraftApp::setup_context(&cc.egui_ctx, Default::default());+ app()+ });+ h.run_steps(4);+ h+}++/// `key` pressed and released with `mods` held, as the platform reports a chord.+fn chord(h: &mut Harness<'static, PhotocraftApp>, key: egui::Key, mods: egui::Modifiers) {+ h.event_modifiers(egui::Event::Key { key, physical_key: None, pressed: true, repeat: false, modifiers: mods }, mods);+ h.event_modifiers(egui::Event::Key { key, physical_key: None, pressed: false, repeat: false, modifiers: mods }, mods);+ h.run_steps(2);+}++fn alt_down(h: &mut Harness<'static, PhotocraftApp>, mods: egui::Modifiers) {+ h.event_modifiers(egui::Event::Key { key: egui::Key::AltLeft, physical_key: None, pressed: true, repeat: false, modifiers: mods }, mods);+ h.run_steps(2);+}++fn alt_up(h: &mut Harness<'static, PhotocraftApp>) {+ h.event_modifiers(+ egui::Event::Key { key: egui::Key::AltLeft, physical_key: None, pressed: false, repeat: false, modifiers: egui::Modifiers::NONE },+ egui::Modifiers::NONE,+ );+ h.run_steps(3);+}++/// #7481: Alt held through a shortcut is no tap, even when the shortcut consumed its key before+/// the bar saw it. Ctrl+Alt+I opens Image Size; releasing Alt leaves the keyboard where it was,+/// so Enter confirms the dialog instead of opening File. A lone tap still puts it on the bar.+#[test]+fn alt_held_through_a_shortcut_does_not_put_the_keyboard_on_the_bar() {+ let mut h = whole_app();+ alt_down(&mut h, egui::Modifiers::ALT);+ chord(&mut h, egui::Key::I, egui::Modifiers::CTRL | egui::Modifiers::ALT | egui::Modifiers::COMMAND);+ alt_up(&mut h);+ assert_eq!(h.state().ui.dialogs.len(), 1, "Image Size opened");+ assert_eq!(Keys::current(&h.ctx).focus, None, "the bar did not take the keyboard");+ h.key_press(egui::Key::Enter);+ h.run_steps(4);+ assert!(!is_open(&h.ctx), "Enter opened no menu");+ assert!(h.state().ui.dialogs.is_empty(), "Enter confirmed Image Size");++ alt_down(&mut h, egui::Modifiers::ALT);+ alt_up(&mut h);+ assert_eq!(Keys::current(&h.ctx).focus, Some(0), "a lone tap still focuses the bar");+}+++ /// #8113: Alt pressed during a drag (Free Transform's scale from the centre) is a modifier for the+ /// drag, not a tap: with the mouse button let go before or after Alt, the keyboard stays where+ /// it was, so Enter commits the transform instead of opening File. A lone tap still works.+ #[test]+ fn alt_held_during_a_drag_is_no_tap() {+ let mut h = bar();+ let at = egui::pos2(640.0, 400.0);+ let button = |h: &mut Harness<'static, PhotocraftApp>, pressed: bool, mods: egui::Modifiers| {+ h.event_modifiers(egui::Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed, modifiers: mods }, mods);+ h.run_steps(2);+ };+ for mouse_up_first in [true, false] {+ h.hover_at(at);+ button(&mut h, true, egui::Modifiers::NONE);+ h.key_down(egui::Key::AltLeft);+ h.run_steps(2);+ if mouse_up_first {+ button(&mut h, false, egui::Modifiers::ALT);+ h.key_up(egui::Key::AltLeft);+ } else {+ h.key_up(egui::Key::AltLeft);+ h.run_steps(2);+ button(&mut h, false, egui::Modifiers::NONE);+ }+ h.run_steps(3);+ assert_eq!(Keys::current(&h.ctx).focus, None, "mouse up first: {mouse_up_first}");+ key(&mut h, egui::Key::Enter);+ assert!(!is_open(&h.ctx), "Enter opens no menu (mouse up first: {mouse_up_first})");+ }+ // The whole gesture within one frame: press, Alt down, Alt up, release.+ let (alt, none) = (egui::Modifiers::ALT, egui::Modifiers::NONE);+ h.event_modifiers(egui::Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed: true, modifiers: none }, none);+ h.event_modifiers(egui::Event::Key { key: egui::Key::AltLeft, physical_key: None, pressed: true, repeat: false, modifiers: alt }, alt);+ h.event_modifiers(egui::Event::Key { key: egui::Key::AltLeft, physical_key: None, pressed: false, repeat: false, modifiers: none }, none);+ h.event_modifiers(egui::Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed: false, modifiers: none }, none);+ h.run_steps(3);+ assert_eq!(Keys::current(&h.ctx).focus, None, "one frame");+ // Two buttons: the right one let go while the left is still down. Alt pressed then is still+ // pressed during the left-button drag.+ let btn = |h: &mut Harness<'static, PhotocraftApp>, button: egui::PointerButton, pressed: bool| {+ h.event_modifiers(egui::Event::PointerButton { pos: at, button, pressed, modifiers: none }, none);+ h.run_steps(2);+ };+ btn(&mut h, egui::PointerButton::Primary, true);+ btn(&mut h, egui::PointerButton::Secondary, true);+ btn(&mut h, egui::PointerButton::Secondary, false);+ h.key_down(egui::Key::AltLeft);+ h.run_steps(2);+ h.key_up(egui::Key::AltLeft);+ h.run_steps(3);+ assert_eq!(Keys::current(&h.ctx).focus, None, "the left button is still down");+ btn(&mut h, egui::PointerButton::Primary, false);+ alt_tap(&mut h);+ assert!(Keys::current(&h.ctx).focus.is_some(), "a lone tap still focuses the bar");+ }