Commit 1695850319
Unsigned
Layout: unified · split
internal/selection_menu.go +15
| @@ -27,6 +27,9 @@ func (m Model) Init() tea.Cmd { | ||
| 27 | 27 | |
| 28 | 28 | // Update handles user input and updates the model |
| 29 | 29 | func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { |
| 30 | // Only filter options if a key press modifies the filter | |
| 31 | updateFilter := false | |
| 32 | ||
| 30 | 33 | switch msg := msg.(type) { |
| 31 | 34 | case tea.KeyMsg: |
| 32 | 35 | switch msg.String() { |
| @@ -35,12 +38,15 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { | ||
| 35 | 38 | case "backspace": |
| 36 | 39 | if len(m.filter) > 0 { |
| 37 | 40 | m.filter = m.filter[:len(m.filter)-1] |
| 41 | updateFilter = true // Mark for updating the filter | |
| 38 | 42 | } |
| 39 | 43 | case "down": |
| 44 | // Move cursor down within bounds | |
| 40 | 45 | if m.selected < len(m.filteredKeys)-1 { |
| 41 | 46 | m.selected++ |
| 42 | 47 | } |
| 43 | 48 | case "up": |
| 49 | // Move cursor up within bounds | |
| 44 | 50 | if m.selected > 0 { |
| 45 | 51 | m.selected-- |
| 46 | 52 | } |
| @@ -49,13 +55,22 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { | ||
| 49 | 55 | default: |
| 50 | 56 | if msg.String() != "" { |
| 51 | 57 | m.filter += msg.String() |
| 58 | updateFilter = true // Mark for updating the filter | |
| 52 | 59 | } |
| 53 | 60 | } |
| 61 | } | |
| 62 | ||
| 63 | // Only filter options if the filter was actually modified | |
| 64 | if updateFilter { | |
| 54 | 65 | m.filterOptions() |
| 66 | // Reset selected index after filtering | |
| 67 | m.selected = 0 | |
| 55 | 68 | } |
| 69 | ||
| 56 | 70 | return m, nil |
| 57 | 71 | } |
| 58 | 72 | |
| 73 | ||
| 59 | 74 | // View renders the UI |
| 60 | 75 | func (m Model) View() string { |
| 61 | 76 | var b strings.Builder |