Skip to content

Commit

Permalink
Fix vim scrolling
Browse files Browse the repository at this point in the history
  • Loading branch information
sayanarijit committed May 5, 2024
1 parent 41648ce commit 805e159
Showing 1 changed file with 8 additions and 20 deletions.
28 changes: 8 additions & 20 deletions src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -778,27 +778,15 @@ impl UI<'_> {
self.scrolltop = height * (dir.focus / height.max(1))
} else {
// Vim-like-scrolling
self.scrolltop = match dir.focus.cmp(&self.scrolltop) {
Ordering::Greater => {
// Scrolling down
if dir.focus >= self.scrolltop + height {
dir.focus.saturating_sub(height + 1)
} else {
self.scrolltop
}
}
Ordering::Less => dir.focus,
Ordering::Equal => self.scrolltop,
};

// Add padding if possible
let padding = app.config.general.scroll_padding;
if padding != 0 {
if dir.focus < self.scrolltop + padding {
self.scrolltop = dir.focus.saturating_sub(padding);
} else if dir.focus >= self.scrolltop + height - padding {
self.scrolltop = dir.focus + padding - height + 1;
};
if dir.focus >= (self.scrolltop + height).saturating_sub(padding) {
// Scrolling down
self.scrolltop = (dir.focus + padding + 1)
.saturating_sub(height)
.min(dir.total.saturating_sub(height));
} else if dir.focus < self.scrolltop + padding {
// Scrolling up
self.scrolltop = dir.focus.saturating_sub(padding);
}
};

Expand Down

0 comments on commit 805e159

Please sign in to comment.