From 1d98577f10cdfa665393c32728aab386a8de7510 Mon Sep 17 00:00:00 2001 From: Antoine Stevan <44101798+amtoine@users.noreply.github.com> Date: Mon, 15 Apr 2024 18:19:39 +0200 Subject: [PATCH] make sure the bottom of the data stays at the bottom (#51) in large data, getting close to the bottom would make the last element "lift off" the bottom of the frame, leaving empty lines below it even though there is enough lines to fill the entire frame... this PR constrains the "tops" to be less than `nb_lines - height`, forcing the last element of the data to always be at the bottom if there are enough lines to fill the frame. --- src/ui.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/ui.rs b/src/ui.rs index bf2c87b..857ae77 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -333,11 +333,15 @@ fn render_data(frame: &mut Frame, app: &mut App, config: &Config) { if cursor >= top + height - margin { app.rendering_tops.pop(); - app.rendering_tops - .push((cursor - height + margin + 1).max(0)); + app.rendering_tops.push( + (cursor - height + margin + 1) + .min(nb_lines as i32 - height) + .max(0), + ); } else if cursor <= top + margin { app.rendering_tops.pop(); - app.rendering_tops.push((cursor - margin).max(0)); + app.rendering_tops + .push((cursor - margin).min(nb_lines as i32 - height).max(0)); } let margin_offset = *app.rendering_tops.last().unwrap_or(&0) as usize;