summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAriane Emory <[email protected]>2026-01-15 02:04:20 -0500
committerGitHub <[email protected]>2026-01-15 01:04:20 -0600
commit08ca1237cc25634e2af97a62d036a48a80dc8d6e (patch)
treee2107593d67eedd1fe5ce129df7a88345e5f997d
parent6473e15793b71413ef1bcc1048c858993b201c92 (diff)
downloadopencode-08ca1237cc25634e2af97a62d036a48a80dc8d6e.tar.gz
opencode-08ca1237cc25634e2af97a62d036a48a80dc8d6e.zip
fix(tui): Center the initially selected session in the session_list (resolves #8558) (#8560)
-rw-r--r--packages/opencode/src/cli/cmd/tui/ui/dialog-select.tsx38
1 files changed, 22 insertions, 16 deletions
diff --git a/packages/opencode/src/cli/cmd/tui/ui/dialog-select.tsx b/packages/opencode/src/cli/cmd/tui/ui/dialog-select.tsx
index a0ab462a5..f7d7306d0 100644
--- a/packages/opencode/src/cli/cmd/tui/ui/dialog-select.tsx
+++ b/packages/opencode/src/cli/cmd/tui/ui/dialog-select.tsx
@@ -109,15 +109,16 @@ export function DialogSelect<T>(props: DialogSelectProps<T>) {
createEffect(
on([() => store.filter, () => props.current], ([filter, current]) => {
- if (filter.length > 0) {
- setStore("selected", 0)
- } else if (current) {
- const currentIndex = flat().findIndex((opt) => isDeepEqual(opt.value, current))
- if (currentIndex >= 0) {
- setStore("selected", currentIndex)
+ setTimeout(() => {
+ if (filter.length > 0) {
+ moveTo(0, true)
+ } else if (current) {
+ const currentIndex = flat().findIndex((opt) => isDeepEqual(opt.value, current))
+ if (currentIndex >= 0) {
+ moveTo(currentIndex, true)
+ }
}
- }
- scroll?.scrollTo(0)
+ }, 0)
}),
)
@@ -129,7 +130,7 @@ export function DialogSelect<T>(props: DialogSelectProps<T>) {
moveTo(next)
}
- function moveTo(next: number) {
+ function moveTo(next: number, center = false) {
setStore("selected", next)
props.onMove?.(selected()!)
if (!scroll) return
@@ -138,13 +139,18 @@ export function DialogSelect<T>(props: DialogSelectProps<T>) {
})
if (!target) return
const y = target.y - scroll.y
- if (y >= scroll.height) {
- scroll.scrollBy(y - scroll.height + 1)
- }
- if (y < 0) {
- scroll.scrollBy(y)
- if (isDeepEqual(flat()[0].value, selected()?.value)) {
- scroll.scrollTo(0)
+ if (center) {
+ const centerOffset = Math.floor(scroll.height / 2)
+ scroll.scrollBy(y - centerOffset)
+ } else {
+ if (y >= scroll.height) {
+ scroll.scrollBy(y - scroll.height + 1)
+ }
+ if (y < 0) {
+ scroll.scrollBy(y)
+ if (isDeepEqual(flat()[0].value, selected()?.value)) {
+ scroll.scrollTo(0)
+ }
}
}
}