From a80f8a024db049f1249266c0ee0c4ec08d6d759f Mon Sep 17 00:00:00 2001 From: funkpower Date: Sat, 19 Sep 2026 17:36:18 -0400 Subject: [PATCH] chunkmd: say rfind, which is what this was doing --- crates/chunkmd/src/pages.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/chunkmd/src/pages.rs b/crates/chunkmd/src/pages.rs index 1c83899..290ee31 100644 --- a/crates/chunkmd/src/pages.rs +++ b/crates/chunkmd/src/pages.rs @@ -179,9 +179,11 @@ impl<'a> ChapterIndex<'a> { /// per page in every chapter's span: a single mistyped marker reading /// `` would ask for a gigabyte of them. pub fn chapter_of_page(chapters: &[Chapter], page: u32) -> Option<&str> { + // The last chapter that covers the page, not the first: chapters can + // nest, and the innermost one is the one a reader would name. chapters .iter() - .filter(|chapter| { + .rfind(|chapter| { let Some(start) = chapter.start_page else { return false; }; @@ -193,7 +195,6 @@ pub fn chapter_of_page(chapters: &[Chapter], page: u32) -> Option<&str> { }; (start..=end.max(start)).contains(&page) && end >= start }) - .next_back() .map(|chapter| chapter.title.as_str()) }