MCPcopy Index your code
hub / github.com/coder/coder / Update

Method Update

cli/cliui/select.go:176–231  ·  view source on GitHub ↗
(msg tea.Msg)

Source from the content-addressed store, hash-verified

174}
175
176func (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
233func (m selectModel) View() string {

Callers

nothing calls this directly

Calls 3

filteredOptionsMethod · 0.95
UpdateMethod · 0.65
ValueMethod · 0.45

Tested by

no test coverage detected