Skip to content

Commit

Permalink
fix ScrollPercent
Browse files Browse the repository at this point in the history
  • Loading branch information
kyu08 committed Aug 25, 2024
1 parent ba5fe39 commit 0fdf18e
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions viewport/viewport.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,14 @@ func (m Model) PastBottom() bool {

// ScrollPercent returns the amount scrolled as a float between 0 and 1.
func (m Model) ScrollPercent() float64 {
if m.Height >= len(m.lines) {
actualDisplayedLength := len(linesToActualDisplayedLines(m.lines, m.Width))

if m.Height >= actualDisplayedLength {
return 1.0
}
y := float64(m.YOffset)
h := float64(m.Height)
t := float64(len(m.lines))
t := float64(actualDisplayedLength)
v := y / (t - h)
return math.Max(0.0, math.Min(1.0, v))
}
Expand Down

0 comments on commit 0fdf18e

Please sign in to comment.