MCPcopy
hub / github.com/g3n/engine / selNext

Method selNext

gui/list.go:238–291  ·  view source on GitHub ↗

selNext selects or highlights the next item, if possible

(sel bool, update bool)

Source from the content-addressed store, hash-verified

236
237// selNext selects or highlights the next item, if possible
238func (li *List) selNext(sel bool, update bool) *ListItem {
239
240 // Checks for empty list
241 if len(li.items) == 0 {
242 return nil
243 }
244 // Find currently selected item
245 var pos int
246 if sel {
247 pos = li.selected()
248 } else {
249 pos = li.highlighted()
250 }
251
252 var newItem *ListItem
253 newSel := true
254 // If no item found, returns first.
255 if pos < 0 {
256 newItem = li.items[0].(*ListItem)
257 if sel {
258 newItem.SetSelected(true)
259 } else {
260 newItem.SetHighlighted(true)
261 }
262 } else {
263 item := li.items[pos].(*ListItem)
264 // Item is not the last, get next
265 if pos < len(li.items)-1 {
266 newItem = li.items[pos+1].(*ListItem)
267 if sel {
268 item.SetSelected(false)
269 newItem.SetSelected(true)
270 } else {
271 item.SetHighlighted(false)
272 newItem.SetHighlighted(true)
273 }
274 if !li.ItemVisible(pos + 1) {
275 li.ScrollDown()
276 }
277 // Item is the last, don't change
278 } else {
279 newItem = item
280 newSel = false
281 }
282 }
283
284 if update {
285 li.update()
286 }
287 if sel && newSel {
288 li.Dispatch(OnChange, nil)
289 }
290 return newItem
291}
292
293// selPrev selects or highlights the next item, if possible
294func (li *List) selPrev(sel bool, update bool) *ListItem {

Callers 1

onKeyEventMethod · 0.95

Calls 9

selectedMethod · 0.95
highlightedMethod · 0.95
SetSelectedMethod · 0.95
SetHighlightedMethod · 0.95
updateMethod · 0.95
ItemVisibleMethod · 0.80
ScrollDownMethod · 0.80
DispatchMethod · 0.65
SetSelectedMethod · 0.45

Tested by

no test coverage detected