enable swapping focus into the table

This commit is contained in:
2025-07-11 23:24:25 -07:00
parent e79d20f7ce
commit c32d200c15
4 changed files with 176 additions and 41 deletions

35
main.go
View File

@@ -18,14 +18,16 @@ const (
// Custom message types
type (
switchToTableListMsg struct{}
switchToTableDataMsg struct{ tableIndex int }
switchToRowDetailMsg struct{ rowIndex int }
switchToEditCellMsg struct{ rowIndex, colIndex int }
switchToQueryMsg struct{}
refreshDataMsg struct{}
updateCellMsg struct{ rowIndex, colIndex int; value string }
executeQueryMsg struct{ query string }
switchToTableListMsg struct{}
switchToTableDataMsg struct{ tableIndex int }
switchToRowDetailMsg struct{ rowIndex int }
switchToRowDetailFromQueryMsg struct{ rowIndex int }
switchToEditCellMsg struct{ rowIndex, colIndex int }
switchToQueryMsg struct{}
returnToQueryMsg struct{} // Return to query mode from row detail
refreshDataMsg struct{}
updateCellMsg struct{ rowIndex, colIndex int; value string }
executeQueryMsg struct{ query string }
)
// Common interface for all models
@@ -378,6 +380,12 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.currentView = newRowDetailModel(m.getSharedData(), msg.rowIndex)
return m, nil
case switchToRowDetailFromQueryMsg:
rowDetail := newRowDetailModel(m.getSharedData(), msg.rowIndex)
rowDetail.fromQuery = true
m.currentView = rowDetail
return m, nil
case switchToEditCellMsg:
m.currentView = newEditCellModel(m.getSharedData(), msg.rowIndex, msg.colIndex)
return m, nil
@@ -386,6 +394,17 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.currentView = newQueryModel(m.getSharedData())
return m, nil
case returnToQueryMsg:
// Return to query mode, preserving the query state if possible
if queryView, ok := m.currentView.(*queryModel); ok {
// If we're already in query mode, just switch focus back to results
queryView.focusOnInput = false
} else {
// Create new query model
m.currentView = newQueryModel(m.getSharedData())
}
return m, nil
case refreshDataMsg:
shared := m.getSharedData()
if err := shared.loadTableData(); err != nil {