fix: visible lines take frame into account

This commit is contained in:
Carlos Alexandro Becker
2025-01-07 15:18:30 -03:00
parent 36be8b62a6
commit 4aff9daeed
+6 -3
View File
@@ -146,19 +146,22 @@ func (m Model) maxYOffset() int {
// visibleLines returns the lines that should currently be visible in the // visibleLines returns the lines that should currently be visible in the
// viewport. // viewport.
func (m Model) visibleLines() (lines []string) { func (m Model) visibleLines() (lines []string) {
h := m.Height - m.Style.GetVerticalFrameSize()
w := m.Width - m.Style.GetHorizontalFrameSize()
if len(m.lines) > 0 { if len(m.lines) > 0 {
top := max(0, m.YOffset) top := max(0, m.YOffset)
bottom := clamp(m.YOffset+m.Height, top, len(m.lines)) bottom := clamp(m.YOffset+h, top, len(m.lines))
lines = m.lines[top:bottom] lines = m.lines[top:bottom]
} }
if (m.xOffset == 0 && m.longestLineWidth <= m.Width) || m.Width == 0 { if (m.xOffset == 0 && m.longestLineWidth <= w) || w == 0 {
return lines return lines
} }
cutLines := make([]string, len(lines)) cutLines := make([]string, len(lines))
for i := range lines { for i := range lines {
cutLines[i] = ansi.Cut(lines[i], m.xOffset, m.xOffset+m.Width) cutLines[i] = ansi.Cut(lines[i], m.xOffset, m.xOffset+w)
} }
return cutLines return cutLines
} }