The open source coding agent.
TypeScript
fix(app): layout jumping
Adam092428633fe0
diff --git a/packages/ui/src/components/list.tsx b/packages/ui/src/components/list.tsxindex b8a8f746072..874638c5a51 100644--- a/packages/ui/src/components/list.tsx+++ b/packages/ui/src/components/list.tsx@@ -35,6 +35,25 @@ export function List<T>(props: ListProps<T> & { ref?: (ref: ListRef) => void })mouseActive: false,})+ const scrollIntoView = (container: HTMLDivElement, node: HTMLElement, block: "center" | "nearest") => {+ const containerRect = container.getBoundingClientRect()+ const nodeRect = node.getBoundingClientRect()+ const top = nodeRect.top - containerRect.top + container.scrollTop+ const bottom = top + nodeRect.height+ const viewTop = container.scrollTop+ const viewBottom = viewTop + container.clientHeight+ const target =+ block === "center"+ ? top - container.clientHeight / 2 + nodeRect.height / 2+ : top < viewTop+ ? top+ : bottom > viewBottom+ ? bottom - container.clientHeight+ : viewTop+ const max = Math.max(0, container.scrollHeight - container.clientHeight)+ container.scrollTop = Math.max(0, Math.min(target, max))+ }+const { filter, grouped, flat, active, setActive, onKeyDown, onInput } = useFilteredList<T>(props)const searchProps = () => (typeof props.search === "object" ? props.search : {})@@ -65,24 +84,31 @@ export function List<T>(props: ListProps<T> & { ref?: (ref: ListRef) => void }))createEffect(() => {- if (!scrollRef()) return+ const scroll = scrollRef()+ if (!scroll) returnif (!props.current) returnconst key = props.key(props.current)requestAnimationFrame(() => {- const element = scrollRef()?.querySelector(`[data-key="${CSS.escape(key)}"]`)- element?.scrollIntoView({ block: "center" })+ const element = scroll.querySelector(`[data-key="${CSS.escape(key)}"]`)+ if (!(element instanceof HTMLElement)) return+ scrollIntoView(scroll, element, "center")})})createEffect(() => {const all = flat()if (store.mouseActive || all.length === 0) return+ const scroll = scrollRef()+ if (!scroll) returnif (active() === props.key(all[0])) {- scrollRef()?.scrollTo(0, 0)+ scroll.scrollTo(0, 0)return}- const element = scrollRef()?.querySelector(`[data-key="${CSS.escape(active()!)}"]`)- element?.scrollIntoView({ block: "center" })+ const key = active()+ if (!key) return+ const element = scroll.querySelector(`[data-key="${CSS.escape(key)}"]`)+ if (!(element instanceof HTMLElement)) return+ scrollIntoView(scroll, element, "center")})createEffect(() => {