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 151f73cf7c0..1e448a243ba 100644 --- a/packages/opencode/src/cli/cmd/tui/ui/dialog-select.tsx +++ b/packages/opencode/src/cli/cmd/tui/ui/dialog-select.tsx @@ -140,6 +140,7 @@ export function DialogSelect(props: DialogSelectProps) { if (filter.length > 0) { moveTo(0, true) } else if (current) { + if (isDeepEqual(selected()?.value, current)) return const currentIndex = flat().findIndex((opt) => isDeepEqual(opt.value, current)) if (currentIndex >= 0) { moveTo(currentIndex, true) @@ -161,26 +162,28 @@ export function DialogSelect(props: DialogSelectProps) { setStore("selected", next) const option = selected() if (option) props.onMove?.(option) - if (!scroll) return - const target = scroll.getChildren().find((child) => { - return child.id === JSON.stringify(selected()?.value) - }) - if (!target) return - const y = target.y - scroll.y - 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) + setTimeout(() => { + if (!scroll) return + const target = scroll.getChildren().find((child) => { + return child.id === JSON.stringify(selected()?.value) + }) + if (!target) return + const y = target.y - scroll.y + 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) + } } } - } + }, 0) } const keybind = useKeybind()