diff options
| author | Fuwn <[email protected]> | 2026-02-11 04:20:56 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-02-11 04:20:56 +0000 |
| commit | ccb25641712cc61fe30438c64313c6a1434b7966 (patch) | |
| tree | 2a8f456cbcdafb6658fd558f3a236dc1a4287219 /internal/app | |
| parent | docs(README): Add instructions to run with Nix (diff) | |
| download | faustus-main.tar.xz faustus-main.zip | |
Diffstat (limited to 'internal/app')
| -rw-r--r-- | internal/app/state.go | 14 | ||||
| -rw-r--r-- | internal/app/view.go | 10 |
2 files changed, 16 insertions, 8 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) +} diff --git a/internal/app/view.go b/internal/app/view.go index 1f9fb4b..a726dae 100644 --- a/internal/app/view.go +++ b/internal/app/view.go @@ -390,9 +390,9 @@ func (m Model) renderList() string { var builder strings.Builder - listHeight := m.listHeight() + visible := m.visibleItemCount() - for index := m.offset; index < min(m.offset+listHeight, len(m.filtered)); index++ { + for index := m.offset; index < min(m.offset+visible, len(m.filtered)); index++ { session := m.filtered[index] isSelected := index == m.cursor @@ -400,9 +400,9 @@ func (m Model) renderList() string { builder.WriteString("\n") } - if len(m.filtered) > listHeight { - position := float64(m.offset) / float64(len(m.filtered)-listHeight) - indicator := fmt.Sprintf(" [%d-%d of %d]", m.offset+1, min(m.offset+listHeight, len(m.filtered)), len(m.filtered)) + if len(m.filtered) > visible { + position := float64(m.offset) / float64(len(m.filtered)-visible) + indicator := fmt.Sprintf(" [%d-%d of %d]", m.offset+1, min(m.offset+visible, len(m.filtered)), len(m.filtered)) builder.WriteString(ui.MetaStyle.Render(indicator)) |