MCPcopy Create free account
hub / github.com/anomalyco/opencode / scrollIntoView

Function scrollIntoView

packages/ui/src/components/list.tsx:71–88  ·  view source on GitHub ↗
(container: HTMLDivElement, node: HTMLElement, block: "center" | "nearest")

Source from the content-addressed store, hash-verified

69 const setInternalFilter = (value: string) => setStore("internalFilter", value)
70
71 const scrollIntoView = (container: HTMLDivElement, node: HTMLElement, block: "center" | "nearest") => {
72 const containerRect = container.getBoundingClientRect()
73 const nodeRect = node.getBoundingClientRect()
74 const top = nodeRect.top - containerRect.top + container.scrollTop
75 const bottom = top + nodeRect.height
76 const viewTop = container.scrollTop
77 const viewBottom = viewTop + container.clientHeight
78 const target =
79 block === "center"
80 ? top - container.clientHeight / 2 + nodeRect.height / 2
81 : top < viewTop
82 ? top
83 : bottom > viewBottom
84 ? bottom - container.clientHeight
85 : viewTop
86 const max = Math.max(0, container.scrollHeight - container.clientHeight)
87 container.scrollTop = Math.max(0, Math.min(target, max))
88 }
89
90 const { filter, grouped, flat, active, setActive, onKeyDown, onInput, refetch } = useFilteredList<T>(props)
91

Callers 1

ListFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected