* claim: #7206 * Browser: a body's name hides the body, not a sketch of the same name (#7206) `browser.visibility` looked a key up as a feature first, so when a sketch had exactly the name of a body (a sketch named after the body it makes), the body's eye in the browser hid and showed the sketch instead, and the body could not be hidden at all. The browser names a sketch by its id and a body only by its name, so a name that is exactly both now names the body. The sketch still hides and shows by its id; matches that differ only in case are left as they are (#6967, #7004). Fixes #7569 too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FN5eEMrqWWXqi65FcK8GXq --------- Co-authored-by: sascha2101 <221609842+sascha2101@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 file changed
+31
@@ -199,6 +199,12 @@ fn is_construction(k: &FeatureKind) -> bool {
|
||||
fn shown_item(s: &Session, key: &str) -> Option<Shown> {
|
||||
if let Some(f) = s.doc.find_feature(key) {
|
||||
if matches!(f.kind, FeatureKind::Sketch { .. }) {
|
||||
// A sketch and a body with exactly the same name, a sketch named after the body it
|
||||
// makes (#7206): the name is the body's. The browser names a sketch by its id and a
|
||||
// body only by its name, so the body could not be reached otherwise.
|
||||
if f.name == key && s.world_state().bodies.iter().any(|b| b.name == key) {
|
||||
return Some(Shown::Body(key.to_string()));
|
||||
}
|
||||
return Some(Shown::Sketch(f.id));
|
||||
}
|
||||
if is_construction(&f.kind) {
|
||||
@@ -1589,6 +1595,31 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
/// #7206, #7569: a sketch named after the body it makes. The name hides and shows the body,
|
||||
/// as the body's eye in the browser asks; the sketch, which the browser names by its id,
|
||||
/// still hides and shows by its id, and the body is left alone.
|
||||
#[test]
|
||||
fn a_body_hides_by_its_name_when_a_sketch_has_the_same_name() {
|
||||
let mut s = Session::default();
|
||||
let sketch = run(&mut s, "sketch.create", json!({"plane": "XY"}))["sketch"].as_u64().unwrap();
|
||||
run(&mut s, "sketch.rectangle.two_point", json!({"p0": [0, 0], "p1": [10, 10]}));
|
||||
run(&mut s, "sketch.finish", json!({}));
|
||||
run(&mut s, "timeline.rename", json!({"feature": sketch, "name": "Deckel"}));
|
||||
run(&mut s, "solid.extrude", json!({"sketch": sketch, "distance": 5, "body_name": "Deckel"}));
|
||||
let r = run(&mut s, "browser.visibility", json!({"items": ["Deckel"], "visible": false}));
|
||||
assert_eq!(r["changed"], 1);
|
||||
assert_eq!(s.visibility.hidden_bodies, vec!["Deckel".to_string()]);
|
||||
assert!(s.visibility.hidden_sketches.is_empty(), "the sketch is not the item that changed");
|
||||
run(&mut s, "browser.visibility", json!({"items": ["Deckel"], "visible": true}));
|
||||
assert!(s.visibility.hidden_bodies.is_empty());
|
||||
// The sketch by its id: shown and hidden again, the body stays shown.
|
||||
run(&mut s, "browser.visibility", json!({"items": [sketch], "visible": true}));
|
||||
assert_eq!(s.visibility.shown_sketches, vec![sketch]);
|
||||
run(&mut s, "browser.visibility", json!({"items": [sketch], "visible": false}));
|
||||
assert_eq!(s.visibility.hidden_sketches, vec![sketch]);
|
||||
assert!(s.visibility.hidden_bodies.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn helper_sketches_hide_and_show() {
|
||||
let mut s = Session::default();
|
||||
|
||||
Reference in new issue
Block a user