(msg tea.Msg)
| 174 | } |
| 175 | |
| 176 | func (m selectModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { |
| 177 | var cmd tea.Cmd |
| 178 | |
| 179 | switch msg := msg.(type) { |
| 180 | case terminateMsg: |
| 181 | m.canceled = true |
| 182 | return m, tea.Quit |
| 183 | |
| 184 | case tea.KeyMsg: |
| 185 | switch msg.Type { |
| 186 | case tea.KeyCtrlC: |
| 187 | m.canceled = true |
| 188 | return m, tea.Quit |
| 189 | |
| 190 | case tea.KeyEnter: |
| 191 | options := m.filteredOptions() |
| 192 | if len(options) != 0 { |
| 193 | m.selected = options[m.cursor] |
| 194 | return m, tea.Quit |
| 195 | } |
| 196 | |
| 197 | case tea.KeyUp: |
| 198 | options := m.filteredOptions() |
| 199 | if m.cursor > 0 { |
| 200 | m.cursor-- |
| 201 | } else { |
| 202 | m.cursor = len(options) - 1 |
| 203 | } |
| 204 | |
| 205 | case tea.KeyDown: |
| 206 | options := m.filteredOptions() |
| 207 | if m.cursor < len(options)-1 { |
| 208 | m.cursor++ |
| 209 | } else { |
| 210 | m.cursor = 0 |
| 211 | } |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | if !m.hideSearch { |
| 216 | oldSearch := m.search.Value() |
| 217 | m.search, cmd = m.search.Update(msg) |
| 218 | |
| 219 | // If the search query has changed then we need to ensure |
| 220 | // the cursor is still pointing at a valid option. |
| 221 | if m.search.Value() != oldSearch { |
| 222 | options := m.filteredOptions() |
| 223 | |
| 224 | if m.cursor > len(options)-1 { |
| 225 | m.cursor = max(0, len(options)-1) |
| 226 | } |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | return m, cmd |
| 231 | } |
| 232 | |
| 233 | func (m selectModel) View() string { |
nothing calls this directly
no test coverage detected