MCPcopy Index your code
hub / github.com/anomalyco/opencode / scrollToSelection

Function scrollToSelection

packages/tui/src/ui/dialog-select.tsx:311–342  ·  view source on GitHub ↗
(center: boolean)

Source from the content-addressed store, hash-verified

309 }
310
311 function scrollToSelection(center: boolean) {
312 if (!scroll) return
313 let remaining = store.selected
314 let index = 0
315 // Locate the row by position because a unique renderable ID cannot currently be ensured.
316 for (const [category, options] of grouped()) {
317 if (category) index++
318 if (remaining < options.length) {
319 index += remaining
320 break
321 }
322 index += options.length
323 remaining -= options.length
324 }
325 const target = scroll.getChildren()[index]
326 if (!target) return
327 const y = target.y - scroll.y
328 if (center) {
329 const centerOffset = Math.floor(scroll.height / 2)
330 scroll.scrollBy(y - centerOffset)
331 } else {
332 if (y >= scroll.height) {
333 scroll.scrollBy(y - scroll.height + 1)
334 }
335 if (y < 0) {
336 scroll.scrollBy(y)
337 if (isDeepEqual(flat()[0].value, selected()?.value)) {
338 scroll.scrollTo(0)
339 }
340 }
341 }
342 }
343
344 function submit() {
345 if (props.locked) return

Callers 2

DialogSelectFunction · 0.85
moveToFunction · 0.85

Calls 2

groupedFunction · 0.85
selectedFunction · 0.50

Tested by

no test coverage detected