Skip to content

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

Merge main into fix/6573-menubar-shortcut

David Mann23b94c6f543c
diff --cc crates/ui-egui/src/menu_keys_tests.rs
index 6b5aaa836,0298cb470..ef55d9ee7
--- a/crates/ui-egui/src/menu_keys_tests.rs
+++ b/crates/ui-egui/src/menu_keys_tests.rs
@@@ -211,28 -242,40 +242,66 @@@ fn the_shortcuts_wait_while_the_keyboar
assert_ne!(h.state().ui.tool, tool, "off the bar, E picks the Eraser again");
}
+/// The whole app: with the bar focused by an Alt tap, a command shortcut leaves the bar and runs
+/// in the same press (#6573); the bar's own keys still drive it.
+#[test]
+fn a_command_shortcut_leaves_the_bar_and_runs() {
+ let mut h = Harness::builder().with_size(egui::vec2(1280.0, 800.0)).with_max_steps(64).build_eframe(|cc| {
+ PhotocraftApp::setup_context(&cc.egui_ctx, Default::default());
+ let mut app = app();
+ app.services.native_menu = None;
+ app
+ });
+ h.run_steps(4);
+ h.state_mut().run("select.all", json!({})).unwrap();
+ h.run_steps(2);
+ alt_tap(&mut h);
+ assert_eq!(Keys::current(&h.ctx).focus, Some(0), "Alt puts the keyboard on File");
+ key(&mut h, egui::Key::ArrowRight);
+ assert_eq!(Keys::current(&h.ctx).focus, Some(1), "→ still moves along the bar");
+ assert!(h.state().session.active().unwrap().doc.selection.is_some());
+ h.key_press_modifiers(egui::Modifiers::COMMAND, egui::Key::D);
+ h.run_steps(3);
+ assert!(h.state().session.active().unwrap().doc.selection.is_none(), "⌘D deselects");
+ assert_eq!(Keys::current(&h.ctx).focus, None, "and takes the keyboard off the bar");
+ assert!(!crate::menu_keys::is_focused(&h.ctx));
+ assert!(!is_open(&h.ctx), "no menu opened");
+}
++
+ /// Checked, unchecked and plain rows (and submenu headers) start their label at the same x, in
+ /// any script: the checkmark column has a fixed width instead of padding characters (#5705).
+ #[test]
+ fn every_menu_row_starts_its_label_after_one_checkmark_column() {
+ let ctx = egui::Context::default();
+ let mut out = ctx.run_ui(Default::default(), |ui| {
+ let start = |checked: bool, label: &str, mnemonic: Option<char>| {
+ let galley = crate::menu_keys::menu_row_text(ui, checked, label, mnemonic).into_galley(
+ ui,
+ Some(egui::TextWrapMode::Extend),
+ f32::INFINITY,
+ egui::TextStyle::Button,
+ );
+ let first = label.chars().next().unwrap_or(' ');
+ let row = galley.rows.first().expect("one row");
+ let glyph = row.glyphs.iter().find(|g| g.chr == first).expect("the label's first glyph");
+ assert!(galley.text().ends_with(label), "the label is shown whole: {:?}", galley.text());
+ glyph.pos.x
+ };
+ let gutter = crate::menu_keys::check_gutter(ui);
+ assert!(gutter > 0.0, "the column has room for the mark");
+ for label in ["Lock Guides", "锁定参考线", "清除参考线"] {
+ let checked = start(true, label, None);
+ let unchecked = start(false, label, None);
+ assert!((checked - unchecked).abs() < 0.01, "{label}: checked {checked} vs unchecked {unchecked}");
+ assert!((unchecked - gutter).abs() < 1.0, "{label}: the label starts right after the column ({unchecked} vs {gutter})");
+ }
+ let underlined = start(false, "Clear Guides", Some('C'));
+ let plain = start(false, "Clear Guides", None);
+ assert!((underlined - plain).abs() < 0.01, "an underlined mnemonic doesn't move the label");
+ let underlined_mid = start(true, "Lock Guides", Some('G'));
+ assert!((underlined_mid - plain).abs() < 0.01, "nor a mnemonic after the first letter");
+ let t = crate::menu_keys::menu_row_text(ui, true, "Rulers", None);
+ assert_eq!(t.text(), "✔ Rulers", "a checked row keeps its mark (and its accessible label)");
+ });
+ out.textures_delta.clear();
+ }