chiark / gitweb /
Scrolling downward, too.
authorSimon Tatham <anakin@pobox.com>
Fri, 29 Dec 2023 18:14:01 +0000 (18:14 +0000)
committerSimon Tatham <anakin@pobox.com>
Fri, 29 Dec 2023 18:17:34 +0000 (18:17 +0000)
src/file.rs

index b61dc27483492e9ee10703cad613f049c3d96915..c98ca9792be127d22c5de088b5783cc294118773 100644 (file)
@@ -169,6 +169,36 @@ impl FeedFile {
         self.pos = FilePosition::Fine(item, line);
         self.ensure_enough_rendered();
     }
+
+    fn move_down(&mut self, distance: usize) {
+        let (w, _h) = self.last_size.expect("move_down before resize");
+        let (item, line) = match self.pos {
+            FilePosition::Fine(item, line) => (item, line),
+            _ => panic!("coarse position reached move_down()"),
+        };
+
+        let mut item = item;
+        let mut line = line;
+        let mut remaining = distance;
+        while remaining > 0 {
+            let mut len = self.ensure_item_rendered(item, w).len();
+            if line == len {
+                if item >= self.contents.last_index() {
+                    break;
+                }
+                item += 1;
+                line = 0;
+                len = self.ensure_item_rendered(item, w).len();
+            }
+
+            let this = min(remaining, len - line);
+            remaining -= this;
+            line += this;
+        }
+
+        self.pos = FilePosition::Fine(item, line);
+        self.ensure_enough_rendered();
+    }
 }
 
 impl ActivityState for FeedFile {
@@ -254,6 +284,23 @@ impl ActivityState for FeedFile {
                 self.move_up(max(1, h - min(h, 3)));
                 LogicalAction::Nothing
             },
+            Down => {
+                self.move_down(1);
+                LogicalAction::Nothing
+            },
+            Return => {
+                let oldpos = self.pos;
+                self.move_down(1);
+                if oldpos == self.pos {
+                    LogicalAction::Pop
+                } else {
+                    LogicalAction::Nothing
+                }
+            },
+            Space | PgDn | Right => {
+                self.move_down(max(1, h - min(h, 3)));
+                LogicalAction::Nothing
+            },
             _ => LogicalAction::Nothing,
         }
     }