From 2eacbc37f4eb00448bd7837c8c16397385eccf9d Mon Sep 17 00:00:00 2001 From: amolinari-autotex Date: Wed, 21 Oct 2026 00:44:43 +0000 Subject: [PATCH] Keep sketches out of the Browser Features folder (#3584) --- crates/ui-egui/src/browser/features.rs | 69 +++++++++++++++++++++++++- crates/ui-egui/src/browser_model.rs | 4 +- docs/picked-face-navigation.md | 2 +- 3 files changed, 71 insertions(+), 4 deletions(-) diff --git a/crates/ui-egui/src/browser/features.rs b/crates/ui-egui/src/browser/features.rs index 3cb44fc01..dd73cb438 100644 --- a/crates/ui-egui/src/browser/features.rs +++ b/crates/ui-egui/src/browser/features.rs @@ -41,7 +41,7 @@ pub(crate) fn reveal(app: &mut SolveApp, id: u64, body: &str) { pub(super) fn rows(app: &mut SolveApp, ui: &mut egui::Ui, component: u64, path: &[u64], depth: usize, acts: &mut Actions) { let has_features = match app.tree.model.as_ref().filter(|m| m.matches(&app.session)) { Some(model) => model.features.get(&component).is_some_and(|features| !features.is_empty()), - None => app.session.doc.features.iter().any(|feature| feature.component == component), + None => app.session.doc.features.iter().any(|feature| feature.component == component && !matches!(feature.kind, FeatureKind::Sketch { .. })), }; if !has_features { return; @@ -58,7 +58,14 @@ pub(super) fn rows(app: &mut SolveApp, ui: &mut egui::Ui, component: u64, path: } let indices = match app.tree.model.as_ref().filter(|m| m.matches(&app.session)) { Some(model) => model.features.get(&component).cloned().unwrap_or_default(), - None => app.session.doc.features.iter().enumerate().filter_map(|(i, f)| (f.component == component).then_some(i)).collect(), + None => app + .session + .doc + .features + .iter() + .enumerate() + .filter_map(|(i, f)| (f.component == component && !matches!(f.kind, FeatureKind::Sketch { .. })).then_some(i)) + .collect(), }; for index in indices { let Some(feature) = app.session.doc.features.get(index) else { continue }; @@ -93,6 +100,64 @@ mod tests { use super::*; use crate::scenario::Harness; + fn feature_rows(h: &mut Harness, cache: &str) -> Vec { + h.app.tree.model = match cache { + "current" => Some(model::Model::new(&h.app.session)), + "stale" => Some(model::Model::new(&solidcraft_engine::Session::default())), + _ => None, + }; + h.app.tree.expanded.insert("c0/features".into()); + DRAWN.with(|d| d.borrow_mut().clear()); + let raw = egui::RawInput { screen_rect: Some(Rect::from_min_size(Pos2::ZERO, vec2(800.0, 600.0))), ..Default::default() }; + let _ = h.ctx.run_ui(raw, |ui| rows(&mut h.app, ui, 0, &[], 0, &mut Actions::default())); + drawn_rows().into_iter().map(|(label, ..)| label).collect() + } + + #[test] + fn browser_feature_sketch_only_has_one_sketch_row_and_no_features_folder() { + let mut h = Harness::new(); + h.app.run("sketch.create", json!({"plane":"XY","name":"Sketch1"})).unwrap(); + h.app.run("sketch.finish", json!({})).unwrap(); + h.app.tree.expanded.insert("c0/features".into()); + let saved = h.app.session.doc.to_json(); + let undo = h.app.session.undo.len(); + h.frames(2); + let labels: Vec<_> = drawn_rows().into_iter().map(|(label, ..)| label).collect(); + assert_eq!(labels.iter().filter(|label| *label == "Sketch1").count(), 1, "{labels:?}"); + assert!(!labels.iter().any(|label| label == "Features"), "{labels:?}"); + for cache in ["current", "missing", "stale"] { + assert!(feature_rows(&mut h, cache).is_empty(), "{cache}: sketch-only document has no Features folder"); + } + assert_eq!(h.app.session.doc.to_json(), saved); + assert_eq!(h.app.session.undo.len(), undo); + } + + #[test] + fn browser_feature_mixed_history_filters_sketches_with_current_missing_and_stale_cache() { + let mut h = Harness::new(); + h.app.run("sketch.create", json!({"plane":"XY","name":"Profile"})).unwrap(); + h.app.run("sketch.rectangle.two_point", json!({"p0":[0,0],"p1":[20,15]})).unwrap(); + h.app.run("sketch.finish", json!({})).unwrap(); + let extrude = h.app.run("solid.extrude", json!({"distance":10,"body_name":"Plate"})).unwrap()["feature"].as_u64().unwrap(); + let name = h.app.session.doc.feature(extrude).unwrap().name.clone(); + let saved = h.app.session.doc.to_json(); + let undo = h.app.session.undo.len(); + for cache in ["current", "missing", "stale"] { + assert_eq!(feature_rows(&mut h, cache), ["Features".to_owned(), name.clone()], "{cache}"); + } + h.frames(2); + let labels: Vec<_> = drawn_rows().into_iter().map(|(label, ..)| label).collect(); + assert_eq!(labels.iter().filter(|label| *label == "Profile").count(), 1, "{labels:?}"); + assert!(labels.contains(&name), "{labels:?}"); + find(&mut h.app, extrude, "Plate"); + h.frames(2); + assert!(h.app.tree.reveal_feature.is_none(), "the creator row was drawn and scrolled to"); + let at = h.call("ui.at", json!({"handle":format!("row:browser-feature:c0:{extrude}")})); + assert_eq!(at["ok"], true, "{at}"); + assert_eq!(h.app.session.doc.to_json(), saved); + assert_eq!(h.app.session.undo.len(), undo); + } + fn find(app: &mut SolveApp, feature: u64, body: &str) { let state = app.session.world_state(); let model_body = state.body(body).unwrap(); diff --git a/crates/ui-egui/src/browser_model.rs b/crates/ui-egui/src/browser_model.rs index 8eb41ba30..9dbe6655e 100644 --- a/crates/ui-egui/src/browser_model.rs +++ b/crates/ui-egui/src/browser_model.rs @@ -35,7 +35,9 @@ impl Model { let mut planes: HashMap> = HashMap::new(); let mut features: HashMap> = HashMap::new(); for (i, feature) in session.doc.features.iter().enumerate() { - features.entry(feature.component).or_default().push(i); + if !matches!(feature.kind, FeatureKind::Sketch { .. }) { + features.entry(feature.component).or_default().push(i); + } let index = match feature.kind { FeatureKind::Sketch { .. } => &mut sketches, FeatureKind::ConstructionPlane { .. } => &mut planes, diff --git a/docs/picked-face-navigation.md b/docs/picked-face-navigation.md index 70dac8b5b..7b8bbecc2 100644 --- a/docs/picked-face-navigation.md +++ b/docs/picked-face-navigation.md @@ -2,6 +2,6 @@ A face selected in the viewport uses its persistent creating feature for **Edit Feature**, **Find in Timeline** and **Find in Browser**. Later holes, blends and trims do not redirect the action to the feature that originally created the whole body. -The Browser contains a **Features** folder for each native component with history. Find in Browser opens the ancestors and this folder in the selected body's actual occurrence, selects the creating feature and scrolls its row into view. Double-clicking the row opens its editor. This leaves the timeline layout, active component and history marker unchanged until an edit is requested. +The Browser contains a **Features** folder for each native component with non-sketch history. Sketches appear only in **Sketches**, and a sketch-only component has no Features folder. Find in Browser opens the ancestors and the Features folder in the selected body's actual occurrence, selects the creating feature and scrolls its row into view. Double-clicking the row opens its editor. This leaves the timeline layout, active component and history marker unchanged until an edit is requested. Selecting a whole body keeps the existing body navigation. A face with an unavailable creator does not fall back to the body's base feature. Imported source identifiers do not acquire an unrelated editable native history.