SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Browser menus: V runs the open menu's Show/Hide on the row it was opened for (#8377)
MarkusRe05f62b09e0a6
diff --git a/crates/ui-egui/src/context_menu.rs b/crates/ui-egui/src/context_menu.rsindex c982e9126e..600057f739 100644--- a/crates/ui-egui/src/context_menu.rs+++ b/crates/ui-egui/src/context_menu.rs@@ -1624,6 +1624,22 @@ pub fn delete(app: &mut SolveApp) {crate::delete::delete_selection(app);}+/// A shortcut key pressed while a menu is open: the row of that menu showing `key` runs on the+/// menu's target, as a click on it would, and the menu closes. A folder, the Origin folder or an+/// origin plane is not selected by the right-click that opens its menu, so the key's own action+/// (V on the selection) would miss it. Returns whether the open menu has a row for the key; a+/// disabled row takes the key and does nothing, as a click on it does.+pub fn press_shortcut(app: &mut SolveApp, key: &str) -> bool {+ let Some(at) = app.viewport.context_menu else { return false };+ let target = app.menu.target.clone();+ let Some(item) = items(app, &target).into_iter().find(|i| i.shortcut == key && i.children.is_empty()) else { return false };+ if item.enabled {+ close(app);+ run_item(app, &item, at);+ }+ true+}+/// Show/Hide (the V key): what is selected in the viewport or picked in the browser flips its/// visibility (bodies, faces' and edges' bodies, sketches, construction and origin planes and/// axes, components' bodies, canvases, joints' glyphs). When some are shown and some hidden, all are hidden.diff --git a/crates/ui-egui/src/menu_tests.rs b/crates/ui-egui/src/menu_tests.rsindex db61f00f87..2251598a60 100644--- a/crates/ui-egui/src/menu_tests.rs+++ b/crates/ui-egui/src/menu_tests.rs@@ -914,6 +914,50 @@ fn v_toggles_what_is_selected() {assert_eq!(find(&context_menu::items(&app, &Target::Body { name: body(&app) }), "Show/Hide").shortcut, "V");}+/// V pressed with a browser menu open runs that menu's Show/Hide, as its row says, on the row+/// the menu was opened for: a folder, the Origin folder or an origin plane is not selected by+/// the right-click, so V used to act on the selection instead (nothing, or another body).+#[test]+fn v_with_a_menu_open_shows_or_hides_what_the_menu_is_for() {+ let mut h = crate::scenario::Harness::new();+ h.app.run("solid.box", json!({"length": 10, "width": 20, "height": 30})).unwrap();+ let b = body(&h.app);+ let press_v = |h: &mut crate::scenario::Harness| {+ for pressed in [true, false] {+ h.app.synthetic.push(egui::Event::Key { key: egui::Key::V, physical_key: None, pressed, repeat: false, modifiers: Default::default() });+ }+ while !h.app.synthetic.is_empty() {+ h.frame();+ }+ h.frames(2);+ };+ let open = |h: &mut crate::scenario::Harness, target: Target| {+ context_menu::open_for(&mut h.app, pos2(300.0, 200.0), target);+ h.frames(2);+ };+ // A body selected elsewhere is not what the folder's menu is for.+ h.app.run("select.set", json!({"items": [{"type": "body", "name": b}]})).unwrap();+ let bodies = Target::Folder { component: 0, folder: "bodies".into(), scope: "c0".into() };+ for hidden in [true, false] {+ open(&mut h, bodies.clone());+ press_v(&mut h);+ assert_eq!(h.app.session.folder_hidden("c0/bodies"), hidden, "V on the Bodies folder's menu");+ assert!(h.app.viewport.context_menu.is_none(), "the menu closes as after a click");+ assert!(!h.app.session.visibility.hidden_bodies.contains(&b), "the selected body is left alone");+ }+ let shown = h.app.origin_shown();+ open(&mut h, Target::Origin);+ press_v(&mut h);+ assert_eq!(h.app.origin_shown(), !shown, "V on the Origin folder's menu");+ open(&mut h, Target::OriginPlane { name: "XY".into() });+ press_v(&mut h);+ assert!(h.app.session.visibility.hidden_origin.iter().any(|o| o == "XY"), "V on an origin plane's menu");+ assert!(!h.app.session.visibility.hidden_bodies.contains(&b));+ // With no menu open, V still flips the selection.+ press_v(&mut h);+ assert!(h.app.session.visibility.hidden_bodies.contains(&b), "V without a menu acts on the selection");+}+#[test]fn named_views_save_restore_rename_and_delete() {let mut app = sample_app();diff --git a/crates/ui-egui/src/toolbar.rs b/crates/ui-egui/src/toolbar.rsindex c3cbd71506..39a5854ec3 100644--- a/crates/ui-egui/src/toolbar.rs+++ b/crates/ui-egui/src/toolbar.rs@@ -2312,7 +2312,12 @@ pub fn shortcuts(app: &mut SolveApp, ctx: &egui::Context) {Key::S if !mods.shift && !mods.alt => {app.start("ui.palette");}- Key::V => crate::context_menu::toggle_visibility(app),+ // With a menu open, V runs that menu's Show/Hide on what the menu is for.+ Key::V => {+ if !crate::context_menu::press_shortcut(app, "V") {+ crate::context_menu::toggle_visibility(app);+ }+ }Key::F2 => {let at = ctx.input(|i| i.pointer.latest_pos()).unwrap_or(ctx.content_rect().center());crate::context_menu::rename_selection(app, at);diff --git a/docs/book/src/guide/shortcuts.md b/docs/book/src/guide/shortcuts.mdindex 42d4f190ac..996e1ab51b 100644--- a/docs/book/src/guide/shortcuts.md+++ b/docs/book/src/guide/shortcuts.md@@ -59,7 +59,7 @@ Keys handled by the window itself:| Key | Action ||---|---|| S | command search under the ribbon search field |-| V | show or hide the selected bodies, sketches and planes |+| V | show or hide the selected bodies, sketches and planes; with a right-click menu open, its Show/Hide (a folder, the Origin folder, an origin plane) || F2 | rename the selected browser or timeline item || F6 | fit the view to the model || ← → ↑ ↓ | turn the view 15° (with Shift, a quarter turn) |