From a60cb72826708326782fef70135a9f46776fe379 Mon Sep 17 00:00:00 2001 From: Madhav Agarwal Date: Sun, 15 Nov 2026 23:10:13 +0530 Subject: [PATCH 1/3] Pages panel: a right-to-left spread label reads left page first (#2601) --- crates/ui-egui/src/panels/pages.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/panels/pages.rs b/crates/ui-egui/src/panels/pages.rs index 52ff2ee08..ff780c807 100644 --- a/crates/ui-egui/src/panels/pages.rs +++ b/crates/ui-egui/src/panels/pages.rs @@ -294,7 +294,10 @@ const LAYOUT_COL_MIN: f32 = 96.0; /// pages numbered on in one section (an en dash), and the names apart ("2, 1", "8, A") when a section starts /// inside the spread. pub(crate) fn spread_label(app: &DesignApp, doc: &designcraft_doc::Document, first: usize, n: usize) -> String { - let names: Vec = (first..first + n).map(|abs| app.session.page_label(abs)).collect(); + let mut names: Vec = (first..first + n).map(|abs| app.session.page_label(abs)).collect(); + if doc.settings.right_to_left_binding { + names.reverse(); + } let starts = |abs: usize| abs == 0 || doc.sections.iter().any(|s| s.start == abs); match (names.first(), names.last()) { (Some(a), Some(b)) if names.len() > 1 => { @@ -1306,6 +1309,21 @@ mod spread_label_tests { assert_eq!(labels(&app), ["1", "2–3", "4–5", "6–7", "8–9"]); } + /// Bound right to left, a spread's label follows the document's reading order: the left + /// page first ("3–2", not "2–3"), and a section inside a spread lists its pages left to + /// right. Left-to-right labels are unchanged. + #[test] + fn rtl_binding_labels_spreads_in_visual_left_to_right_order() { + let mut app = app(); + assert_eq!(labels(&app), ["1", "2–3", "4–5", "6–7", "8–9"]); + app.run("layout.documentSetup", json!({"binding": "rightToLeft"})).unwrap(); + assert_eq!(labels(&app), ["1", "3–2", "5–4", "7–6", "9–8"]); + app.run("layout.section", json!({"page": 3, "startNumber": 1})).unwrap(); + let got = labels(&app); + assert_eq!(got[1], "1, 2"); + assert_eq!(got[2], "3–2"); + } + /// Labels navigate to document spreads, including when parent editing was active. #[test] fn the_panel_shows_spread_labels_and_a_click_on_one_goes_to_its_spread() { From 1f75a8d8f0025ae6f86554ca9e6fc9314b0ba395 Mon Sep 17 00:00:00 2001 From: "autocraft-bot[bot]" <354215646+autocraft-bot[bot]@users.noreply.github.com> Date: Sun, 15 Nov 2026 18:28:23 +0000 Subject: [PATCH 2/3] Apply review fixes - crates/ui-egui/src/panels/pages.rs --- crates/ui-egui/src/panels/pages.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/crates/ui-egui/src/panels/pages.rs b/crates/ui-egui/src/panels/pages.rs index ff780c807..7917b2ab5 100644 --- a/crates/ui-egui/src/panels/pages.rs +++ b/crates/ui-egui/src/panels/pages.rs @@ -293,11 +293,16 @@ const LAYOUT_COL_MIN: f32 = 96.0; /// A spread's label under its thumbnails, as InDesign's: one name for a single page, "2–3" for /// pages numbered on in one section (an en dash), and the names apart ("2, 1", "8, A") when a section starts /// inside the spread. +/// The names read left to right as the thumbnails are drawn, so a spread bound right to left +/// lists its second page first. pub(crate) fn spread_label(app: &DesignApp, doc: &designcraft_doc::Document, first: usize, n: usize) -> String { - let mut names: Vec = (first..first + n).map(|abs| app.session.page_label(abs)).collect(); - if doc.settings.right_to_left_binding { - names.reverse(); + let mut order: Vec = (first..first + n).collect(); + // In the order the thumbnails are drawn: by each page's x (a right-to-left pair shows its second page on the left). + if let Some(sp) = doc.page_loc(first).and_then(|(si, _)| doc.spreads.get(si)) { + let x = |abs: usize| sp.pages.get(abs.saturating_sub(first)).map_or(0.0, |p| p.x); + order.sort_by(|&a, &b| x(a).total_cmp(&x(b))); } + let names: Vec = order.into_iter().map(|abs| app.session.page_label(abs)).collect(); let starts = |abs: usize| abs == 0 || doc.sections.iter().any(|s| s.start == abs); match (names.first(), names.last()) { (Some(a), Some(b)) if names.len() > 1 => { @@ -1311,7 +1316,8 @@ mod spread_label_tests { /// Bound right to left, a spread's label follows the document's reading order: the left /// page first ("3–2", not "2–3"), and a section inside a spread lists its pages left to - /// right. Left-to-right labels are unchanged. + /// right. Left-to-right labels are unchanged. A spread of more pages, drawn in document + /// order, keeps its label in that order. #[test] fn rtl_binding_labels_spreads_in_visual_left_to_right_order() { let mut app = app(); @@ -1322,6 +1328,8 @@ mod spread_label_tests { let got = labels(&app); assert_eq!(got[1], "1, 2"); assert_eq!(got[2], "3–2"); + app.run("layout.pages.toSpread", json!({"page": 4, "spread": 1})).unwrap(); + assert_eq!(labels(&app)[1], "2–4"); } /// Labels navigate to document spreads, including when parent editing was active. From 105a080c03fa3c0ae3989a457e65cedb8484272c Mon Sep 17 00:00:00 2001 From: Madhav Agarwal Date: Mon, 16 Nov 2026 21:09:45 +0530 Subject: [PATCH 3/3] review: the spread test expects the labels in the order they are drawn (CodeRabbit/a spread with a section inside lists its names apart) Moving page 4 into spread 1 does not move the section that starts at page 3, so the label takes the comma-separated branch: pages 2, 3 and 4 are numbered 2, 1 and 2, and the assertion now expects exactly that. The test failed before this change (left: "2, 1, 2", right: "2-4"). --- crates/ui-egui/src/panels/pages.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/panels/pages.rs b/crates/ui-egui/src/panels/pages.rs index 7917b2ab5..35480e714 100644 --- a/crates/ui-egui/src/panels/pages.rs +++ b/crates/ui-egui/src/panels/pages.rs @@ -1317,7 +1317,7 @@ mod spread_label_tests { /// Bound right to left, a spread's label follows the document's reading order: the left /// page first ("3–2", not "2–3"), and a section inside a spread lists its pages left to /// right. Left-to-right labels are unchanged. A spread of more pages, drawn in document - /// order, keeps its label in that order. + /// order, lists its names in that order, apart while a section still starts inside it. #[test] fn rtl_binding_labels_spreads_in_visual_left_to_right_order() { let mut app = app(); @@ -1329,7 +1329,9 @@ mod spread_label_tests { assert_eq!(got[1], "1, 2"); assert_eq!(got[2], "3–2"); app.run("layout.pages.toSpread", json!({"page": 4, "spread": 1})).unwrap(); - assert_eq!(labels(&app)[1], "2–4"); + // Three pages, drawn in document order: 2, 3 and 4 are numbered 2, 1 and 2, and the + // section that starts on page 3 stays inside the spread, so the names stay apart. + assert_eq!(labels(&app)[1], "2, 1, 2"); } /// Labels navigate to document spreads, including when parent editing was active.