Skip to content

Commit

Permalink
make sure the bottom of the data stays at the bottom (#51)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
amtoine authored Apr 15, 2024
1 parent 8906b4a commit 1d98577
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 1d98577

Please sign in to comment.