Viewport: right-click keeps a multi-selection of faces and edges (#3733) (#3788)

* claim: #3733

* Viewport: right-click keeps a multi-selection of faces and edges (#3733)

---------

Co-authored-by: AhmetV <344941595+ahmetv10@users.noreply.github.com>
This commit is contained in:
AhmetV
2026-10-23 14:31:30 +00:00
committed by GitHub
parent fa2c1c31f6
commit 30a1fe74ca
2 changed files with 30 additions and 3 deletions
+5 -3
View File
@@ -1495,7 +1495,8 @@ pub(crate) fn commit_rename(app: &mut SolveApp, r: &Rename) {
// ---------------------------------------------------------------------------------------------
/// Open the viewport menu at a screen position. A right-click on something not selected
/// selects it first, so the menu is about what is under the cursor.
/// selects it first, so the menu is about what is under the cursor; a face or edge already in a
/// multi-selection keeps the whole selection (#3733).
pub fn open(app: &mut SolveApp, at: Pos2) {
app.menu.over_geometry = app.viewport.hover.is_some();
// A right-click leaves a plane unselected, but the menu offers a sketch on it.
@@ -1504,10 +1505,11 @@ pub fn open(app: &mut SolveApp, at: Pos2) {
_ => None,
});
crate::select_other::close(app);
let selected = |app: &SolveApp, sel: &Sel| app.session.selection.iter().any(|x| crate::selection::same_item(x, sel));
if app.session.active_sketch.is_none()
&& let Some(h) = app.viewport.hover.clone()
&& let Some((_, sel)) = crate::viewport::candidate(app, &[h])
&& !app.session.selection.contains(&sel)
&& !selected(app, &sel)
&& !matches!(sel, Sel::Plane { .. } | Sel::Axis { .. })
{
let _ = app.run("select.set", json!({ "items": [sel] }));
@@ -1515,7 +1517,7 @@ pub fn open(app: &mut SolveApp, at: Pos2) {
&& let Some(h) = app.viewport.hover.clone()
&& let Some((_, sel)) = crate::viewport::candidate(app, &[h])
&& (matches!(sel, Sel::SketchCurve { .. } | Sel::SketchPoint { .. }) || crate::sketch_text::entity_for_selection(app, &sel).is_some())
&& !app.session.selection.contains(&sel)
&& !selected(app, &sel)
{
let _ = app.run("select.set", json!({ "items": [sel] }));
}
+25
View File
@@ -4,8 +4,10 @@ use crate::test_support::sample_app;
use egui::pos2;
use serde_json::json;
use solidcraft_engine::Session;
use solidcraft_engine::geom::Vec3;
use crate::context_menu::{self, Item, Target};
use crate::viewport::Hit;
use crate::{Services, SolveApp};
#[test]
@@ -135,6 +137,29 @@ fn a_selected_face_keeps_the_body_menu_beside_a_sketch_curve() {
assert!(!items.iter().any(|i| i.label == "Redefine Sketch Plane"), "the face menu, not the sketch menu");
}
/// A right-click on a face or edge that is part of a multi-selection keeps the whole selection:
/// the pick keeps a point of its own, so the face is compared by body and index (#3733).
#[test]
fn right_click_on_a_selected_face_keeps_the_multi_selection() {
let mut app = sample_app();
let b = body(&app);
app.run(
"select.set",
json!({"items": [
{"type": "face", "body": b, "index": 0, "point": [1, 2, 3]},
{"type": "face", "body": b, "index": 1, "point": [4, 5, 6]},
]}),
)
.unwrap();
app.viewport.hover = Some(Hit::Face { body: b.clone(), index: 0, point: Vec3::new(9.0, 9.0, 9.0) });
context_menu::open(&mut app, pos2(400.0, 300.0));
assert_eq!(app.session.selection.len(), 2, "the right-click keeps the faces it is about: {:?}", app.session.selection);
// A face outside the selection is still picked, so its menu is about the face under the cursor.
app.viewport.hover = Some(Hit::Face { body: b, index: 2, point: Vec3::new(9.0, 9.0, 9.0) });
context_menu::open(&mut app, pos2(400.0, 300.0));
assert_eq!(app.session.selection.len(), 1, "a face outside the selection is picked: {:?}", app.session.selection);
}
#[test]
fn face_menu_hides_and_finds_the_body() {
let mut app = sample_app();