From: Simon Tatham Date: Sun, 31 Dec 2023 15:11:07 +0000 (+0000) Subject: Fix panic when going to Read Mentions. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=38f3474b4d2884fde08b9e3dd6d271569462b308;p=mastodonochrome.git Fix panic when going to Read Mentions. My rewrite of the ensure_enough_rendered loop introduced a further bug in which we counted the number of visible lines of the bottom item _plus_ its full height. Should have been _instead of_ its full height. So we didn't get right to the top of the screen. --- diff --git a/src/file.rs b/src/file.rs index 8727c55..28409e8 100644 --- a/src/file.rs +++ b/src/file.rs @@ -187,9 +187,22 @@ impl FeedFile { let (item, line) = self.refine_pos(w); let mut item = item; - let mut lines_rendered = line; + let mut lines_rendered = 0; + // We count most items we render for their full height, but + // not the one we can only see the top segment of + let mut line_count_override = Some(line); + loop { - lines_rendered += self.ensure_item_rendered(item, w).len(); + let item_height = self.ensure_item_rendered(item, w).len(); + + let item_height = if let Some(over) = line_count_override { + min(item_height, over) + } else { + item_height + }; + line_count_override = None; + lines_rendered += item_height; + if lines_rendered >= h { break; }