diff options
Diffstat (limited to 'internal/app/state.go')
| -rw-r--r-- | internal/app/state.go | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/internal/app/state.go b/internal/app/state.go index 6b24d80..aa9fb77 100644 --- a/internal/app/state.go +++ b/internal/app/state.go @@ -88,14 +88,14 @@ func (m *Model) reloadSessions() { } func (m *Model) ensureVisible() { - visibleHeight := m.listHeight() + visible := m.visibleItemCount() if m.cursor < m.offset { m.offset = m.cursor } - if m.cursor >= m.offset+visibleHeight { - m.offset = m.cursor - visibleHeight + 1 + if m.cursor >= m.offset+visible { + m.offset = m.cursor - visible + 1 } } @@ -120,3 +120,11 @@ func (m Model) listHeight() int { return max(1, m.height-reserved) } + +func (m Model) visibleItemCount() int { + if m.showPreview { + return m.listHeight() - 2 + } + + return max(1, m.listHeight()/2) +} |