fix(tui): Center the initially selected session in the session_list (resolves #8558) (#8560)

This commit is contained in:
Ariane Emory
2026-01-15 02:04:20 -05:00
committed by GitHub
parent 6473e15793
commit 08ca1237cc

View File

@@ -109,15 +109,16 @@ export function DialogSelect<T>(props: DialogSelectProps<T>) {
createEffect( createEffect(
on([() => store.filter, () => props.current], ([filter, current]) => { on([() => store.filter, () => props.current], ([filter, current]) => {
if (filter.length > 0) { setTimeout(() => {
setStore("selected", 0) if (filter.length > 0) {
} else if (current) { moveTo(0, true)
const currentIndex = flat().findIndex((opt) => isDeepEqual(opt.value, current)) } else if (current) {
if (currentIndex >= 0) { const currentIndex = flat().findIndex((opt) => isDeepEqual(opt.value, current))
setStore("selected", currentIndex) if (currentIndex >= 0) {
moveTo(currentIndex, true)
}
} }
} }, 0)
scroll?.scrollTo(0)
}), }),
) )
@@ -129,7 +130,7 @@ export function DialogSelect<T>(props: DialogSelectProps<T>) {
moveTo(next) moveTo(next)
} }
function moveTo(next: number) { function moveTo(next: number, center = false) {
setStore("selected", next) setStore("selected", next)
props.onMove?.(selected()!) props.onMove?.(selected()!)
if (!scroll) return if (!scroll) return
@@ -138,13 +139,18 @@ export function DialogSelect<T>(props: DialogSelectProps<T>) {
}) })
if (!target) return if (!target) return
const y = target.y - scroll.y const y = target.y - scroll.y
if (y >= scroll.height) { if (center) {
scroll.scrollBy(y - scroll.height + 1) const centerOffset = Math.floor(scroll.height / 2)
} scroll.scrollBy(y - centerOffset)
if (y < 0) { } else {
scroll.scrollBy(y) if (y >= scroll.height) {
if (isDeepEqual(flat()[0].value, selected()?.value)) { scroll.scrollBy(y - scroll.height + 1)
scroll.scrollTo(0) }
if (y < 0) {
scroll.scrollBy(y)
if (isDeepEqual(flat()[0].value, selected()?.value)) {
scroll.scrollTo(0)
}
} }
} }
} }