mirror of
https://github.com/Gu1llaum-3/sshm.git
synced 2026-01-27 03:04:21 +01:00
fix: resolve search behavior when cursor is not at top of list
- Fix search mode not triggering properly after navigation - Preserve cursor position during filtering operations - Add comprehensive UI tests for search functionality - Improve search to include user field filtering
This commit is contained in:
@@ -364,6 +364,7 @@ func (m Model) handleListViewKeys(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
m.updateTableStyles()
|
||||
m.table.Blur()
|
||||
m.searchInput.Focus()
|
||||
// Don't trigger filtering when entering search mode - wait for user input
|
||||
return m, textinput.Blink
|
||||
}
|
||||
case "tab":
|
||||
@@ -381,6 +382,7 @@ func (m Model) handleListViewKeys(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
m.updateTableStyles()
|
||||
m.table.Blur()
|
||||
m.searchInput.Focus()
|
||||
// Don't trigger filtering when switching to search mode
|
||||
return m, textinput.Blink
|
||||
}
|
||||
return m, nil
|
||||
@@ -619,12 +621,17 @@ func (m Model) handleListViewKeys(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
m.searchInput, cmd = m.searchInput.Update(msg)
|
||||
// Update filtered hosts only if the search value has changed
|
||||
if m.searchInput.Value() != oldValue {
|
||||
currentCursor := m.table.Cursor()
|
||||
if m.searchInput.Value() != "" {
|
||||
m.filteredHosts = m.filterHosts(m.searchInput.Value())
|
||||
} else {
|
||||
m.filteredHosts = m.sortHosts(m.hosts)
|
||||
}
|
||||
m.updateTableRows()
|
||||
// If the current cursor position is beyond the filtered results, reset to 0
|
||||
if currentCursor >= len(m.filteredHosts) && len(m.filteredHosts) > 0 {
|
||||
m.table.SetCursor(0)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
m.table, cmd = m.table.Update(msg)
|
||||
|
||||
Reference in New Issue
Block a user