tweaks to controls for pagination

This commit is contained in:
2025-07-13 20:06:40 -07:00
parent 2fa8ebe741
commit 1d9c8fff73
4 changed files with 174 additions and 6 deletions

View File

@@ -13,6 +13,7 @@ type TableListModel struct {
searching bool
selectedTable int
currentPage int
gPressed bool
}
func NewTableListModel(shared *SharedData) *TableListModel {
@@ -59,12 +60,47 @@ func (m *TableListModel) handleSearchInput(msg tea.KeyMsg) (tea.Model, tea.Cmd)
func (m *TableListModel) handleNavigation(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
switch msg.String() {
case "esc":
if m.searchInput != "" {
// Clear search filter
m.searchInput = ""
m.filterTables()
m.gPressed = false
return m, nil
}
// If no filter, escape does nothing (could exit app but that's handled at higher level)
m.gPressed = false
return m, nil
case "/":
m.searching = true
m.searchInput = ""
m.gPressed = false
return m, nil
case "g":
if m.gPressed {
// Second g - go to beginning
m.selectedTable = 0
m.currentPage = 0
m.gPressed = false
} else {
// First g - wait for second g
m.gPressed = true
}
return m, nil
case "G":
// Go to end
if len(m.Shared.FilteredTables) > 0 {
m.selectedTable = len(m.Shared.FilteredTables) - 1
m.adjustPage()
}
m.gPressed = false
return m, nil
case "enter":
m.gPressed = false
if len(m.Shared.FilteredTables) > 0 {
return m, func() tea.Msg {
return SwitchToTableDataMsg{TableIndex: m.selectedTable}
@@ -72,32 +108,38 @@ func (m *TableListModel) handleNavigation(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
}
case "s":
m.gPressed = false
return m, func() tea.Msg { return SwitchToQueryMsg{} }
case "r":
m.gPressed = false
if err := m.Shared.LoadTables(); err == nil {
m.filterTables()
}
case "up", "k":
m.gPressed = false
if m.selectedTable > 0 {
m.selectedTable--
m.adjustPage()
}
case "down", "j":
m.gPressed = false
if m.selectedTable < len(m.Shared.FilteredTables)-1 {
m.selectedTable++
m.adjustPage()
}
case "left", "h":
m.gPressed = false
if m.currentPage > 0 {
m.currentPage--
m.selectedTable = m.currentPage * m.getVisibleCount()
}
case "right", "l":
m.gPressed = false
maxPage := (len(m.Shared.FilteredTables) - 1) / m.getVisibleCount()
if m.currentPage < maxPage {
m.currentPage++
@@ -106,6 +148,10 @@ func (m *TableListModel) handleNavigation(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
m.selectedTable = len(m.Shared.FilteredTables) - 1
}
}
default:
// Any other key resets the g state
m.gPressed = false
}
return m, nil
}
@@ -190,7 +236,7 @@ func (m *TableListModel) View() string {
if m.searching {
content.WriteString(HelpStyle.Render("Type to search • enter/esc: finish search"))
} else {
content.WriteString(HelpStyle.Render("↑/↓: navigate • ←/→: page • /: search • enter: view • s: SQL • r: refresh • ctrl+c: quit"))
content.WriteString(HelpStyle.Render("↑/↓: navigate • ←/→: page • /: search • enter: view • s: SQL • r: refresh • gg/G: first/last • ctrl+c: quit"))
}
return content.String()