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