From 0fdf18e77d6fb085c541157781acb1a1f21f8f78 Mon Sep 17 00:00:00 2001 From: kyu08 <49891479+kyu08@users.noreply.github.com> Date: Mon, 26 Aug 2024 00:44:25 +0900 Subject: [PATCH] fix ScrollPercent --- viewport/viewport.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/viewport/viewport.go b/viewport/viewport.go index ae044c22..dea45600 100644 --- a/viewport/viewport.go +++ b/viewport/viewport.go @@ -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)) }