mirror of
https://github.com/zoriya/bubbles.git
synced 2026-08-16 01:43:21 +00:00
fix: visible lines take frame into account
This commit is contained in:
@@ -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
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user