From 376cf3325a5f4fb6dfbd36ea4b55ab0d03bc5c6f Mon Sep 17 00:00:00 2001 From: aiongg Date: Fri, 30 Oct 2026 21:24:39 +0000 Subject: [PATCH] Integration: #1505 leaving parent pages for a page fits its spread before centring the page --- crates/ui-egui/src/canvas/tests.rs | 14 ++++++++++++++ crates/ui-egui/src/canvas/view.rs | 8 +++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/canvas/tests.rs b/crates/ui-egui/src/canvas/tests.rs index f36269479..7d89a24a8 100644 --- a/crates/ui-egui/src/canvas/tests.rs +++ b/crates/ui-egui/src/canvas/tests.rs @@ -2869,3 +2869,17 @@ fn table_cells_show_their_hidden_characters() { let last = marks.last().unwrap(); assert_eq!((last.0, last.1), (designcraft_geom::Point::new(frag.rect.x1 + 1.0, frag.rect.y1), "ΒΆ")); } + +#[test] +fn leaving_parent_editing_for_the_left_page_of_a_spread_keeps_that_page_selected() { + let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default()); + app.run("file.new", json!({"pages": 4, "facingPages": true})).unwrap(); + let mut h = harness(app); + h.state_mut().run("layout.parents.edit", json!({"on": true, "parent": "A-Parent"})).unwrap(); + h.run_steps(2); + let b = page_box(h.state()).unwrap(); + // Page 2 is the left page of the second spread. + page_box_go(h.state_mut(), &b, 1); + h.run_steps(3); + assert_eq!(current_page(h.state()), Some(1)); +} diff --git a/crates/ui-egui/src/canvas/view.rs b/crates/ui-egui/src/canvas/view.rs index b679923d2..2ba0876a1 100644 --- a/crates/ui-egui/src/canvas/view.rs +++ b/crates/ui-egui/src/canvas/view.rs @@ -188,9 +188,11 @@ pub fn page_box_go(app: &mut DesignApp, b: &PageBox, i: usize) { if i < b.pages { if app.session.active().is_some_and(|st| st.editing_parents) { let _ = app.run("layout.parents.edit", serde_json::json!({"on": false})); - // The canvas refits to the page's spread once it is centred. - if let Some(v) = app.view_mut() { - v.fitted = false; + // Fit the page's spread first, then centre the page: a later refit would centre the + // spread, and the page box would then show its other page. + let spread = app.session.active().and_then(|st| st.doc.page_loc(i)).map(|(si, _)| SpreadRef::Doc(si)); + if let Some(r) = spread { + show_spread(app, r); } } go_to_page(app, i);