chiark / gitweb /
Go to top and bottom of file.
authorSimon Tatham <anakin@pobox.com>
Fri, 29 Dec 2023 18:35:49 +0000 (18:35 +0000)
committerSimon Tatham <anakin@pobox.com>
Fri, 29 Dec 2023 18:35:49 +0000 (18:35 +0000)
I think this is all the basic 'paging around' actions done!

src/file.rs

index 6b5db17caddf2303f362693498e4e035d9704ed3..68b77658c9dc73ea2e0c11e281a28376e78aa71c 100644 (file)
@@ -213,6 +213,23 @@ impl FeedFile {
         self.pos = FilePosition::Fine(item, line);
         self.ensure_enough_rendered();
     }
+
+    fn goto_top(&mut self) {
+        self.pos = FilePosition::Fine(self.contents.first_index(), 0);
+        let overshoot = self.ensure_enough_rendered();
+        // Clip position at top of file
+        if overshoot > 0 {
+            self.move_down(overshoot);
+        }
+    }
+
+    fn goto_bottom(&mut self) {
+        let (w, _h) = self.last_size.expect("goto_bottom before resize");
+        let item = self.contents.last_index();
+        let line = self.ensure_item_rendered(item, w).len();
+        self.pos = FilePosition::Fine(item, line);
+        self.ensure_enough_rendered();
+    }
 }
 
 impl ActivityState for FeedFile {
@@ -317,6 +334,14 @@ impl ActivityState for FeedFile {
                 self.move_down(max(1, h - min(h, 3)));
                 LogicalAction::Nothing
             },
+            Pr('0') | Home => {
+                self.goto_top();
+                LogicalAction::Nothing
+            }
+            Pr('z') | Pr('Z') | End => {
+                self.goto_bottom();
+                LogicalAction::Nothing
+            }
             _ => LogicalAction::Nothing,
         }
     }