clear filter via esc

This commit is contained in:
2025-07-13 20:19:41 -07:00
parent 928db70011
commit 460917ceca
4 changed files with 21 additions and 5 deletions

View File

@@ -18,6 +18,7 @@ const (
// Custom message types // Custom message types
type ( type (
SwitchToTableListMsg struct{} SwitchToTableListMsg struct{}
SwitchToTableListClearMsg struct{} // Switch to table list and clear any filter
SwitchToTableDataMsg struct{ TableIndex int } SwitchToTableDataMsg struct{ TableIndex int }
SwitchToRowDetailMsg struct{ RowIndex int } SwitchToRowDetailMsg struct{ RowIndex int }
SwitchToRowDetailFromQueryMsg struct{ RowIndex int } SwitchToRowDetailFromQueryMsg struct{ RowIndex int }
@@ -519,6 +520,14 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.currentView = NewTableListModel(m.getSharedData()) m.currentView = NewTableListModel(m.getSharedData())
return m, nil return m, nil
case SwitchToTableListClearMsg:
shared := m.getSharedData()
// Clear any table filter
shared.FilteredTables = make([]string, len(shared.Tables))
copy(shared.FilteredTables, shared.Tables)
m.currentView = NewTableListModel(shared)
return m, nil
case SwitchToTableDataMsg: case SwitchToTableDataMsg:
shared := m.getSharedData() shared := m.getSharedData()
shared.SelectedTable = msg.TableIndex shared.SelectedTable = msg.TableIndex

View File

@@ -57,7 +57,7 @@ func (m *QueryModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
func (m *QueryModel) handleQueryInput(msg tea.KeyMsg) (tea.Model, tea.Cmd) { func (m *QueryModel) handleQueryInput(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
switch msg.String() { switch msg.String() {
case "esc": case "esc":
return m, func() tea.Msg { return SwitchToTableListMsg{} } return m, func() tea.Msg { return SwitchToTableListClearMsg{} }
case "enter": case "enter":
if strings.TrimSpace(m.query) != "" { if strings.TrimSpace(m.query) != "" {
@@ -108,7 +108,7 @@ func (m *QueryModel) handleResultsNavigation(msg tea.KeyMsg) (tea.Model, tea.Cmd
switch msg.String() { switch msg.String() {
case "esc", "q": case "esc", "q":
m.gPressed = false m.gPressed = false
return m, func() tea.Msg { return SwitchToTableListMsg{} } return m, func() tea.Msg { return SwitchToTableListClearMsg{} }
case "g": case "g":
if m.gPressed { if m.gPressed {

View File

@@ -61,7 +61,7 @@ func (m *TableDataModel) handleNavigation(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
switch msg.String() { switch msg.String() {
case "q": case "q":
m.gPressed = false m.gPressed = false
return m, func() tea.Msg { return SwitchToTableListMsg{} } return m, func() tea.Msg { return SwitchToTableListClearMsg{} }
case "esc": case "esc":
m.gPressed = false m.gPressed = false
@@ -71,7 +71,7 @@ func (m *TableDataModel) handleNavigation(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
m.filterData() m.filterData()
return m, nil return m, nil
} }
return m, func() tea.Msg { return SwitchToTableListMsg{} } return m, func() tea.Msg { return SwitchToTableListClearMsg{} }
case "g": case "g":
if m.gPressed { if m.gPressed {

View File

@@ -42,7 +42,14 @@ func (m *TableListModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
func (m *TableListModel) handleSearchInput(msg tea.KeyMsg) (tea.Model, tea.Cmd) { func (m *TableListModel) handleSearchInput(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
switch msg.String() { switch msg.String() {
case "esc", "enter": case "esc":
m.searching = false
// If there's an existing filter, clear it
if m.searchInput != "" {
m.searchInput = ""
m.filterTables()
}
case "enter":
m.searching = false m.searching = false
m.filterTables() m.filterTables()
case "backspace": case "backspace":