handleCustomInputSubmission processes the submission of custom input
()
| 586 | |
| 587 | // handleCustomInputSubmission processes the submission of custom input |
| 588 | func (m *multiSelectModel) handleCustomInputSubmission() (tea.Model, tea.Cmd) { |
| 589 | if m.customInput == "" { |
| 590 | m.isCustomInputMode = false |
| 591 | return m, nil |
| 592 | } |
| 593 | |
| 594 | // Clear search to ensure option is visible and cursor points to the new option |
| 595 | m.search.SetValue("") |
| 596 | |
| 597 | // Check for duplicates |
| 598 | for i, opt := range m.options { |
| 599 | if opt.option == m.customInput { |
| 600 | // If the option exists but isn't chosen, select it |
| 601 | if !opt.chosen { |
| 602 | opt.chosen = true |
| 603 | } |
| 604 | |
| 605 | // Point cursor to the new option |
| 606 | m.cursor = i |
| 607 | |
| 608 | // Reset custom input mode to disabled |
| 609 | m.isCustomInputMode = false |
| 610 | m.customInput = "" |
| 611 | return m, nil |
| 612 | } |
| 613 | } |
| 614 | |
| 615 | // Add new unique option |
| 616 | m.options = append(m.options, &multiSelectOption{ |
| 617 | option: m.customInput, |
| 618 | chosen: true, |
| 619 | }) |
| 620 | |
| 621 | // Point cursor to the newly added option |
| 622 | m.cursor = len(m.options) - 1 |
| 623 | |
| 624 | // Reset custom input mode to disabled |
| 625 | m.customInput = "" |
| 626 | m.isCustomInputMode = false |
| 627 | return m, nil |
| 628 | } |
| 629 | |
| 630 | // handleCustomInputBackspace handles backspace in custom input mode |
| 631 | func (m *multiSelectModel) handleCustomInputBackspace() (tea.Model, tea.Cmd) { |
no test coverage detected