(msg tea.Msg)
| 463 | } |
| 464 | |
| 465 | func (m multiSelectModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { |
| 466 | var cmd tea.Cmd |
| 467 | |
| 468 | if m.isCustomInputMode { |
| 469 | return m.handleCustomInputMode(msg) |
| 470 | } |
| 471 | |
| 472 | switch msg := msg.(type) { |
| 473 | case terminateMsg: |
| 474 | m.canceled = true |
| 475 | return m, tea.Quit |
| 476 | |
| 477 | case tea.KeyMsg: |
| 478 | switch msg.Type { |
| 479 | case tea.KeyCtrlC: |
| 480 | m.canceled = true |
| 481 | return m, tea.Quit |
| 482 | |
| 483 | case tea.KeyEnter: |
| 484 | // Switch to custom input mode if we're on the "+ Add custom value:" option |
| 485 | if m.enableCustomInput && m.cursor == len(m.filteredOptions()) { |
| 486 | m.isCustomInputMode = true |
| 487 | return m, nil |
| 488 | } |
| 489 | if len(m.options) != 0 { |
| 490 | m.selected = true |
| 491 | return m, tea.Quit |
| 492 | } |
| 493 | |
| 494 | case tea.KeySpace: |
| 495 | options := m.filteredOptions() |
| 496 | |
| 497 | if m.enableCustomInput && m.cursor == len(options) { |
| 498 | return m, nil |
| 499 | } |
| 500 | |
| 501 | if len(options) != 0 { |
| 502 | options[m.cursor].chosen = !options[m.cursor].chosen |
| 503 | } |
| 504 | // We back out early here otherwise a space will be inserted |
| 505 | // into the search field. |
| 506 | return m, nil |
| 507 | |
| 508 | case tea.KeyUp: |
| 509 | maxIndex := m.getMaxIndex() |
| 510 | if m.cursor > 0 { |
| 511 | m.cursor-- |
| 512 | } else { |
| 513 | m.cursor = maxIndex |
| 514 | } |
| 515 | |
| 516 | case tea.KeyDown: |
| 517 | maxIndex := m.getMaxIndex() |
| 518 | if m.cursor < maxIndex { |
| 519 | m.cursor++ |
| 520 | } else { |
| 521 | m.cursor = 0 |
| 522 | } |
nothing calls this directly
no test coverage detected