Merge pull request #2844 from gmrmad1/fix/2601-rtl-spread-label

Pages panel: a right-to-left spread label reads left page first (#2601)
This commit is contained in:
autocraft-bot[bot] authored and GitHub committed 2026-11-16 16:00:05 +00:00
commit 47ef1ec411
1 file changed
+29 -1
+29 -1
View File
@@ -293,8 +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 names: Vec<String> = (first..first + n).map(|abs| app.session.page_label(abs)).collect();
let mut order: Vec<usize> = (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<String> = 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 => {
@@ -1306,6 +1314,26 @@ 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. A spread of more pages, drawn in document
/// 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();
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");
app.run("layout.pages.toSpread", json!({"page": 4, "spread": 1})).unwrap();
// 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.
#[test]
fn the_panel_shows_spread_labels_and_a_click_on_one_goes_to_its_spread() {