diff options
author | qkzk <qu3nt1n@gmail.com> | 2023-10-01 14:30:41 +0200 |
---|---|---|
committer | qkzk <qu3nt1n@gmail.com> | 2023-10-01 14:30:41 +0200 |
commit | 7d14753b3f516b6157e22517f292959bd4b86473 (patch) | |
tree | 4861e2447b9ca91a0190abf2e5b28c1c02bf36d0 /src | |
parent | f9f7f9548089715ddfc4fa021b2780403203b7b6 (diff) |
FIX: page down when only a few file screw the display
Diffstat (limited to 'src')
-rw-r--r-- | src/content_window.rs | 8 | ||||
-rw-r--r-- | src/tab.rs | 18 |
2 files changed, 18 insertions, 8 deletions
diff --git a/src/content_window.rs b/src/content_window.rs index b3a8c9d..7f19b69 100644 --- a/src/content_window.rs +++ b/src/content_window.rs @@ -88,11 +88,19 @@ impl ContentWindow { /// Scroll the window to this index if possible. /// Does nothing if the index can't be reached. pub fn scroll_to(&mut self, index: usize) { + if self.len < self.height { + return; + } if self.is_index_outside_window(index) { self.top = max(index, Self::WINDOW_PADDING) - Self::WINDOW_PADDING; self.bottom = (self.top + Self::default_bottom(self.height, self.len)) .checked_sub(Self::BOTTOM_ROWS) .unwrap_or_else(|| 2); + log::info!( + "scroll_to {index} is outside window top {top} bottom {bottom}", + top = self.top, + bottom = self.bottom + ); } } @@ -536,19 +536,21 @@ impl Tab { /// if moves down one page. pub fn page_down(&mut self) { match self.mode { - Mode::Normal => { - let down_index = min( - self.path_content.content.len() - 1, - self.path_content.index + 10, - ); - self.path_content.select_index(down_index); - self.window.scroll_to(down_index); - } + Mode::Normal => self.normal_page_down(), Mode::Preview => self.preview_page_down(), _ => (), } } + fn normal_page_down(&mut self) { + let down_index = min( + self.path_content.content.len() - 1, + self.path_content.index + 10, + ); + self.path_content.select_index(down_index); + self.window.scroll_to(down_index); + } + fn preview_page_down(&mut self) { if self.window.bottom < self.preview.len() { let skip = min(self.preview.len() - self.window.bottom, 30); |