Browser menus: V runs the open menu's Show/Hide on the row it was opened for (#8377)
Most browser menus show V beside Show/Hide, but the V key always ran toggle_visibility, which acts on the selection. A right-click on a body or sketch row also selects it, so the two agreed there; a right-click on the Bodies, Sketches or Origin folder, a group, the component or an origin plane does not, so V did nothing, or flipped a body selected earlier, and left the menu open. With a menu open, V now runs that menu's row whose shortcut is V, through run_item as a click does, and closes the menu (context_menu::press_shortcut). A disabled row takes the key and does nothing. With no menu open, or a menu without such a row, V still acts on the selection (#4128, #4409: V stays selection-based). Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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) |
|
||||
|
||||
Reference in New Issue
Block a user