Fix bug where scroll wheel could create duplicate lines on top and bottom

This commit is contained in:
Christian Rocha 2020-07-20 17:46:15 -04:00
parent 5a26cb0d8e
commit 5357dd61bd
No known key found for this signature in database
GPG Key ID: D6CC7A16E5878018

View File

@ -173,6 +173,12 @@ func (m *Model) LineDown(n int) (lines []string) {
return nil
}
// Make sure the number of lines by which we're going to scroll isn't
// greater than the number of lines we actually have left before we reach
// the bottom.
maxDelta := (len(m.lines) - 1) - (m.YOffset + m.Height) // number of lines - viewport bottom edge
n = min(n, maxDelta)
m.YOffset = min(
m.YOffset+n, // target
len(m.lines)-1-m.Height, // fallback
@ -194,6 +200,10 @@ func (m *Model) LineUp(n int) (lines []string) {
return nil
}
// Make sure the number of lines by which we're going to scroll isn't
// greater than the number of lines we are from the top.
n = min(n, m.YOffset)
m.YOffset = max(m.YOffset-n, 0)
if len(m.lines) > 0 {