diff --git a/crates/ui-egui/src/shortcuts.rs b/crates/ui-egui/src/shortcuts.rs index 217b53c65..3c27eae2c 100644 --- a/crates/ui-egui/src/shortcuts.rs +++ b/crates/ui-egui/src/shortcuts.rs @@ -930,9 +930,16 @@ mod tests { assert!(wrong.is_empty(), "{wrong:#?}"); } - /// Ctrl and Ctrl+Alt chords that type no text still run their commands while the Type tool - /// edits, and with the Selection tool a Ctrl+Alt press runs its chord as before. Ctrl+L is New - /// Layer, and Ctrl+Alt+L is New Layer Options…, which opens Layer Options for a new layer. + /// What egui reports for the command key: Cmd on a Mac, Ctrl elsewhere. The keymap reads a + /// Mac's Ctrl as a key of its own, so Ctrl+L there is not Cmd+L. + fn command_key() -> Modifiers { + if crate::keymap::platform().is_mac() { Modifiers::MAC_CMD | Modifiers::COMMAND } else { Modifiers::CTRL | Modifiers::COMMAND } + } + + /// Ctrl and Ctrl+Alt chords (Cmd and Cmd+Alt on a Mac) that type no text still run their + /// commands while the Type tool edits, and with the Selection tool a Ctrl+Alt press runs its + /// chord as before. Ctrl+L is New Layer, and Ctrl+Alt+L is New Layer Options…, which opens + /// Layer Options for a new layer. #[test] fn ctrl_alt_chords_without_typed_text_still_run() { let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default()); @@ -944,20 +951,21 @@ mod tests { let layers = text_and_layers(&mut app, id).1; let new_layer_options = |app: &VectorcraftApp| app.ui.dialog.as_ref().is_some_and(|d| d.kind == "layerOptions" && d.fields.get("mode") == Some(&json!("new"))); - let m = Modifiers::COMMAND | Modifiers::CTRL; - let ctrl_l = egui::Event::Key { key: Key::L, physical_key: Some(Key::L), pressed: true, repeat: false, modifiers: m }; - frame(&mut app, vec![egui::Event::ModifiersChanged(m), ctrl_l]); + let m = command_key(); + frame(&mut app, press(Key::L, m)); assert_eq!(text_and_layers(&mut app, id), ("Hi".into(), layers + 1), "Ctrl+L while editing: New Layer"); assert!(app.ui.dialog.is_none(), "Ctrl+L opens no dialog"); app.select_tool("type"); app.session.apply_actions(vec![vectorcraft_tools::Action::Notify("text.editNew".into())]).unwrap(); assert!(app.session.tool_wants_text()); - frame(&mut app, ctrl_alt_press(Key::L, None)); + frame(&mut app, press(Key::L, m | Modifiers::ALT)); assert!(new_layer_options(&app), "Ctrl+Alt+L with no text typed while editing: New Layer Options…"); assert_eq!(text_and_layers(&mut app, id), ("Hi".into(), layers + 1), "no layer is added until OK"); crate::dialogs::cancel(&mut app); app.select_tool("selection"); - frame(&mut app, ctrl_alt_press(Key::L, Some("ł"))); + let mut typed = press(Key::L, m | Modifiers::ALT); + typed.push(egui::Event::Text("ł".into())); + frame(&mut app, typed); assert!(new_layer_options(&app), "Selection tool: Ctrl+Alt+L runs New Layer Options… as before"); assert_eq!(text_and_layers(&mut app, id), ("Hi".into(), layers + 1), "no layer is added until OK"); }