From 992c93fe5bf22287b1bbaf717d7f9d0ae26fc9bb Mon Sep 17 00:00:00 2001 From: HiroKenEz <59478073+HiroKenEz@users.noreply.github.com> Date: Sun, 25 Oct 2026 01:25:44 +0000 Subject: [PATCH] Find in Timeline scrolls both timeline layouts to the found feature (#5850) (#5863) * claim: #5850 * Find in Timeline scrolls both timeline layouts to the found feature (#5850) Find in Timeline selected the feature but neither the bottom History strip nor the history on the left scrolled to it. The handler now leaves a one-shot reveal request (TreeState::timeline_reveal); whichever layout draws its items next scrolls the found item into the middle of its scroll area and drops it. Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Claude Opus 5.5 --- crates/ui-egui/src/browser.rs | 3 +++ crates/ui-egui/src/context_menu.rs | 1 + crates/ui-egui/src/timeline.rs | 37 +++++++++++++++++++++++++++++ crates/ui-egui/src/timeline_left.rs | 5 ++++ 4 files changed, 46 insertions(+) diff --git a/crates/ui-egui/src/browser.rs b/crates/ui-egui/src/browser.rs index 1c2987031..8613d6ac5 100644 --- a/crates/ui-egui/src/browser.rs +++ b/crates/ui-egui/src/browser.rs @@ -122,6 +122,9 @@ pub struct TreeState { pub picked_timeline_groups: Vec, /// Last feature-history item clicked, for Shift ranges (`f:` or `g:`). pub timeline_anchor: Option, + /// Find in Timeline: the feature the history scrolls to the next time it draws its items, in + /// the bottom strip or in the history on the left (#5850). + pub timeline_reveal: Option, /// The Edit Canvas / Calibrate panel. pub canvas_panel: Option, /// A Section Analysis hidden with its eye in the Analysis folder: its plane (origin, diff --git a/crates/ui-egui/src/context_menu.rs b/crates/ui-egui/src/context_menu.rs index c676e490a..704e1c623 100644 --- a/crates/ui-egui/src/context_menu.rs +++ b/crates/ui-egui/src/context_menu.rs @@ -1190,6 +1190,7 @@ pub fn run_item(app: &mut SolveApp, item: &Item, at: Pos2) { crate::browser::reveal_feature(app, f, body); } let _ = app.run("select.set", json!({"items": [{"type": "feature", "id": f}]})); + app.tree.timeline_reveal = Some(f); } } "ui.tangentChain" => tangent_chain(app), diff --git a/crates/ui-egui/src/timeline.rs b/crates/ui-egui/src/timeline.rs index 42c3e2d68..ad1781e33 100644 --- a/crates/ui-egui/src/timeline.rs +++ b/crates/ui-egui/src/timeline.rs @@ -419,6 +419,8 @@ fn timeline_contents(app: &mut SolveApp, ui: &mut egui::Ui, floating: bool) { .map(|f| (f.id, f.name.clone(), icon_of(&f.kind), f.suppressed, f.kind.type_name(), TimelineKind::of(&f.kind))) .collect(); let order: Vec = feats.iter().map(|f| f.0).collect(); + // Find in Timeline: scroll the found feature into the strip on this frame (#5850). + let reveal = app.tree.timeline_reveal.take(); // The feature whose body is under the cursor in the viewport. let st = app.session.world_state(); let from_view = match &app.viewport.hover { @@ -441,6 +443,9 @@ fn timeline_contents(app: &mut SolveApp, ui: &mut egui::Ui, floating: bool) { } xs.push(x); let br = Rect::from_min_size(pos2(x, r.top() + 6.0), vec2(28.0, 28.0)); + if reveal == Some(*id) { + ui.scroll_to_rect(br, Some(egui::Align::Center)); + } crate::scenario::publish_handle(&format!("timeline:{name}"), br.center()); let resp = ui.interact(br, ui.id().with(("feat", *id)), Sense::click_and_drag()); let res = app.session.model.result(*id); @@ -769,6 +774,38 @@ mod tests { assert_eq!(moved.y, first.y); } + /// Find in Timeline on the last body of a history longer than the timeline scrolls its + /// feature into view, in the bottom strip and in the history on the left (#5850). + #[test] + fn find_in_timeline_scrolls_both_timelines_to_the_found_feature() { + for left in [false, true] { + let mut h = Harness::new(); + h.app.preferences.timeline_left = left; + for i in 0..80 { + h.app.run("sketch.create", json!({"plane": "XY", "name": format!("S{i}")})).unwrap(); + h.app.run("sketch.finish", json!({})).unwrap(); + } + h.app.run("solid.box", json!({"length": 10, "width": 10, "height": 10, "name": "Last", "body_name": "Plate"})).unwrap(); + h.app.run("select.clear", json!({})).unwrap(); + h.frames(4); + let shown = |h: &Harness| { + let history = h.app.shell.history.unwrap(); + let found = crate::scenario::handle_at("timeline:Last").unwrap(); + history.contains(found) + }; + assert!(!shown(&h), "left={left}: the last feature starts outside the timeline"); + + let target = crate::context_menu::Target::Body { name: "Plate".into() }; + let item = crate::context_menu::items(&h.app, &target).into_iter().find(|item| item.id == "ui.findTimeline").unwrap(); + crate::context_menu::run_item(&mut h.app, &item, egui::pos2(0.0, 0.0)); + h.frames(30); + let last = h.app.session.doc.find_feature("Last").unwrap().id; + assert_eq!(h.app.session.selection, [solidcraft_engine::Sel::Feature { id: last }], "left={left}"); + assert!(shown(&h), "left={left}: Find in Timeline scrolled the found feature into the timeline"); + assert!(h.app.tree.timeline_reveal.is_none(), "left={left}: the request is done once drawn"); + } + } + #[test] fn the_feature_menu_edits_its_profile_sketch_in_both_timelines() { for left in [false, true] { diff --git a/crates/ui-egui/src/timeline_left.rs b/crates/ui-egui/src/timeline_left.rs index 246c149dd..fa91b7b76 100644 --- a/crates/ui-egui/src/timeline_left.rs +++ b/crates/ui-egui/src/timeline_left.rs @@ -935,6 +935,8 @@ fn vertical_features(app: &mut SolveApp, ui: &mut egui::Ui, names: bool) { .collect(); let groups = app.session.doc.timeline_groups.clone(); let order = visible_order(app, &features, &groups); + // Find in Timeline: scroll the found feature into the history on this frame (#5850). + let reveal = app.tree.timeline_reveal.take(); let first_indices: std::collections::BTreeMap> = groups.iter().map(|group| (group.id, group_first_feature(&groups, &features, group.id))).collect(); let end_indices: std::collections::BTreeMap = groups @@ -1014,6 +1016,9 @@ fn vertical_features(app: &mut SolveApp, ui: &mut egui::Ui, names: bool) { row }; crate::scenario::publish_rect(&format!("history:feature:{name}"), rect); + if reveal == Some(*id) { + ui.scroll_to_rect(rect, Some(egui::Align::Center)); + } let fold_rect = Rect::from_min_size(rect.left_top() + vec2(indent, 0.0), vec2(16.0, rect.height())); let on_fold = has_patterns && response.interact_pointer_pos().is_some_and(|p| fold_rect.contains(p)); crate::scenario::publish_handle(&format!("timeline:{name}"), rect.center());