fix(reader): skip leading newlines after page split to prevent blank top/bottom

This commit is contained in:
Developer
2026-05-15 23:12:52 +08:00
parent 7602121fda
commit 31efa90a87

View File

@@ -437,6 +437,11 @@ pub fn calculate_pages(text: &str, chars_per_line: usize, lines_per_page: usize)
if split <= page_start { if split <= page_start {
split = i; split = i;
} }
if split < total {
// Skip leading newlines to prevent starting page with blank line
while split < total && chars[split] == '\n' {
split += 1;
}
if split < total { if split < total {
pages.push(split); pages.push(split);
page_start = split; page_start = split;
@@ -446,6 +451,7 @@ pub fn calculate_pages(text: &str, chars_per_line: usize, lines_per_page: usize)
} }
} }
} }
}
if *pages.last().unwrap() < total { if *pages.last().unwrap() < total {
pages.push(total); pages.push(total);