mirror of
https://github.com/Maks1mS/bubbles.git
synced 2025-01-11 14:38:10 +03:00
Fix bug where scroll wheel could create duplicate lines on top and bottom
This commit is contained in:
parent
5a26cb0d8e
commit
5357dd61bd
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user