( title, searchTitle string, defaults, persistent []string, searchFunc func(string) MultiSelectSearchResult, )
| 68 | } |
| 69 | |
| 70 | func newMultiSelectSearchField( |
| 71 | title, searchTitle string, |
| 72 | defaults, persistent []string, |
| 73 | searchFunc func(string) MultiSelectSearchResult, |
| 74 | ) *multiSelectSearchField { |
| 75 | ti := textinput.New() |
| 76 | ti.Prompt = "> " |
| 77 | ti.Placeholder = "Type to search" |
| 78 | ti.Focus() |
| 79 | |
| 80 | selected := make(map[string]bool) |
| 81 | for _, k := range defaults { |
| 82 | selected[k] = true |
| 83 | } |
| 84 | |
| 85 | m := &multiSelectSearchField{ |
| 86 | title: title, |
| 87 | searchTitle: searchTitle, |
| 88 | searchFunc: searchFunc, |
| 89 | mode: msModeSearch, |
| 90 | search: ti, |
| 91 | selected: selected, |
| 92 | optionLabels: make(map[string]string), |
| 93 | defaultValues: defaults, |
| 94 | persistent: persistent, |
| 95 | height: 10, |
| 96 | spinner: spinner.New(spinner.WithSpinner(spinner.Line)), |
| 97 | } |
| 98 | |
| 99 | // Load initial results synchronously (form hasn't started yet). |
| 100 | m.applySearchResult("", m.searchFunc("")) |
| 101 | |
| 102 | return m |
| 103 | } |
| 104 | |
| 105 | // startSearch launches an async search and returns a tea.Cmd that will |
| 106 | // deliver the result via msSearchResultMsg. |
no test coverage detected