PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Merge upstream main into fix/5863-cjk-menu-mnemonics
Higgs32584d0bff02d1737
diff --cc crates/ui-egui/src/menu_keys_tests.rsindex f4a8e4460,ef55d9ee7..458695b6d--- a/crates/ui-egui/src/menu_keys_tests.rs+++ b/crates/ui-egui/src/menu_keys_tests.rs@@@ -242,34 -242,32 +242,60 @@@ fn the_shortcuts_wait_while_the_keyboarassert_ne!(h.state().ui.tool, tool, "off the bar, E picks the Eraser again");}+/// #5863: a label with no Latin letter (Chinese, Japanese…) shows its English label's letter in+/// parentheses, before a trailing ellipsis, and takes it as its mnemonic; labels with letters and+/// the top menus' Photoshop letters are as before, and the letters stay unique.+#[test]+fn labels_without_latin_letters_show_their_english_key() {+ let labels: Vec<String> = ["文件", "编辑", "Image", "图层"].map(String::from).to_vec();+ let english = ["File", "Edit", "Image", "Layer"];+ let preferred = [Some('F'), Some('E'), Some('I'), Some('L')];+ let (shown, keys) = crate::menu_keys::localized(&labels, &english, &preferred);+ assert_eq!(shown, ["文件(F)", "编辑(E)", "Image", "图层(L)"]);+ assert_eq!(keys, [Some('F'), Some('E'), Some('I'), Some('L')]);+ // Rows: the key goes before the ellipsis; a clash takes the next letter of the shown label.+ let labels: Vec<String> = ["新建…", "打开...", "关闭"].map(String::from).to_vec();+ let (shown, keys) = crate::menu_keys::localized(&labels, &["New…", "Open...", "Close"], &[]);+ assert_eq!(shown, ["新建(N)…", "打开(O)...", "关闭(C)"]);+ assert_eq!(keys, [Some('N'), Some('O'), Some('C')]);+ let (shown, keys) = crate::menu_keys::localized(&["关闭".to_string(), "复制".to_string()], &["Close", "Copy"], &[]);+ assert_eq!(shown, ["关闭(C)", "复制(O)"]);+ assert_eq!(keys, [Some('C'), Some('O')]);+ // A shown "(C)" keeps its key even when a label with letters of its own comes first.+ let (shown, keys) = crate::menu_keys::localized(&["Copy".to_string(), "关闭".to_string()], &["Open", "Close"], &[]);+ assert_eq!(shown, ["Copy", "关闭(C)"]);+ assert_eq!(keys, [Some('O'), Some('C')]);+ // An English UI is unchanged.+ let labels: Vec<String> = ["File", "Edit"].map(String::from).to_vec();+ assert_eq!(crate::menu_keys::localized(&labels, &["File", "Edit"], &[Some('F'), Some('E')]).0, labels);+}++ /// 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]