From: Simon Tatham Date: Fri, 29 Dec 2023 18:35:49 +0000 (+0000) Subject: Go to top and bottom of file. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=7bc8ba102774dff00a4896ccf92c1d45ddaf7b64;p=mastodonochrome.git Go to top and bottom of file. I think this is all the basic 'paging around' actions done! --- diff --git a/src/file.rs b/src/file.rs index 6b5db17..68b7765 100644 --- a/src/file.rs +++ b/src/file.rs @@ -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, } }