Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

Menu bar: releasing Alt after Alt+scroll no longer focuses the bar, so Space can't run File > New

artman67c4de02978b23
diff --git a/crates/ui-egui/src/menu_keys.rs b/crates/ui-egui/src/menu_keys.rs
index 5762b2a94..7260ef538 100644
--- a/crates/ui-egui/src/menu_keys.rs
+++ b/crates/ui-egui/src/menu_keys.rs
@@ -173,7 +173,12 @@ impl Keys {
self.alt_down = false;
tap |= std::mem::take(&mut self.alt_tap);
}
- Event::Key { pressed: true, .. } | Event::Text(_) | Event::PointerButton { pressed: true, .. } => self.alt_tap = false,
+ // Alt+wheel (zoom, brush size…) or Alt going to the desktop is no tap either.
+ Event::Key { pressed: true, .. }
+ | Event::Text(_)
+ | Event::PointerButton { pressed: true, .. }
+ | Event::MouseWheel { .. }
+ | Event::WindowFocused(false) => self.alt_tap = false,
_ => {}
}
}
diff --git a/crates/ui-egui/src/menu_keys_tests.rs b/crates/ui-egui/src/menu_keys_tests.rs
index 1f226054e..632d6d6cf 100644
--- a/crates/ui-egui/src/menu_keys_tests.rs
+++ b/crates/ui-egui/src/menu_keys_tests.rs
@@ -76,6 +76,37 @@ fn alt_focuses_the_bar_arrows_move_and_down_opens_the_lit_menu() {
assert!(!is_open(&h.ctx) && Keys::current(&h.ctx).focus.is_none(), "Esc leaves the menu and the bar");
}
+/// Alt+wheel zooms; letting go of Alt after it is no tap, so Space (the hand tool) can't then
+/// open File and run New….
+#[test]
+fn alt_with_a_wheel_scroll_or_a_lost_focus_is_no_tap() {
+ let mut h = bar();
+ h.key_down(egui::Key::AltLeft);
+ h.run_steps(2);
+ h.event_modifiers(
+ egui::Event::MouseWheel {
+ unit: egui::MouseWheelUnit::Line,
+ delta: egui::vec2(0.0, -1.0),
+ phase: egui::TouchPhase::Move,
+ modifiers: egui::Modifiers::ALT,
+ },
+ egui::Modifiers::ALT,
+ );
+ h.run_steps(2);
+ h.key_up(egui::Key::AltLeft);
+ h.run_steps(3);
+ assert_eq!(Keys::current(&h.ctx).focus, None, "Alt+scroll leaves the bar alone");
+ key(&mut h, egui::Key::Space);
+ assert!(!is_open(&h.ctx), "Space opens no menu");
+ h.key_down(egui::Key::AltLeft);
+ h.run_steps(2);
+ h.event(egui::Event::WindowFocused(false));
+ h.event(egui::Event::WindowFocused(true));
+ h.key_up(egui::Key::AltLeft);
+ h.run_steps(3);
+ assert_eq!(Keys::current(&h.ctx).focus, None, "Alt that went to the desktop leaves the bar alone");
+}
+
#[test]
fn a_second_alt_or_esc_or_a_click_takes_the_keyboard_off_the_bar() {
let mut h = bar();