chiark / gitweb /
Fix panic when going to Read Mentions.
authorSimon Tatham <anakin@pobox.com>
Sun, 31 Dec 2023 15:11:07 +0000 (15:11 +0000)
committerSimon Tatham <anakin@pobox.com>
Sun, 31 Dec 2023 15:11:07 +0000 (15:11 +0000)
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.

src/file.rs

index 8727c55fddfa20dc5b4e81a93f2cb0e095e103bf..28409e8b876d878fcd3fc31db939b8a3eff42cdb 100644 (file)
@@ -187,9 +187,22 @@ impl<Type: FeedType> FeedFile<Type> {
         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;
             }